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

📄 ip.4

📁 Unix操作系统minix 2.0源码
💻 4
📖 第 1 页 / 共 3 页
字号:

          #define NWRF_EMPTY      0
          #define NWRF_INUSE      1
          #define NWRF_FIXED      2

     The requested entry is taken from nwr_ent_no.  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 nwr_ent_count.  The nwr_flags  indicates  if
     the  entry  is in use (NWRF_INUSE) and if the entry was inserted manually
     (using NWIOSIPOROUTE) or generated by the IP server itself.  The route is
     described  by nwr_dest, nwr_netmask, nwr_gateway, nwr_dist, and nwr_pref.
     Nwr_dest and nwr_netmask select the destination addresses.   A  value  of
     0.0.0.0 (0x0) in both nwr_dest and nwr_netmask means every host.  A value
     of 255.255.255.255 (0xffffffff)  in  nwr_netmask  means  a  single  host.
     Other  values  of  nwr_netmask  are netmasks for the network specified by
     nwr_dest.  Nwr_gateway is gateway that should be  used.   Nwr_dist  is  a
     minimal distance.  Packets with a time to live smaller than nwr_dist will
     not reach the destination.  If two routes have equal netmask and distance
     fields  but  different  gateways  then  the gateway with highest value in
     nwr_pref is used.

     ioctl(fd, NWIOSIPCONF, &struct nwio_ipconf)

     The NWIOSIPCONF ioctl can be used to  inform  the  IP  server  about  its
     Internet Address and/or its netmask.  Normally an IP server will discover
     its Internet Address using the RARP protocol.  NWIOSIPCONF can 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
     Address  of  an  IP  device  does  not change, therefore TCP and UDP stop
     functioning if the Internet Address is changed.

     The structure nwio_ipconf is defined in <net/gen/ip_io.h>:





                                                                             6



IP(4)                     Minix Programmer's Manual                      IP(4)


          typedef struct nwio_ipconf
          {
                  u32_t   nwic_flags;
                  ipaddr_t nwic_ipaddr;
                  ipaddr_t nwic_netmask;
          } nwio_ipconf_t;

          #define NWIC_NOFLAGS            0x0
          #define NWIC_FLAGS              0x3
          #       define NWIC_IPADDR_SET          0x1
          #       define NWIC_NETMASK_SET         0x2

     The function of nwio_ipconf depends  on  the  value  of  nwic_flags.   If
     NWIC_IPADDR_SET  is  set  then  the  Internet  Address  will  be  set  to
     nwic_ipaddr.  If NWIC_NETMASK_SET is set then the Internet  Address  will
     be set to nwic_netmask.

     ioctl(fd, NWIOSIPOPT, &struct nwio_ipopt)

     Before an IP channel can be used, it  has  to  be  configured  using  the
     NWIOSIPOPT    ioctl.     The   structure   nwio_ipopt   is   defined   in
     <net/gen/ip_io.h>:

          typedef struct nwio_ipopt
          {
                  u32_t nwio_flags;
                  ipaddr_t nwio_rem;
                  ip_hdropt_t nwio_hdropt;
                  u8_t nwio_tos;
                  u8_t nwio_ttl;
                  u8_t nwio_df;
                  ipproto_t nwio_proto;
          } nwio_ipopt_t;

          #define NWIO_NOFLAGS    0x0000L
          #define NWIO_ACC_MASK   0x0003L
          #       define NWIO_EXCL        0x00000001L
          #       define NWIO_SHARED      0x00000002L
          #       define NWIO_COPY        0x00000003L
          #define NWIO_LOC_MASK   0x0010L
          #       define NWIO_EN_LOC      0x00000010L
          #       define NWIO_DI_LOC      0x00100000L
          #define NWIO_BROAD_MASK 0x0020L
          #       define NWIO_EN_BROAD    0x00000020L
          #       define NWIO_DI_BROAD    0x00200000L
          #define NWIO_REM_MASK   0x0100L
          #       define NWIO_REMSPEC     0x00000100L
          #       define NWIO_REMANY      0x01000000L
          #define NWIO_PROTO_MASK 0x0200L
          #       define NWIO_PROTOSPEC   0x00000200L


                                                                             7



