⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ip.4

📁 操作系统设计与实现源码
💻 4
📖 第 1 页 / 共 3 页
字号:
.B NWTO_SND_URGoption causes bytes written to the channel to be send out as urgent data.On receiving an.B EURGerror the.B NWTO_RCV_URGoption must be set to switch over to reading urgent data.  When all urgentdata has been read an.B ENOURGerror will follow,indicating that the option must be cleared with.BR NWTO_RCV_NOTURG .Alas the BSD implementation of urgent data disagrees with the RFC's, so tobe BSD compatible one must set the.B NWTO_BSD_URGoption beforehand on a channel that is to send or receive urgent data.Given that the BSD implementation is the regarded as the TCP/IP standard oneshould always use the BSD style.  The.B NWTO_DEL_RSToption delays a failure response on a connect to the same port as thecurrent open connection.  Without this option a connect would fail ifa server is not yet listening.  With this option a connect will lingeron until the server starts listening.  This option is useful for a serverthat opens a connection, tells the remote end the local port number andthen listens (FTP), or for a program that forks off servers for incomingconnections (TELNET).  A new connection may come in before a new listencan be started, so it is nice if the new connect doesn't fail.  Use thisoption only when it is clearly needed..SS "UDP Functions".PP.ft Bioctl(\fIfd\fP, NWIOGUDPOPT, &struct nwio_udpopt).ft R.PPThe.B NWIOGUDPOPTioctl returns the current options that result from the default optionsand the options set with.BR NWIOSUDPOPT .When.B NWUO_LP_SELor.B NWUO_LP_SETis selected the local port is returned in.BR nwuo_locport .When.B NWUO_RP_SETis selected the remote port is returned in.BR nwuo_remport .The local address is always returned in.BR nwuo_locaddr ,and when.B NWUO_RA_SETis selected the remote address is returned in.BR nwuo_remaddr ..PP.ft Bioctl(\fIfd\fP, NWIOSUDPOPT, &struct nwio_udpopt).ft R.PPA UDP channel must be configured using the.B NWIOSUDPOPTioctl before any data can be read or written..B NWIOSUDPOPTtakes two parameters, a file descriptor to an open UDP device andpointer to a.B nwio_udpoptstructure that describes the requested configuration.The.B nwio_udpoptstructure is defined in <net/gen/udp_io.h> as:.PP.RS.nf.if t .ft Ctypedef struct nwio_udpopt{	unsigned long nwuo_flags;	udpport_t nwuo_locport;	udpport_t nwuo_remport;	ipaddr_t nwuo_locaddr;	ipaddr_t nwuo_remaddr;} nwio_udpopt_t;.SP#define NWUO_NOFLAGS            0x0000L#define NWUO_ACC_MASK           0x0003L#define         NWUO_EXCL               0x00000001L#define         NWUO_SHARED             0x00000002L#define         NWUO_COPY               0x00000003L#define NWUO_LOCPORT_MASK       0x000CL#define         NWUO_LP_SEL             0x00000004L#define         NWUO_LP_SET             0x00000008L#define         NWUO_LP_ANY             0x0000000CL#define NWUO_LOCADDR_MASK       0x0010L#define         NWUO_EN_LOC             0x00000010L#define         NWUO_DI_LOC             0x00100000L#define NWUO_BROAD_MASK         0x0020L#define         NWUO_EN_BROAD           0x00000020L#define         NWUO_DI_BROAD           0x00200000L#define NWUO_REMPORT_MASK       0x0100L#define         NWUO_RP_SET             0x00000100L#define         NWUO_RP_ANY             0x01000000L#define NWUO_REMADDR_MASK       0x0200L#define         NWUO_RA_SET             0x00000200L#define         NWUO_RA_ANY             0x02000000L#define NWUO_RW_MASK            0x1000L#define         NWUO_RWDATONLY          0x00001000L#define         NWUO_RWDATALL           0x10000000L#define NWUO_IPOPT_MASK         0x2000L#define         NWUO_EN_IPOPT           0x00002000L#define         NWUO_DI_IPOPT           0x20000000L.if t .ft R.fi.RE.PPA UDP channel is considered configured when one flag in each category has beenselected.Thus one of.BR NWUO_EXCL ,.B NWUO_SHAREDor.BR NWUO_COPY ,one of.BR NWUO_LP_SEL ,.B NWUO_LP_SETor.BR NWUO_LP_ANY ,one of.B NWUO_EN_LOCor.BR NWUO_DI_LOC ,one of.BR NWUO_EN_BROAD ,or.BR NWUO_DI_BROAD ,one of.BR NWUO_RP_SET ,or.BR NWUO_RP_ANY ,one of.BR NWUO_RA_SET ,or.BR NWUO_RA_ANY ,one of.BR NWUO_RWDATONLY ,or.BR NWUO_RWDATALL ,and one of.BR NWUO_EN_IPOPT ,or.BR NWUO_DI_IPOPT .The acc flags control the access to a certain UDP port..B NWUO_EXCLmeans exclusive access:no other channel can use this port..B NWUO_SHAREDmeans shared access:only channels that specify shared access can use this portand all packets that are received are handed to at most one channel..B NWUO_COPYimposes no access restriction and all channels get a copy of every receivedpacket for that port..PPThe.B locportflags control the selection of the UDP port for this channel..B NWUO_LP_SELrequests the server to pick a port.This port will be in the range from 32768 to 65535 and it will be unique..B NWUO_LP_SETsets the local port to the value of the.B nwuo_locportfield..B NWUO_LP_ANYdoes not select a port.Reception of data is therefore not possible but it ispossible to send data.(See.BR tcpip_read ,and.B tcpip_writeabove)..PPThe.B locaddrflags control the reception of packets..B NWUO_EN_LOCenables the reception of packets with the local IP address as destination..B NWUO_DI_LOCdisables the reception of packet for the local IP address..PPThe.B broadflags control the reception of broadcast packets..B NWUO_EN_BROADenables the reception of broadcast packets and.B NWUO_DI_BROADdisables the reception of broadcast packets..PPThe.B remportflags let the client to specify one specific remote UDP port orto allow any remote port..B NWUO_RP_SETsets the remote UDP port to the value of.BR nwuo_remport .Only packets with a matching remote port will be deliveredand all packets will be sent to that port..B NWUO_RP_ANYallows reception of packets form any port and when transmitting packets theremote port has to be specified..PPThe.B remaddrflags control the remote IP address..B NWUO_RA_SETsets the remote IP address the value of.BR nwuo_remaddr .Only packets from that address will be delivered and all packets will be sentto that address..B NWUO_RA_ANYallows reception of packets from any host and when transmitting packets theremote host has to be specified..PPThe.B rwflags control the format of the data to be sent or received.With.B NWUO_RWDATONLYonly the data part of a UDP packet is sent to the server and only the datapart is received from the server.The.B NWUO_RWDATALLmode presents the data part of a UDP packet with a header that containsthe source and destination IP address, source and destination UDP ports,the IP options, etc.The server expects such a header in front of the data to be transmitted..ig \" Some for Philip to explain properly:The header is defined in <net/gen/udp_hdr.h> and looks like this:.PP.RS.nf.if t .ft Ctypedef struct udp_io_hdr{	ipaddr_t uih_src_addr;	ipaddr_t uih_dst_addr;	udpport_t uih_src_port;	udpport_t uih_dst_port;	u16_t uih_ip_opt_len;	u16_t uih_data_len;} udp_io_hdr_t;.if t .ft R.fi.RE.PPThe first four fields are the source and destination IP addresses andports..B Uih_ip_opt_lenis ???..B Uih_data_lenshould equal the length of the packet data (packet lenght minus theheader.) ???...PPThe.B ipoptflags control the delivery and transmission of IP options.When.B NWUO_EN_IPOPTis set IP, options will be delivered and sent.When.B NWUO_DI_IPOPTis set IP option will be stripped from received packets and no IP options willbe sent..ig \" Minix doesn't have this stuff (yet? ever?).SS "UDP Library Functions".PPThe following routines provide an somewhat easier to use interface to UDP thanthe routines described above (\fBtcpip_open\fP, \fBudp_ioc_setopt\fP,\fBtcpip_read\fP and \fBtcpip_write\fP)..LP.sCerrstatudp_connect(udp_cap, chan_cap, srcport, dstport, dstaddr, flags)capability *udp_cap;capability *chan_cap;udpport_t srcport;udpport_t dstport;ipaddr_t dstaddr;int flags;.eC.kW "\fIudp_connect\fP"\fIUdp_connect\fP combines the functionality of \fItcpip_open\fP and\fIudp_ioc_setopt\fP.A pointer to a UDP server capability should be passed in \fIudp_cap\fP, andthe channel capability will be returned in the capability pointed to by\fIchan_cap\fP.If \fIsrcport\fP is 0 then an unused port will be selected, otherwise the localport will be set to \fIsrcport\fP.If \fIdstport\fP is non-zero then communication will be restricted to remote portsthat equal to \fIdstport\fP, otherwise any data can be sent to or received fromany remote port.The same thing applies to \fIdstaddr\fP; if \fIdstaddr\fP is non-zero thenonly \fIdstaddr\fP can be reached.Currently no flags are defined so \fIflags\fP should be 0..sHudp_reconnect.LP.sCerrstatudp_reconnect(chan_cap, srcport, dstport, dstaddr, flags)capability *chan_cap;udpport_t srcport;udpport_t dstport;ipaddr_t dstaddr;int flags;.eC.kW "\fIudp_reconnect\fP"\fIUdp_reconnect\fP is the same as \fIudp_connect\fP except that an existingchannel capability is (re)used..sHudp_read_msg.LP.sCerrstatudp_read_msg(chan_cap, msg, msglen, actlen, flags)capability *chan_cap;char *msg;int msglen;int *actlen;int flags;.eC.kW "\fIudp_read_msg\fP"\fIUdp_read_msg\fP delivers a UDP packet.The data part of the UDP packet isprepended with an \fIudp_io_hdr\fP.The actual length of the possibly truncated packet is returned in \fIactlen\fP.No flags are defined so \fIflags\fP should be 0..sHudp_write_msg.LP.sCerrstatudp_write_msg(chan_cap, msg, msglen, flags)capability *chan_cap;char *msg;int msglen;int flags;.eC.kW "\fIudp_write_msg\fP"A UDP packet can be sent with \fIudp_write_msg\fP.\fIMsg\fP should point to a \fIudp_io_hdr\fP followed by the data part of theUDP packet.The \fIuih_dst_addr\fP and \fIuih_dst_port\fP fields of the \fIudp_io_hdr\fPshould be filled in if no values are specified in the \fIudp_connect\fP,or \fIudp_reconnect\fP..sHudp_close.LP.sCerrstatudp_close(chan_cap, flags)capability *chan_cap;int flags;.eC.kW "\fIudp_close\fP"\fIUdp_close\fP cleans up the administration kept by the UDP library but doesnot destroy the capability.The function should be used if the capability is passed to another processand should continue to exist.No flags are defined so \fIflags\fP should be 0..sHudp_destroy.LP.sCerrstatudp_destroy(chan_cap, flags)capability *chan_cap;int flags;.eC.kW "\fIudp_destroy\fP"\fIUdp_destroy\fP not only cleans up the administration kept by the UDP librarybut also destroys the channel capability....SH FILES.IP /dev/eth[01] 18nFirst and second raw ethernet..IP /dev/psip[01]First and second Pseudo IP network..IP /dev/ip[0123]IP devices for two ethernets and two Pseudo IP networks..IP /dev/tcp[0123]TCP devices for same four networks..IP /dev/udp[0123]UDP devices..IP "/dev/eth, /dev/psip, /dev/ip, /dev/tcp, /dev/udp"Devices for the default network, links to the devices above..B Ethis only present if ethernet is the default,.B psiponly for pseudo IP..SH "SEE ALSO".BR hton (3),.BR oneC_sum (3),.BR set_net_default (8),.BR boot (8)..SH DIAGNOSTICSSeveral errors may be returned by the TCP/IP server.  The error codeis found in the.B errnovariable if the.BR read ,.BR write ,or.B ioctlcall returns -1.  The TCP/IP error codes defined in <errno.h> are:.IP EPACKSIZE 5cThis indicates an attempt to read or write with a buffer that is toolarge or too small..IP EOUTOFBUFSThe TCP/IP server has insufficient memory to execute the request..IP EBADIOCTLThis indicates an attempt to execute a command the particular serverdoes not understand.For example, a.B NWIOGTCPCONFon an ETH channel..IP EBADMODEThe request is refused because the channel is not fully configured, in thewrong state or the parameters are invalid..IP EBADDESTThis indicates an illegal destination address for a packet..IP EDSTNORCHThe destination is not reachable..IP EISCONNThe channel is already connected so a second request is refused..IP EADDRINUSEThis address is in use..IP ECONNREFUSEDThe connection is refused by the other side..IP ECONNRESETThe connection is reset (non-gracefully terminated) by the other side..IP ETIMEDOUTThe connection is terminated due to an expired timer..IP EURGUrgent data is present and the current receive mode does not allow urgent datato be transferred..IP ENOURGNo urgent data is present and a request came for urgent data..IP ENOTCONNThe request requires a connected channel and the channel is not connected..IP ESHUTDOWNThe connection is shut down.That is, a.B NWIOTCPSHUTDOWNhas been executed so no more data can be transmitted..IP ENOCONNThe connection does not exist..IP EGENERICA generic error code for extremely weird cases..SH AUTHORPhilip Homburg (philip@cs.vu.nl)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -