3 eipfmt, parseip, parseipmask, parseipandmask, v4parseip, parseether, myipaddr, myetheraddr, maskip, equivip4, equivip6, defmask, isv4, v4tov6, v6tov4, nhgetv, nhgetl, nhgets, hnputv, hnputl, hnputs, ptclbsum, readipifc \- Internet Protocol addressing
15 vlong parseip(uchar *ipaddr, char *str)
18 vlong parseipmask(uchar *ipaddr, char *str, int v4)
21 vlong parseipandmask(uchar *ipaddr, uchar *ipmask, char *ipstr, char *maskstr)
24 char* v4parseip(uchar *ipaddr, 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 equivip4(uchar *ipaddr1, uchar *ipaddr2)
42 int equivip6(uchar *ipaddr1, uchar *ipaddr2)
45 uchar* defmask(uchar *ipaddr)
48 int isv4(uchar *ipaddr)
51 void v4tov6(uchar *ipv6, uchar *ipv4)
54 int v6tov4(uchar *ipv4, uchar *ipv6)
57 ushort nhgets(void *p)
63 uvlong nhgetv(void *p)
66 void hnputs(void *p, ushort v)
69 void hnputl(void *p, uint v)
72 void hnputv(void *p, uvlong v)
75 ushort ptclbsum(uchar *a, int n)
78 Ipifc* readipifc(char *net, Ipifc *ifc, int index)
81 uchar IPv4bcast[IPaddrlen];
84 uchar IPv4allsys[IPaddrlen];
87 uchar IPv4allrouter[IPaddrlen];
90 uchar IPallbits[IPaddrlen];
93 uchar IPnoaddr[IPaddrlen];
96 uchar v4prefix[IPaddrlen];
98 These routines are used by Internet Protocol (IP) programs to
99 manipulate IP and Ethernet addresses.
100 Plan 9, by default, uses V6 format IP addresses. Since V4
101 addresses fit into the V6 space, all IP addresses can be represented.
102 IP addresses are stored as a string of 16
109 Either V4 or V6 string representation can be used for IP addresses.
110 For V4 addresses, the representation can be (up to) 4 decimal
111 integers from 0 to 255 separated by periods.
112 For V6 addresses, the representation is (up to) 8 hex integers
113 from 0x0 to 0xFFFF separated by colons.
114 Strings of 0 integers can be elided using two colons.
118 .BR FFFF:0:0:0:0:0:0:1111 .
119 The string representation for IP masks is a superset of the
120 address representation. It includes slash notation that indicates
121 the number of leading 1 bits in the mask. Thus, a
122 V4 class C mask can be represented as
123 .BR FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FF00 ,
127 The string representation of Ethernet addresses is exactly
128 12 hexadecimal digits.
133 formatter for Ethernet (verb
147 converts a string pointed to by
149 to a 16-byte IP address starting at
151 As a concession to backwards compatibility,
152 if the string is a V4 address, the return value
153 is an unsigned long integer containing the big-endian V4 address.
154 If not, the return value is 6.
157 converts a string pointed to by
159 to a 16-byte IP mask starting at
161 It too returns an unsigned long big-endian V4 address or 6.
165 slash notation. When the
167 argument is non-zero, then
169 in range [0..32] is offset by 96 to yield a mask for a V4 address.
176 into a single call, interpreting the mask in context of the
177 supplied IP address type.
178 The returned IP mask is
185 All three functions return -1 on errors.
188 converts a string pointed to by
190 to a 4-byte V4 IP address starting at
194 returns the first valid IP address in
195 the IP stack rooted at
199 converts a string pointed to by
201 to a 6-byte Ethernet address starting at
204 reads the Ethernet address string from file
208 Both routines return a negative number on errors.
211 places the bit-wise AND of the IP addresses pointed
212 to by its first two arguments into the buffer pointed
216 returns non-zero if the IP addresses pointed to by its two
219 operates on v4 addresses,
221 operates on v6 addresses.
224 returns the standard class A, B, or C mask for
228 returns non-zero if the V6 address is in the V4 space, that is,
230 .BR 0:0:0:0:0:0:FFFF .
232 converts the 4-byte V4 address,
234 to a V6 address and puts the result in
237 converts the V6 address,
239 to a 4-byte V4 address and puts the result in
246 are used to store 16-bit, 32-bit, and 64-bit integers, respectively, into IP big-endian form.
251 convert big-endian 2, 4 and 8 byte quantities into integers (or
255 returns the one's complement checksum used in IP protocols, typically invoked as
258 hnputs(hdr->cksum, ~ptclbsum(data, len) & 0xffff);
261 A number of standard IP addresses in V6 format are also defined. They are:
265 the V4 broadcast address
268 the V4 all systems multicast address
271 the V4 all routers multicast address
274 the V6 all bits on address
277 the V6 null address, all zeros
280 the IP V6 prefix to all embedded V4 addresses
284 returns information about
285 a particular interface
291 configured under a mount point
295 Each interface is described by one
297 structure which in turn points to a linked list of
299 structures describing the addresses assigned
305 Thus, subsequent calls can be used
306 to free the list returned by the previous call.
314 Iplifc *lifc; /* local addressses */
316 /* per ip interface */
317 int index; /* number of interface in ipifc dir */
318 char dev[64]; /* associated physical device */
319 int mtu; /* max transfer unit */
321 uchar sendra6; /* on == send router adv */
322 uchar recvra6; /* on == rcv router adv */
324 ulong pktin; /* packets read */
325 ulong pktout; /* packets written */
326 ulong errin; /* read errors */
327 ulong errout; /* write errors */
328 Ipv6rp rp; /* route advertisement params */
341 uchar mask[IPaddrlen];
342 uchar net[IPaddrlen]; /* ip & mask */
343 ulong preflt; /* preferred lifetime */
344 ulong validlt; /* valid lifetime */
356 int maxraint; /* max route adv interval */
357 int minraint; /* min route adv interval */
367 contains the first 64 bytes of the device configured with this
372 if the network is multipoint or
373 the remote address if the network is