IP(4)                     Minix Programmer's Manual                      IP(4)


          #       define NWIO_PROTOANY    0x02000000L
          #define NWIO_HDR_O_MASK 0x0400L
          #       define NWIO_HDR_O_SPEC  0x00000400L
          #       define NWIO_HDR_O_ANY   0x04000000L
          #define NWIO_RW_MASK    0x1000L
          #       define NWIO_RWDATONLY   0x00001000L
          #       define NWIO_RWDATALL    0x10000000L

     The  options  are  divided   in   several   categories:    NWIO_ACC_MASK,
     NWIO_LOC_MASK,     NWIO_BROAD_MASK,    NWIO_REM_MASK,    NWIO_PROTO_MASK,
     NWIO_HDR_O_MASK and NWIO_RW_MASK.   A  channel  is  configured  when  one
     option of each category is set.

     The options covered by NWIO_ACC_MASK control the number of channels  that
     can  use  one  IP  protocol.   If  NWIO_EXCL  is specified then only that
     channel can use a certain IP  protocol.   If  NWIO_SHARED  then  multiple
     channels  that  all  have  to  specify  NWIO_SHARED  can  use the same IP
     protocol, but incoming packets will be delivered to a most  one  channel.
     NWIO_SHARED  does not impose any restrictions.  Every channel gets a copy
     of an incoming packet.

     NWIO_LOC_MASK and NWIO_BROAD_MASK control the delivery  of  packets.   If
     NWIO_EN_LOC  is specified then packets that are explicitly send to the IP
     server are delivered.   If  NWIO_EN_BROAD  is  specified  then  broadcast
     packets  are  delivered.  Either one or both of them can be disabled with
     NWIO_DI_LOC and NWIO_DI_BROAD.

     NWIO_REMSPEC can be used to restrict communication to  one  remote  host.
     This  host is taken from the nwio_rem field.  If any remote host is to be
     allowed then NWIO_REMANY can be used.

     NWIO_PROTOSPEC restricts communication to one IP protocol,  specified  in
     nwio_proto.  NWIO_PROTOANY allows any protocol to be sent or received.

     NWIO_HDR_O_SPEC specifies all IP header options in advance.   The  values
     are taken from nwio_hdropt, nwio_tos, nwio_ttl, and nwio_df.  Nwio_hdropt
     specifies the IP options that should be present in  an  outgoing  packet.
     Ip_hdropt_t is defined in <net/gen/in.h>:

          typedef struct ip_hdropt
          {
                  u8_t iho_opt_siz;
                  u8_t iho_data[IP_MAX_HDR_SIZE-IP_MIN_HDR_SIZE];
          } ip_hdropt_t;

     The bytes of size iho_opt_siz in iho_data are appended to the IP  header.
     Nwio_tos  specifies  the  value of the ``type of service'' bits, nwio_ttl
     gives the value of the ``time  to  live''  field  and  nwio_df  specifies
     whether  fragmentation  is  disallowed  or not.  NWIO_HDR_O_ANY specifies
     that the header options should be specified at each write request.


                                                                             8



IP(4)                     Minix Programmer's Manual                      IP(4)


     NWIO_RWDATONLY specifies that the header should be omitted from  a  write
     request.   This  option  can  only  be  used  when  all header fields are
     specified in previous options:  NWIO_EN_LOC, NWIO_DI_BROAD, NWIO_REMSPEC,
     NWIO_PROTOSPEC  and  NWIO_HDR_O_SPEC.   A  read  operation will also only
     return the data part, so the IP options will be lost.

     ioctl(fd, NWIOSIPOROUTE, &struct nwio_route)

     The  NWIOSIPOROUTE  ioctl  adds  a  route  to  the  routing  table.   See
     NWIOGIPOROUTE  above  for a description of the nwio_route structure.  The
     fields nwr_ent_no and nwr_ent_count are ignored.

  TCP Functions

     ioctl(fd, NWIOTCPCONN, &struct nwio_tcpcl)

     The NWIOTCPCONN ioctl tries to setup a connection with  a  remote  TCP/IP
     server.   The  channel  must  be  fully configured (see NWIOSTCPCONF) and
     values for the local port, the remote port and the remote address have be
     specified  using NWTC_LP_SET or NWTC_LP_SEL, NWTC_SET_RA and NWTC_SET_RP.
     The struct nwio_tcpcl is defined in <net/gen/tcp_io.h> as:

          typedef struct nwio_tcpcl
          {
                  long nwtcl_flags;
                  long nwtcl_ttl;
          } nwio_tcpcl_t;

     Set the nwtcl_flags field to zero before  the  connect  or  listen  call.
     [[[Further explanation of nwio_tcpcl?]]]

     ioctl(fd, NWIOGTCPCONF, &struct nwio_tcpconf)

     This call reports the  current  configuration  of  a  TCP  channel.   The
     nwtc_flags  field  shows  the  status of the access, locport, remaddr and
     remport fields.  Nwtc_locaddr contains the Internet address of the TCP/IP
     server.   Remaddr  contains  the  Internet  address  of the remote TCP/IP
     server when set with NWTC_SET_RA or after a successful connect or  listen
     (see  NWIOTCPCONN  or  NWIOTCPLISTEN).   Nwio_locport  contains the local
     TCP/IP  port  set  with  NWTC_LP_SET  or  the  selected  port  set   with
     NWTC_LP_SEL.   Nwtc_remport  contains  the  TCP port of the remote TCP/IP
     server as set with NWIO_SET_RP or after a successful connect or listen.

     A value of  0  (zero)  is  reported  for  nwtc_remaddr,  nwtc_locport  or
     nwtc_remport when no value is set either explicitly or implicitly.

     ioctl(fd, NWIOTCPLISTEN, &struct nwio_tcpcl)





                                                                             9



