| IP(2) | System Calls Manual | IP(2) |
IP - Internet Protocol addresses and interfaces
include "ip.m";
ip := load IP IP->PATH;
IPaddr: import IP;
IPaddr: adt {
newv6: fn(nil: array of byte): IPaddr;
newv4: fn(nil: array of byte): IPaddr;
copy: fn(nil: self IPaddr): IPaddr;
eq: fn(nil: self IPaddr, v: IPaddr): int;
mask: fn(nil: self IPaddr, m: IPaddr): IPaddr;
isv4: fn(nil: self IPaddr): int;
ismulticast: fn(nil: self IPaddr): int;
isvalid: fn(nil: self IPaddr): int;
v4: fn(nil: self IPaddr): array of byte;
v6: fn(nil: self IPaddr): array of byte;
class: fn(nil: self IPaddr): int;
classmask: fn(nil: self IPaddr): IPaddr;
parse: fn(s: string): (int, IPaddr);
parsemask: fn(s: string): (int, IPaddr);
parsecidr: fn(s: string): (int, IPaddr, IPaddr);
text: fn(nil: self IPaddr): string;
masktext: fn(nil: self IPaddr): string;
};
v4bcast, v4allsys, v4allrouter, noaddr, allbits: IPaddr;
selfv6, selfv4: IPaddr;
v4prefix: array of byte;
Ifcaddr: adt {
ip: IPaddr; # local interface address
mask: IPaddr; # subnet mask
net: IPaddr; # ip & mask
preflt: big; # preferred life time
validlt: big; # valid life time
};
Ipifc: adt {
index: int; # /net/ipifc/N
dev: string; # bound device
addrs: list of ref Ifcaddr;
sendra: int; # !=0, send router adverts
recvra: int; # !=0, receive router adverts
mtu: int;
pktin: big; # packets in
pktout: big; # packets out
errin: big; # input errors
errout: big; # output errors
rp: IPv6rp; # IPv6 route advert parameters
};
IPv6rp: adt {
mflag: int;
oflag: int;
maxraint: int; # max route advert interval
minraint: int; # min route advert interval
linkmtu: int;
reachtime: int;
rxmitra: int;
ttl: int;
routerlt: int;
};
init: fn();
readipifc: fn(net: string, index: int): (list of ref Ipifc, string);
IP provides data types and operations that manipulate Internet Protocol addresses, and operations that convert between internal and textual address forms, for both IPv4 and IPv6. The textual forms are those defined by RFC2373. Briefly, an IPv6 address is 16 bytes, represented textually as a sequence of 8 colon-separated hexadecimal values ranging from 0 to FFFF, except that any one sequence of zeroes can be replaced by ::. IPv4 addresses are embedded in the IPv6 space with a prefix of either 0:0:0:0:0:FFFF (for addresses of `IPv4-mapped' nodes), or 0:0:0:0:0:0 (for `IPv4-compatible' IPv6 nodes). See RFC2373 for the distinction. For convenience in working with such addresses, the textual syntax allows the last 4 bytes of an IPv6 address to be specified using a restricted IPv4 syntax, allowing an address to end in four dot-separated decimal values (for example, 0:0:0:0:0:FFFF:127.0.0.1 for the IPv4 loopback address). The functions here also accept the common forms of IPv4 syntax with one or two values omitted (eg, 127.1 for the loopback address), and accept IPv4 format for masks (eg, 255.255.254.0).
Init must be called once before using any value or function of the module.
An Internet address or network mask is represented by an IPaddr value. It has the following operations:
The module provides some predefined IPaddr values, mainly for common IPv4 addresses: v4bcast (broadcast address), v4allsys (all hosts multicast address), v4allrouter (all routers multicast address), selfv4 (loopback in IPv4), selfv6 (loopback in IPv6), noaddr (all zero address, used before a node has an address), v4noaddr (all zero address with IPv4 prefix), and allbits (address of all 1 bits). The 12-byte IPv6 prefix for IPv4 embedded addresses is provided in the array of bytes v4prefix.
Readipifc returns a list of the host's IP interfaces and the attributes and addresses of each, read from the interface status files in /net/ipifc. On an error, the string in the returned tuple contains a diagnostic and the list is nil. Each interface is represented by an Ipifc value, which contains a list of local interface addresses, addrs. Each local address is represented by an Iplifc value in that list.
/appl/lib/ip.b
Readipifc is currently only usable in native Inferno. That will change shortly.