📄 ip.4
字号:
IP(4) Minix Programmer's Manual IP(4)
NAME
ip, eth, psip, udp, tcp - Internet Protocol server devices and
definitions
DESCRIPTION
The ip*, eth*, psip*, tcp*, and udp* devices give access to the Internet
Protocol (IP) services in Minix. There are 16 such devices for four
different networks, and four different ways of accessing them. The eth*
and psip* devices give direct access to the network packets at the lowest
level. The ip*, tcp*, and udp* devices give access to IP, TCP, or UDP
services. See set_net_default(8) for a description of the default
network devices and environment variables. The proper TCP device to use
for instance is found by:
if ((tcp_device= getenv("TCP_DEVICE")) == NULL)
tcp_device= "/dev/tcp";
Access to the IP services is provided using filedescriptors to open IP
devices. These open IP channels can be configured with ioctl(2) calls,
and data can be transferred by calls to read(2), and write(2).
Types (general)
<sys/types.h>
defines u8_t, u16_t, u32_t and i32_t (and U8_t, U16_t, U32_t and
I32_t for use in prototypes).
Types (eth)
<net/gen/ether.h>
defines struct ether_addr (ether_addr_t) and ether_type_t and
Ether_type_t for use in prototypes.
<net/gen/eth_io.h>
defines struct nwio_ethopt (nwio_ethopt_t) and struct nwio_ethstat
(nwio_ethstat_t)
<net/gen/eth_hdr.h>
defines struct eth_hdr (eth_hdr_t)
Types (ip)
<net/gen/in.h>
defines ipaddr_t, ipproto_t and struct ip_hdropt (ip_hdropt_t).
<net/gen/ip_io.h>
defines struct nwio_ipconf (nwio_ipconf_t) and struct nwio_ipopt
(nwio_ipopt_t)
1
IP(4) Minix Programmer's Manual IP(4)
<net/gen/ip_hdr.h>
defines struct ip_hdr (ip_hdr_t)
<net/gen/route.h>
defines struct nwio_route (nwio_route_t)
Types (tcp)
<net/gen/tcp.h>
defines tcpport_t and Tcpport_t for use in prototypes.
<net/gen/tcp_io.h>
defines struct nwio_tcpconf (nwio_tcpconf_t), struct nwio_tcpcl
(nwio_tcpcl_t), struct nwio_tcpatt (nwio_tcpatt_t) and struct
nwio_tcpopt (nwio_tcpopt_t).
<net/gen/tcp_hdr.h>
defines struct tcp_hdr (tcp_hdr_t) and struct tcp_hdropt
(tcp_hdropt_t).
Types (udp)
<net/gen/udp.h>
defines udpport_t and Udpport_t for use in prototypes.
<net/gen/udp_io.h>
defines struct nwio_udpopt (nwio_udpopt_t).
<net/gen/udp_hdr.h>
defines struct udp_hdr (udp_hdr_t) and struct udp_io_hdr
(udp_io_hdr_t).
Byte Order Conversion
All 16-bit and 32-bit quantities in IP headers must be in network byte
order. The macros described in hton(3) can be used to convert these
values to and from the byte order used by the host machine.
The Internet Checksum
The OneC_sum function (see oneC_sum(3)) is used to calculate the one's
complement checksum needed for IP network packets.
General Functions
fd = open(tcpip_device, O_RDWR)
This is how one normally obtains a filedescriptor for a new TCP/IP
channel. tcpip_device names one of the TCP/IP devices. The channel may
be used both to send or to receive data.
2
IP(4) Minix Programmer's Manual IP(4)
n = read(fd, buf, size)
Receives one packet (low level devices) or a number of bytes (TCP
stream). Returns the the number of bytes placed into buf, or returns -1
with an error code placed into errno.
n = write(fd, buf, size)
Sends one packet (low level devices) or a number of bytes (TCP stream).
Returns size or -1 with the error code placed into errno. The TCP/IP
read and write functions behave like reads and writes on pipes when it
comes to signals.
ETH Functions
ioctl(fd, NWIOGETHSTAT, &struct nwio_ethstat)
The NWIOGETHSTAT ioctl returns the Ethernet address and some statistics
of the Ethernet server of the channel fd. The result is returned in the
nwio_ethstat structure. The struct nwio_ethstat is defined in
<net/gen/eth_io.h>:
typedef struct nwio_ethstat
{
ether_addr_t nwes_addr;
eth_stat_t nwes_stat;
} nwio_ethstat_t;
typedef 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
3
IP(4) Minix Programmer's Manual IP(4)
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;
ioctl(fd, NWIOSETHOPT, &struct nwio_ethopt)
Before an Ethernet channel can be used to send or receive Ethernet
packets, it has to be configured using the NWIOSETHOPT ioctl. The
structure nwio_ethopt is defined in <net/gen/eth_io.h>:
typedef struct nwio_ethopt
{
u32_t nweo_flags;
ether_addr_t nweo_multi, nweo_rem;
ether_type_t nweo_type;
} nwio_ethopt_t;
#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
4
IP(4) Minix Programmer's Manual IP(4)
The configuration is divided in a number of section (covered by the
xx_MASK macros). Options can be set in the nweo_flags field. The first
section (NWEO_ACC_MASK) controls the access to a certain Ethernet packet
type. If NWEO_EXCL is selected then this is the only channel that can
send or receive Ethernet packets of the selected type. If NWEO_SHARED is
selected then multiple channels (which all have to select NWEO_SHARED)
can use the same Ethernet type, they all can send packets but incoming
packets will be delivered to at most one of them. If NWEO_COPY is
selected then multiple channels have access to the same Ethernet type and
all receive a copy of an incoming packet.
The NWEO_LOC_MASK flags control the delivery of packets with a
destination address equal to the Ethernet address of the machine. If
NWEO_EN_LOC is selected then these packets will be delivered and with
NWEO_DI_LOC they will be discarded.
NWEO_BROAD_MASK, NWEO_MULTI_MASK, and NWEO_PROMISC_MASK do the same to
broadcast packets, multicast packets and promiscuous mode packets as
NWEO_LOC_MASK does for local packets. Except that the precise multicast
address is taken from the nweo_multi field.
The NWEO_REM_MASK flags control whether communication is restricted to
single destination or not. NWEO_REMSPEC restricts sending and receiving
of packets to the single remote computer specified in the nweo_rem field.
NWEO_REMANY allows sending to and receiving from any remote computer.
NWEO_TYPESPEC restricts sending and receiving of packets to the type
specified in nweo_type. The type has to be in network byte order (using
hton(3)). NWEO_TYPEANY allows any type.
If the Ethernet header is completely specified by the nweo_flags i.e.,
all of NWEO_EN_LOC, NWEO_DI_BROAD, NWEO_DI_MULTI, NWEO_DI_PROMISC,
NWEO_REMSPEC and NWEO_TYPESPEC are specified, then NWEO_RWDATONLY can be
used to send and receive only the data part of an Ethernet packet. If
NWEO_RWDATALL is specified then both Ethernet header and data are used.
PSIP Functions
[[[No description available yet.]]]
IP Functions
ioctl(fd, NWIOGIPCONF, &struct nwio_ipconf)
The NWIOGIPCONF ioctl reports the Internet Address and the netmask. For
the nwio_ipconf structure see the NWIOSIPCONF ioctl below.
ioctl(fd, NWIOGIPOROUTE, &struct nwio_route)
5
IP(4) Minix Programmer's Manual IP(4)
The NWIOGIPOROUTE ioctl can be used to query an IP server about its
routing table. [[[NWIODIPOROUTE, NWIOGIPIROUTE, NWIODIPIROUTE?]]] The
structure nwio_route is defined in <net/gen/route.h>:
typedef 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -