📄 ip.4
字号:
.\".\" Copyright 1994 Vrije Universiteit, The Netherlands..\" For full copyright and restrictions on use see the file COPYRIGHT in the.\" top level of the Amoeba distribution..\".ig Software: Philip Homburg, 1991 Document: Philip Homburg, Sept 3, 1991 Modified: Greg Sharp and Philip Homburg, March 1992 - merged with udp(L) and made a little more complete. Greg Sharp, April 1992 - updated keywords for auto index generation Modified: Kees J. Bot, June 1994 - changed to man(7) format for Minix....TH IP 4.SH NAMEip, eth, psip, udp, tcp \- Internet Protocol server devices and definitions.SH DESCRIPTION.de SP.if t .sp 0.4.if n .sp..The.BR ip* ,.BR eth* ,.BR psip* ,.BR tcp* ,and.B udp*devices give access to the Internet Protocol (IP) services in Minix.There are 16 such devices for four different networks, and fourdifferent ways of accessing them. The.B eth*and.B psip*devices give direct access to the network packets at the lowest level.The.BR ip* ,.BR tcp* ,and.B udp*devices give access to IP, TCP, or UDP services. See.BR set_net_default (8)for a description of the default network devices and environmentvariables. The proper TCP device to use for instance is found by:.PP.RS.nfif ((tcp_device= getenv("TCP_DEVICE")) == NULL) tcp_device= "/dev/tcp";.fi.RE.PPAccess to the IP services is provided using filedescriptors to open IPdevices. These open IP channels can be configured with.BR ioctl (2)calls, and data can be transferred by calls to.BR read (2),and.BR write (2)..SS "Types (general)".IP <sys/types.h>.brdefines.BR u8_t ,.BR u16_t ,.B u32_tand.B i32_t(and.BR U8_t ,.BR U16_t ,.B U32_tand.B I32_tfor use in prototypes)..SS "Types (eth)".IP <net/gen/ether.h>.brdefines struct ether_addr (\fBether_addr_t\fP) and.B ether_type_tand.B Ether_type_tfor use in prototypes..IP <net/gen/eth_io.h>.brdefines struct nwio_ethopt (\fBnwio_ethopt_t\fP) andstruct nwio_ethstat (\fBnwio_ethstat_t\fP).IP <net/gen/eth_hdr.h>.brdefines struct eth_hdr (\fBeth_hdr_t\fP).SS "Types (ip)".IP <net/gen/in.h>.brdefines.BR ipaddr_t ,.BR ipproto_tand struct ip_hdropt (\fBip_hdropt_t\fP)..IP <net/gen/ip_io.h>.brdefines struct nwio_ipconf (\fBnwio_ipconf_t\fP) andstruct nwio_ipopt (\fBnwio_ipopt_t\fP).IP <net/gen/ip_hdr.h>.brdefines struct ip_hdr (\fBip_hdr_t\fP).IP <net/gen/route.h>.brdefines struct nwio_route (\fBnwio_route_t\fP).SS "Types (tcp)".IP <net/gen/tcp.h>.brdefines.B tcpport_tand.B Tcpport_tfor use in prototypes..IP <net/gen/tcp_io.h>.brdefines struct nwio_tcpconf (\fBnwio_tcpconf_t\fP),struct nwio_tcpcl (\fBnwio_tcpcl_t\fP),struct nwio_tcpatt (\fBnwio_tcpatt_t\fP) andstruct nwio_tcpopt (\fBnwio_tcpopt_t\fP)..IP <net/gen/tcp_hdr.h>.brdefines struct tcp_hdr (\fBtcp_hdr_t\fP) and struct tcp_hdropt(\fBtcp_hdropt_t\fP)..SS "Types (udp)".IP <net/gen/udp.h>.brdefines.B udpport_tand.B Udpport_tfor use in prototypes..IP <net/gen/udp_io.h>.brdefines struct nwio_udpopt (\fBnwio_udpopt_t\fP)..IP <net/gen/udp_hdr.h>.brdefines struct udp_hdr (\fBudp_hdr_t\fP) and struct udp_io_hdr(\fBudp_io_hdr_t\fP)..SS "Byte Order Conversion"All 16-bit and 32-bit quantities in IP headers must be in network byteorder. The macros described in.BR hton (3)can be used to convert these values to and from the byte order used bythe host machine..SS "The Internet Checksum"The.B OneC_sumfunction (see.BR oneC_sum (3))is used to calculate the one's complement checksum needed for IP networkpackets..SS "General Functions".PP.ft B\fIfd\fP = open(\fItcpip_device\fP, O_RDWR).ft R.PPThis is how one normally obtains a filedescriptor for a new TCP/IP channel..I tcpip_devicenames one of the TCP/IP devices. The channel may be used both to send or toreceive data..PP.ft B\fIn\fP = read(\fIfd\fP, \fIbuf\fP, \fIsize\fP).ft R.PPReceives one packet (low level devices) or a number of bytes (TCP stream).Returns the the number of bytes placed into.IR buf ,or returns -1 with an error code placed into.BR errno ..PP.ft B\fIn\fP = write(\fIfd\fP, \fIbuf\fP, \fIsize\fP).ft R.PPSends one packet (low level devices) or a number of bytes (TCP stream).Returns.I sizeor -1 with the error code placed into.BR errno .The TCP/IP.B readand.B writefunctions behave like reads and writes on pipes when it comes to signals..SS "ETH Functions".PP.ft Bioctl(\fIfd\fP, NWIOGETHSTAT, &struct nwio_ethstat).ft R.PPThe.B NWIOGETHSTATioctlreturns the Ethernet address and some statistics of the Ethernet server ofthe channel.IR fd .The result is returned in the nwio_ethstat structure.The \fBstruct nwio_ethstat\fP is defined in <net/gen/eth_io.h>:.PP.RS.nf.if t .ft Ctypedef struct nwio_ethstat{ ether_addr_t nwes_addr; eth_stat_t nwes_stat;} nwio_ethstat_t;.SPtypedef struct eth_stat{ unsigned long ets_recvErr, /* # receive errors */ ets_sendErr, /* # send error */ ets_OVW, /* # buffer overwrite warnings, (packets arrive faster than can be processed) */ ets_CRCerr, /* # crc errors of read */ ets_frameAll, /* # frames not aligned (# bits not a multiple of 8) */ ets_missedP, /* # packets missed due to too slow packet processing */ ets_packetR, /* # packets received */ ets_packetT, /* # packets transmitted */ ets_transDef, /* # transmission deferred (there was a transmission of an other station in progress */ ets_collision, /* # collisions */ ets_transAb, /* # transmissions aborted due to excessive collisions */ ets_carrSense, /* # carrier sense lost */ ets_fifoUnder, /* # fifo underruns (processor is too busy) */ ets_fifoOver, /* # fifo overruns (processor is too busy) */ ets_CDheartbeat, /* # times unable to transmit collision signal */ ets_OWC; /* # times out of window collision */} eth_stat_t;.if t .ft R.fi.RE.PP.ft Bioctl(\fIfd\fP, NWIOSETHOPT, &struct nwio_ethopt).ft R.PPBefore an Ethernet channel can be used to send or receiveEthernet packets, it has to be configured using the.B NWIOSETHOPTioctl.The structure.B nwio_ethoptis defined in <net/gen/eth_io.h>:.PP.RS.nf.if t .ft Ctypedef struct nwio_ethopt{ u32_t nweo_flags; ether_addr_t nweo_multi, nweo_rem; ether_type_t nweo_type;} nwio_ethopt_t;.SP#define NWEO_NOFLAGS 0x0000L#define NWEO_ACC_MASK 0x0003L# define NWEO_EXCL 0x00000001L# define NWEO_SHARED 0x00000002L# define NWEO_COPY 0x00000003L#define NWEO_LOC_MASK 0x0010L# define NWEO_EN_LOC 0x00000010L# define NWEO_DI_LOC 0x00100000L#define NWEO_BROAD_MASK 0x0020L# define NWEO_EN_BROAD 0x00000020L# define NWEO_DI_BROAD 0x00200000L#define NWEO_MULTI_MASK 0x0040L# define NWEO_EN_MULTI 0x00000040L# define NWEO_DI_MULTI 0x00400000L#define NWEO_PROMISC_MASK 0x0080L# define NWEO_EN_PROMISC 0x00000080L# define NWEO_DI_PROMISC 0x00800000L#define NWEO_REM_MASK 0x0100L# define NWEO_REMSPEC 0x00000100L# define NWEO_REMANY 0x01000000L#define NWEO_TYPE_MASK 0x0200L# define NWEO_TYPESPEC 0x00000200L# define NWEO_TYPEANY 0x02000000L#define NWEO_RW_MASK 0x1000L# define NWEO_RWDATONLY 0x00001000L# define NWEO_RWDATALL 0x10000000L.if t .ft R.fi.RE.PPThe configuration is divided in a number of section (covered by the xx_MASKmacros).Options can be set in the.B nweo_flagsfield.The first section (\fBNWEO_ACC_MASK\fP) controls the access to a certainEthernet packet type.If.B NWEO_EXCLis selected then this is the only channel that can send orreceive Ethernet packets of the selected type.If.B NWEO_SHAREDis selected then multiple channels (which all have toselect.BR NWEO_SHARED )can use the same Ethernet type, they all can sendpackets but incoming packets will be delivered to at most one of them.If.B NWEO_COPYis selected then multiple channels have access to the sameEthernet type and all receive a copy of an incoming packet..LPThe.B NWEO_LOC_MASKflags control the delivery of packets with a destinationaddress equal to the Ethernet address of the machine.If.B NWEO_EN_LOCis selected then these packets will be delivered and with.B NWEO_DI_LOCthey will be discarded..PP.BR NWEO_BROAD_MASK ,.BR NWEO_MULTI_MASK ,and.B NWEO_PROMISC_MASKdo the same to broadcast packets,multicast packets and promiscuous mode packets as.B NWEO_LOC_MASKdoes for local packets.Except that the precise multicast address is taken from the \fBnweo_multi\fPfield..LPThe.B NWEO_REM_MASKflags control whether communication is restricted tosingle destination or not..B NWEO_REMSPECrestricts sending and receiving of packets to the singleremote computer specified in the \fBnweo_rem\fP field..B NWEO_REMANYallows sending to and receiving from any remote computer..PP.B NWEO_TYPESPECrestricts sending and receiving of packets to the typespecified in \fBnweo_type\fP.The type has to be in network byte order (using.BR hton (3))..B NWEO_TYPEANYallows any type..PPIf the Ethernet header is completely specified by the.B nweo_flagsi.e., all of.BR NWEO_EN_LOC ,.BR NWEO_DI_BROAD ,.BR NWEO_DI_MULTI ,.BR NWEO_DI_PROMISC ,.BR NWEO_REMSPECand.B NWEO_TYPESPECarespecified, then.B NWEO_RWDATONLYcan be used to send and receive only the data part of an Ethernet packet.If.B NWEO_RWDATALLis specified then both Ethernet header and data are used..SS "PSIP Functions".PP[[[No description available yet.]]].SS "IP Functions".PP.ft Bioctl(\fIfd\fP, NWIOGIPCONF, &struct nwio_ipconf).ft R.PPThe.B NWIOGIPCONFioctl reports the Internet Address and the netmask.For the \fInwio_ipconf\fP structure see the \fBNWIOSIPCONF\fP ioctl below..PP.ft Bioctl(\fIfd\fP, NWIOGIPOROUTE, &struct nwio_route).ft R.PPThe.B NWIOGIPOROUTEioctl can be used to query an IP server about its routing table.[[[NWIODIPOROUTE, NWIOGIPIROUTE, NWIODIPIROUTE?]]]The structure \fBnwio_route\fP is defined in <net/gen/route.h>:.PP.RS.nf.if t .ft Ctypedef struct nwio_route{ u32_t nwr_ent_no; u32_t nwr_ent_count; ipaddr_t nwr_dest; ipaddr_t nwr_netmask; ipaddr_t nwr_gateway; u32_t nwr_dist; u32_t nwr_flags; u32_t nwr_pref;} nwio_route_t;.SP#define NWRF_EMPTY 0#define NWRF_INUSE 1#define NWRF_FIXED 2.if t .ft R.fi.RE.PPThe requested entry is taken from \fBnwr_ent_no\fP.Entries are counted from 0, so the value 0 can be used for an initial query.The size of the routing table is returned in \fBnwr_ent_count\fP.The \fBnwr_flags\fP indicates if the entry is in use (\fBNWRF_INUSE\fP) andif the entry was inserted manually (using \fBNWIOSIPOROUTE\fP) or generatedby the IP server itself.The route is described by.BR nwr_dest ,.BR nwr_netmask ,.BR nwr_gateway ,.BR nwr_dist ,and.BR nwr_pref .\fBNwr_dest\fP and \fBnwr_netmask\fP select the destination addresses.A value of 0.0.0.0 (0x0) in both \fBnwr_dest\fP and \fBnwr_netmask\fP meansevery host.A value of 255.255.255.255 (0xffffffff) in \fBnwr_netmask\fP means a singlehost.Other values of \fBnwr_netmask\fP are netmasks for the network specifiedby \fBnwr_dest\fP.\fBNwr_gateway\fP is gateway that should be used.\fBNwr_dist\fP is a minimal distance.Packets with a time to live smaller than \fBnwr_dist\fP will not reach thedestination.If two routes have equal netmask and distance fields but differentgateways then the gateway with highest value in \fBnwr_pref\fP is used..PP.ft Bioctl(\fIfd\fP, NWIOSIPCONF, &struct nwio_ipconf).ft R.PPThe.B NWIOSIPCONFioctl can be used to inform the IP server about its Internet Addressand/or its netmask.Normally an IP server will discover its Internet Address using the RARPprotocol..B NWIOSIPCONFcan be used in the case that the RARP failed, or the netmask has to be changed.Note that higher level protocols (TCP and UDP) assume that the Internet Addressof an IP device does not change, therefore TCP and UDP stop functioning if
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -