3 eipfmt, parseip, parseipmask, v4parseip, v4parsecidr, parseether, myipaddr, myetheraddr, maskip, equivip, defmask, isv4, v4tov6, v6tov4, nhgetl, nhgets, nhgetv, hnputl, hnputs, hnputv, 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 uvlong nhgetv(void *p)
63 void hnputs(void *p, ushort v)
66 void hnputl(void *p, uint v)
69 void hnputv(void *p, uvlong v)
72 ushort ptclbsum(uchar *a, int n)
75 Ipifc* readipifc(char *net, Ipifc *ifc, int index)
78 uchar IPv4bcast[IPaddrlen];
81 uchar IPv4allsys[IPaddrlen];
84 uchar IPv4allrouter[IPaddrlen];
87 uchar IPallbits[IPaddrlen];
90 uchar IPnoaddr[IPaddrlen];
93 uchar v4prefix[IPaddrlen];
95 These routines are used by Internet Protocol (IP) programs to
96 manipulate IP and Ethernet addresses.
97 Plan 9, by default, uses V6 format IP addresses. Since V4
98 addresses fit into the V6 space, all IP addresses can be represented.
99 IP addresses are stored as a string of 16
106 Either V4 or V6 string representation can be used for IP addresses.
107 For V4 addresses, the representation can be (up to) 4 decimal
108 integers from 0 to 255 separated by periods.
109 For V6 addresses, the representation is (up to) 8 hex integers
110 from 0x0 to 0xFFFF separated by colons.
111 Strings of 0 integers can be elided using two colons.
115 .BR FFFF:0:0:0:0:0:0:1111 .
116 The string representation for IP masks is a superset of the
117 address representation. It includes slash notation that indicates
118 the number of leading 1 bits in the mask. Thus, a
119 V4 class C mask can be represented as
120 .BR FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FF00 ,
124 The string representation of Ethernet addresses is exactly
125 12 hexadecimal digits.
130 formatter for Ethernet (verb
144 converts a string pointed to by
146 to a 16-byte IP address starting at
148 As a concession to backwards compatibility,
149 if the string is a V4 address, the return value
150 is an unsigned long integer containing the big-endian V4 address.
151 If not, the return value is 6.
153 converts a string pointed to by
155 to a 6-byte IP mask starting at
157 It too returns an unsigned long big-endian V4 address or 6.
158 Both routines return -1 on errors.
161 converts a string pointed to by
163 to a 4-byte V4 IP address starting at
167 converts a string of the form
168 addr/mask, pointed to by
170 to a 4-byte V4 IP address starting at
172 and a 4-byte V4 IP mask starting at
176 returns the first valid IP address in
177 the IP stack rooted at
181 converts a string pointed to by
183 to a 6-byte Ethernet address starting at
186 reads the Ethernet address string from file
190 Both routines return a negative number on errors.
193 places the bit-wise AND of the IP addresses pointed
194 to by its first two arguments into the buffer pointed
198 returns non-zero if the IP addresses pointed to by its two
202 returns the standard class A, B, or C mask for
206 returns non-zero if the V6 address is in the V4 space, that is,
208 .BR 0:0:0:0:0:0:FFFF .
210 converts the V4 address,
212 to a V6 address and puts the result in
215 converts the V6 address,
217 to a V4 address and puts the result in
224 are used to store 16-, 32-, and 64-bit integers into IP big-endian form.
229 convert big-endian 2-, 4-, and 8-byte quantities into integers.
232 returns the one's complement checksum used in IP protocols, typically invoked as
234 hnputs(hdr->cksum, ~ptclbsum(data, len) & 0xffff);
237 A number of standard IP addresses in V6 format are also defined. They
240 the V4 broadcast address
242 the V4 all systems multicast address
244 the V4 all routers multicast address
246 the V6 all bits on address
248 the V6 null address, all zeros
250 the IP V6 prefix to all embedded V4 addresses
253 returns information about
254 a particular interface (\fIindex\fP >= 0)
255 or all IP interfaces (\fIindex\fP < 0)
261 Each interface is described by one
263 structure which in turn points to a linked list of
265 structures describing the addresses assigned
271 Thus, subsequent calls can be used
272 to free the list returned by the previous call.
280 Iplifc *lifc; /* local addressses */
282 /* per ip interface */
283 int index; /* number of interface in ipifc dir */
284 char dev[64]; /* associated physical device */
285 int mtu; /* max transfer unit */
287 long validlt; /* valid life time */
288 long preflt; /* preferred life time */
289 uchar sendra6; /* on == send router adv */
290 uchar recvra6; /* on == rcv router adv */
292 ulong pktin; /* packets read */
293 ulong pktout; /* packets written */
294 ulong errin; /* read errors */
295 ulong errout; /* write errors */
296 Ipv6rp rp; /* route advertisement params */
309 uchar mask[IPaddrlen];
310 uchar net[IPaddrlen]; /* ip & mask */
311 ulong preflt; /* preferred lifetime */
312 ulong validlt; /* valid lifetime */
322 int maxraint; /* max route adv interval */
323 int minraint; /* min route adv interval */
332 contains the first 64 bytes of the device configured with this
337 if the network is multipoint or
338 the remote address if the network is