3 eipfmt, parseip, parseipmask, v4parseip, v4parsecidr, 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)
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 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 void 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.
156 converts a string pointed to by
158 to a 6-byte IP mask starting at
160 It too returns an unsigned long big-endian V4 address or 6.
161 Both routines return -1 on errors.
164 converts a string pointed to by
166 to a 4-byte V4 IP address starting at
170 converts a string of the form
171 addr/mask, pointed to by
173 to a 4-byte V4 IP address starting at
175 and a 4-byte V4 IP mask starting at
179 returns the first valid IP address in
180 the IP stack rooted at
184 converts a string pointed to by
186 to a 6-byte Ethernet address starting at
189 reads the Ethernet address string from file
193 Both routines return a negative number on errors.
196 places the bit-wise AND of the IP addresses pointed
197 to by its first two arguments into the buffer pointed
201 returns non-zero if the IP addresses pointed to by its two
204 operates on v4 addresses,
206 operates on v6 addresses.
209 returns the standard class A, B, or C mask for
213 returns non-zero if the V6 address is in the V4 space, that is,
215 .BR 0:0:0:0:0:0:FFFF .
217 converts the 4-byte V4 address,
219 to a V6 address and puts the result in
222 converts the V6 address,
224 to a 4-byte V4 address and puts the result in
231 are used to store 16-bit, 32-bit, and 64-bit integers, respectively, into IP big-endian form.
236 convert big-endian 2, 4 and 8 byte quantities into integers (or
240 returns the one's complement checksum used in IP protocols, typically invoked as
243 hnputs(hdr->cksum, ~ptclbsum(data, len) & 0xffff);
246 A number of standard IP addresses in V6 format are also defined. They are:
250 the V4 broadcast address
253 the V4 all systems multicast address
256 the V4 all routers multicast address
259 the V6 all bits on address
262 the V6 null address, all zeros
265 the IP V6 prefix to all embedded V4 addresses
269 returns information about
270 a particular interface
276 configured under a mount point
280 Each interface is described by one
282 structure which in turn points to a linked list of
284 structures describing the addresses assigned
290 Thus, subsequent calls can be used
291 to free the list returned by the previous call.
299 Iplifc *lifc; /* local addressses */
301 /* per ip interface */
302 int index; /* number of interface in ipifc dir */
303 char dev[64]; /* associated physical device */
304 int mtu; /* max transfer unit */
306 uchar sendra6; /* on == send router adv */
307 uchar recvra6; /* on == rcv router adv */
309 ulong pktin; /* packets read */
310 ulong pktout; /* packets written */
311 ulong errin; /* read errors */
312 ulong errout; /* write errors */
313 Ipv6rp rp; /* route advertisement params */
326 uchar mask[IPaddrlen];
327 uchar net[IPaddrlen]; /* ip & mask */
328 ulong preflt; /* preferred lifetime */
329 ulong validlt; /* valid lifetime */
341 int maxraint; /* max route adv interval */
342 int minraint; /* min route adv interval */
352 contains the first 64 bytes of the device configured with this
357 if the network is multipoint or
358 the remote address if the network is