IP(4) IP(4) NAME ip, ip_ld - DARPA internet protocol SYNOPSIS #include <sys/inio.h> #include <sys/inet/in.h> #include <sys/inet/ip_var.h> DESCRIPTION The ip_ld line discipline and the files together implement the DARPA IP datagram protocol. They are used by the pro- grams described in ipconfig(8) and route(8). Each Ethernet device, Datakit channel, or other stream that is to send and receive IP packets must be registered as an `IP interface' by pushing ip_ld and setting local and remote addresses with ioctl calls. Thereafter, data received from the network are assumed to be IP packets, and are inter- cepted by the line discipline. Packets destined for the local address of an active IP interface are routed for read- ing on one of the ip device files. Other packets are routed to the IP interface with a matching remote address and retransmitted. Data written on ip devices are taken to be IP packets, are handed to the IP interface with a matching address, and are sent. Packets destined for unreachable places are quietly dropped. A packet consists of a single stream record, followed by a delimiter: at most one packet is returned by a read call; an entire packet must be presented in a single write. A packet includes the IP header. Numbers in the header are in host byte order. Different ip devices handle different protocols atop IP. The minor device is the protocol number in the IP header; e.g. 6 for TCP or 17 for UDP. While an ip device is open, it may not be opened again. IP packets are often processed by pushing a line discipline such as tcp_ld on an ip device, rather than by explicit read and write calls; see tcp(4). The following ioctl(2) calls, defined in <sys/inio.h>, apply to an IP interface. IPIOLOCAL and either IPIOHOST or IPIONET must be called on each interface before packets will be routed correctly. Type in_addr, defined in <sys/inet/in.h>, is a 32-bit integer representing an IP address in host byte order. IPIOLOCAL The third argument points to an in_addr: the IP(4) IP(4) local IP address for this interface. IPIOHOST The third argument points to an in_addr: the remote IP address of the single host reachable through this interface. IPIONET The third argument points to an in_addr: the remote IP address of the network of many hosts reachable through this interface. IP addresses are matched to the network address by applying an internal bit-mask: any IP address for which (address&mask)==net-address is part of the net- work. The default mask depends on the IP address class; see the IP protocol standard for details. IPIOMASK The third argument points to an in_addr contain- ing a new network mask for this interface. IPIOMTU The third argument points to an integer number of bytes. IP packets larger than this size (1500 by default) will be split into smaller ones before being sent through this interface. IPIOARP The network device for this interface is an Eth- ernet. Discard the Ethernet header from each incoming packet. When sending a packet, prefix an Ethernet header containing protocol type 0x8 and a destination address obtained by looking up the IP destination address in a table. If the IP address is not in the table, discard the packet, and make an in_addr containing the offending address available for reading on this file descriptor (the one on which ip_ld was pushed). IPIORESOLVE The third argument points to a structure: struct { in_addr inaddr; unsigned char enaddr[6]; }; Add an entry to the table consulted after IPIOARP, mapping IP address inaddr to Ethernet address enaddr. The following ioctl calls, define in <sys/inio.h>, apply to the entire IP subsystem; they may be used on any file with ip_ld pushed. IPIOROUTE The third argument points to a structure: struct route { in_addr dst; IP(4) IP(4) in_addr gate; }; Arrange that henceforth, any IP packet destined for address dst will be routed as if destined for gate. IPIOGETIFS The third argument points to a union as follows. The structure is defined in <sys/inet/ip_var.h>. union { int index; struct ipif { struct queue *queue; int flags; int mtu; in_addr thishost; in_addr that; in_addr mask; in_addr broadcast; int ipackets, ierrors; int opackets, oerrors; int arp; int dev; } ipif; }; Before the call, index should contain an integer naming an entry in the system's table of active interfaces. Interfaces are numbered in a con- tinuous sequence starting at 0. Out-of-range numbers return an error. After the call, ipif is filled in with various numbers about that interface. FILES /dev/ip* SEE ALSO ioctl(2), internet(3), ipconfig(8), route(8) DARPA standards RFC 791, RFC 1122 BUGS The ARP mechanism should be generalized to deal with net- works other than Ethernet. There is only one ARP table for the entire system; there should be one for each interface. The structures used by IPIOROUTE and IPIORESOLVE should appear in a header file somewhere.