IP(4)                     Minix Programmer's Manual                      IP(4)


     The NWIOTCPLISTEN ioctl waits until  a  remote  TCP/IP  server  tries  to
     connect  to  this  channel.   The  channel  has  to  be  configured  (see
     NWIOSTCPCONF).  An additional restriction is that the local port must  be
     set  (with  NWTC_LP_SET)  or  selected (with NWTC_LP_SEL).  When a remote
     address is set only connections for that host are accepted,  and  when  a
     remote port is set only connections from that port are accepted.  After a
     successful listen NWIOGTCPCONF can be used to find out what  the  address
     and port of the other side are.

     ioctl(fd, NWIOSTCPCONF, &struct nwio_tcpconf)

     Before  a  TCP  channel  can  be  used  it  must  configured  using   the
     NWIOSTCPCONF  ioctl.  The parameters to NWIOSTCPCONF are the channel file
     descriptor and a struct nwio_tcpconf as defined in <net/gen/tcp_io.h>:

          typedef struct nwio_tcpconf
          {
                  u32_t nwtc_flags;
                  ipaddr_t nwtc_locaddr;
                  ipaddr_t nwtc_remaddr;
                  tcpport_t nwtc_locport;
                  tcpport_t nwtc_remport;
          } nwio_tcpconf_t;

          #define NWTC_NOFLAGS    0x0000L
          #define NWTC_ACC_MASK   0x0003L
          #       define NWTC_EXCL        0x00000001L
          #       define NWTC_SHARED      0x00000002L
          #       define NWTC_COPY        0x00000003L
          #define NWTC_LOCPORT_MASK       0x0030L
          #       define NWTC_LP_UNSET    0x00000010L
          #       define NWTC_LP_SET      0x00000020L
          #       define NWTC_LP_SEL      0x00000030L
          #define NWTC_REMADDR_MASK       0x0100L
          #       define NWTC_SET_RA      0x00000100L
          #       define NWTC_UNSET_RA    0x01000000L
          #define NWTC_REMPORT_MASK       0x0200L
          #       define NWTC_SET_RP      0x00000200L
          #       define NWTC_UNSET_RP    0x02000000L

     A tcp channel is considered configured when one flag in each category has
     been  selected.   Thus one of NWTC_EXCL, NWTC_SHARED or NWTC_COPY, one of
     NWTC_LP_UNSET,  NWTC_LP_SET  or  NWTC_LP_SEL,  one  of   NWTC_SET_RA   or
     NWTC_UNSET_RA, and one of NWTC_SET_RP or NWTC_UNSET_RP.

     The acc flags control the access to a certain TCP port.  NWTC_EXCL  means
     exclusive  access.   An  attempt to configure a channel will be denied if
     the same port is specified as that of a channel that requested  exclusive
     access.   NWTC_SHARED  indicates  that several channels use the same port
     but cooperate.  If the shared mode is specified for one channel than  all


                                                                            10



IP(4)                     Minix Programmer's Manual                      IP(4)


     other channel that use the same port should also be configured  with  the
     NWTC_SHARED  flag.   NWTC_COPY  is specified when the programmer does not
     care about other channels.  This is the default.

     The locport flags control which  TCP  port  is  used  for  communication.
     NWTC_LP_UNSET  indicates  the  absence  of  a  local  port.   This is the
     default.  NWTC_LP_SET means that  the  nwtc_locport  field  contains  the
     local  port  to be used by TCP.  This value must be in network byte order
     (see hton(3).)  NWTC_LP_SEL requests the TCP server to pick a port.  This
     port will be in the range from 32768 to 65535 and will be unique.

     The remaddr flags specify which hosts  are  acceptable  for  connections.
     NWTC_SET_RA  indicates  that  only  connection  to  the host specified in
     nwtc_remaddr are acceptable.  Nwtc_remaddr  should  be  in  network  byte
     order  (see  hton(3).)  NWTC_UNSET_RA allows every host on the other side
     of a connection.  This is the default.

     The  remport  flags  specify  which  remote  ports  are  acceptable   for
     connections.   NWTC_SET_RP  indicates  that  only  the  port specified in
     nwtc_remport is acceptable.  NWTC_UNSET_RP allows every port on the other
     side of a connection.  This is the default.

     ioctl(fd, NWIOTCPSHUTDOWN)

     The NWIOTCPSHUTDOWN tells the TCP/IP server that no  more  data  will  be
     sent  over  the channel specified by fd.  This command can be issued when
     the channel is connected to a remote TCP/IP server.   The  TCP/IP  server
     will  tell  the  remote TCP/IP server and the client of the remote TCP/IP
     server will receive an end-of-file indication.

     ioctl(fd, NWIOGTCPOPT, &struct nwio_tcpopt)
     ioctl(fd, NWIOSTCPOPT, &struct nwio_tcpopt)

     The behaviour of a TCP channel may be changed  by  setting  a  number  of
     options.   The TCP options can be obtained with the NWIOGTCPOPT ioctl and

⌨️ 快捷键说明

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