3 eipfmt, parseip, parseipmask, v4parseip, v4parsecidr, parseether, myipaddr, myetheraddr, maskip, equivip, defmask, isv4, v4tov6, v6tov4, nhgetl, nhgets, hnputl, hnputs, ptclbsum, readipifc \- Internet protocol
15 ulong parseip(uchar *ipaddr, char *str)
18 ulong parseipmask(uchar *ipaddr, char *str)
21 char* v4parseip(uchar *ipaddr, char *str)
24 ulong v4parsecidr(uchar *addr, uchar *mask, char *str)
27 int parseether(uchar *eaddr, char *str)
30 int myetheraddr(uchar *eaddr, char *dev)
33 int myipaddr(uchar *ipaddr, char *net)
36 void maskip(uchar *from, uchar *mask, uchar *to)
39 int equivip(uchar *ipaddr1, uchar *ipaddr2)
42 uchar* defmask(uchar *ipaddr)
45 int isv4(uchar *ipaddr)
48 void v4tov6(uchar *ipv6, uchar *ipv4)
51 void v6tov4(uchar *ipv4, uchar *ipv6)
54 ushort nhgets(void *p)
60 void hnputs(void *p, ushort v)
63 void hnputl(void *p, uint v)
66 ushort ptclbsum(uchar *a, int n)
69 Ipifc* readipifc(char *net, Ipifc *ifc, int index)
72 uchar IPv4bcast[IPaddrlen];
75 uchar IPv4allsys[IPaddrlen];
78 uchar IPv4allrouter[IPaddrlen];
81 uchar IPallbits[IPaddrlen];
84 uchar IPnoaddr[IPaddrlen];
87 uchar v4prefix[IPaddrlen];
89 These routines are used by Internet Protocol (IP) programs to
90 manipulate IP and Ethernet addresses.
91 Plan 9, by default, uses V6 format IP addresses. Since V4
92 addresses fit into the V6 space, all IP addresses can be represented.
93 IP addresses are stored as a string of 16
100 Either V4 or V6 string representation can be used for IP addresses.
101 For V4 addresses, the representation can be (up to) 4 decimal
102 integers from 0 to 255 separated by periods.
103 For V6 addresses, the representation is (up to) 8 hex integers
104 from 0x0 to 0xFFFF separated by colons.
105 Strings of 0 integers can be elided using two colons.
109 .BR FFFF:0:0:0:0:0:0:1111 .
110 The string representation for IP masks is a superset of the
111 address representation. It includes slash notation that indicates
112 the number of leading 1 bits in the mask. Thus, a
113 V4 class C mask can be represented as
114 .BR FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FF00 ,
118 The string representation of Ethernet addresses is exactly
119 12 hexadecimal digits.
124 formatter for Ethernet (verb
138 converts a string pointed to by
140 to a 16-byte IP address starting at
142 As a concession to backwards compatibility,
143 if the string is a V4 address, the return value
144 is an unsigned long integer containing the big-endian V4 address.
145 If not, the return value is 6.
147 converts a string pointed to by
149 to a 6-byte IP mask starting at
151 It too returns an unsigned long big-endian V4 address or 6.
152 Both routines return -1 on errors.
155 converts a string pointed to by
157 to a 4-byte V4 IP address starting at
161 converts a string of the form
162 addr/mask, pointed to by
164 to a 4-byte V4 IP address starting at
166 and a 4-byte V4 IP mask starting at
170 returns the first valid IP address in
171 the IP stack rooted at
175 converts a string pointed to by
177 to a 6-byte Ethernet address starting at
180 reads the Ethernet address string from file
184 Both routines return a negative number on errors.
187 places the bit-wise AND of the IP addresses pointed
188 to by its first two arguments into the buffer pointed
192 returns non-zero if the IP addresses pointed to by its two
196 returns the standard class A, B, or C mask for
200 returns non-zero if the V6 address is in the V4 space, that is,
202 .BR 0:0:0:0:0:0:FFFF .
204 converts the V4 address,
206 to a V6 address and puts the result in
209 converts the V6 address,
211 to a V4 address and puts the result in
217 are used to store 16-bit and 32-bit integers into IP big-endian form.
221 convert big-endian 2 and 4 byte quantities into integers.
224 returns the one's complement checksum used in IP protocols, typically invoked as
226 hnputs(hdr->cksum, ~ptclbsum(data, len) & 0xffff);
229 A number of standard IP addresses in V6 format are also defined. They
232 the V4 broadcast address
234 the V4 all systems multicast address
236 the V4 all routers multicast address
238 the V6 all bits on address
240 the V6 null address, all zeros
242 the IP V6 prefix to all embedded V4 addresses
245 returns information about
246 a particular interface (\fIindex\fP >= 0)
247 or all IP interfaces (\fIindex\fP < 0)
253 Each interface is described by one
255 structure which in turn points to a linked list of
257 structures describing the addresses assigned
263 Thus, subsequent calls can be used
264 to free the list returned by the previous call.
272 Iplifc *lifc; /* local addressses */
274 /* per ip interface */
275 int index; /* number of interface in ipifc dir */
276 char dev[64]; /* associated physical device */
277 int mtu; /* max transfer unit */
279 long validlt; /* valid life time */
280 long preflt; /* preferred life time */
281 uchar sendra6; /* on == send router adv */
282 uchar recvra6; /* on == rcv router adv */
284 ulong pktin; /* packets read */
285 ulong pktout; /* packets written */
286 ulong errin; /* read errors */
287 ulong errout; /* write errors */
288 Ipv6rp rp; /* route advertisement params */
301 uchar mask[IPaddrlen];
302 uchar net[IPaddrlen]; /* ip & mask */
303 ulong preflt; /* preferred lifetime */
304 ulong validlt; /* valid lifetime */
314 int maxraint; /* max route adv interval */
315 int minraint; /* min route adv interval */
324 contains the first 64 bytes of the device configured with this
329 if the network is multipoint or
330 the remote address if the network is