]> git.lizzy.rs Git - plan9front.git/blob - sys/man/2/ip
tmdate(1): document tz field
[plan9front.git] / sys / man / 2 / ip
1 .TH IP 2
2 .SH NAME
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
4 .SH SYNOPSIS
5 .B #include <u.h>
6 .br
7 .B #include <libc.h>
8 .br
9 .B #include <ip.h>
10 .PP
11 .B
12 int     eipfmt(Fmt*)
13 .PP
14 .B
15 vlong   parseip(uchar *ipaddr, char *str)
16 .PP
17 .B
18 vlong   parseipmask(uchar *ipaddr, char *str, int v4)
19 .PP
20 .B
21 vlong   parseipandmask(uchar *ipaddr, uchar *ipmask, char *ipstr, char *maskstr)
22 .PP
23 .B
24 char*   v4parseip(uchar *ipaddr, char *str)
25 .PP
26 .B
27 int     parseether(uchar *eaddr, char *str)
28 .PP
29 .B
30 int     myetheraddr(uchar *eaddr, char *dev)
31 .PP
32 .B
33 int     myipaddr(uchar *ipaddr, char *net)
34 .PP
35 .B
36 void    maskip(uchar *from, uchar *mask, uchar *to)
37 .PP
38 .B
39 int     equivip4(uchar *ipaddr1, uchar *ipaddr2)
40 .PP
41 .B
42 int     equivip6(uchar *ipaddr1, uchar *ipaddr2)
43 .PP
44 .B
45 uchar*  defmask(uchar *ipaddr)
46 .PP
47 .B
48 int     isv4(uchar *ipaddr)
49 .PP
50 .B
51 void    v4tov6(uchar *ipv6, uchar *ipv4)
52 .PP
53 .B
54 int     v6tov4(uchar *ipv4, uchar *ipv6)
55 .PP
56 .B
57 ushort  nhgets(void *p)
58 .PP
59 .B
60 uint    nhgetl(void *p)
61 .PP
62 .B
63 uvlong  nhgetv(void *p)
64 .PP
65 .B
66 void    hnputs(void *p, ushort v)
67 .PP
68 .B
69 void    hnputl(void *p, uint v)
70 .PP
71 .B
72 void    hnputv(void *p, uvlong v)
73 .PP
74 .B
75 ushort  ptclbsum(uchar *a, int n)
76 .PP
77 .B
78 Ipifc*  readipifc(char *net, Ipifc *ifc, int index)
79 .PP
80 .B
81 uchar   IPv4bcast[IPaddrlen];
82 .PP
83 .B
84 uchar   IPv4allsys[IPaddrlen];
85 .PP
86 .B
87 uchar   IPv4allrouter[IPaddrlen];
88 .PP
89 .B
90 uchar   IPallbits[IPaddrlen];
91 .PP
92 .B
93 uchar   IPnoaddr[IPaddrlen];
94 .PP
95 .B
96 uchar   v4prefix[IPaddrlen];
97 .SH DESCRIPTION
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
103 .B unsigned
104 .BR chars ,
105 Ethernet
106 addresses as 6
107 .B unsigned
108 .BR chars .
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.
115 For example,
116 .B FFFF::1111
117 is equivalent to
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 ,
124 .BR 255.255.255.0 ,
125 or
126 .BR /120.
127 The string representation of Ethernet addresses is exactly
128 12 hexadecimal digits.
129 .PP
130 .I Eipfmt
131 is a
132 .IR print (2)
133 formatter for Ethernet (verb
134 .BR E )
135 addresses,
136 IP V6 (verb
137 .BR I )
138 addresses,
139 IP V4 (verb
140 .BR V )
141 addresses,
142 and IP V6 (verb
143 .BR M )
144 masks.
145 .PP
146 .I Parseip
147 converts a string pointed to by
148 .I str
149 to a 16-byte IP address starting at
150 .IR ipaddr .
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.
155 .PP
156 .I Parseipmask
157 converts a string pointed to by
158 .I str
159 to a 16-byte IP mask starting at
160 .IR ipaddr .
161 It too returns an unsigned long big-endian V4 address or 6.
162 .I Parseipmask
163 accepts a mask in
164 .BI / prefixlen
165 slash notation. When the
166 .IR v4
167 argument is non-zero, then
168 .I prefixlen
169 in range [0..32] is offset by 96 to yield a mask for a V4 address.
170 .PP
171 .I Parseipandmask
172 combines
173 .I parseip
174 and
175 .I parseipmask
176 into a single call, interpreting the mask in context of the
177 supplied IP address type.
178 The returned IP mask is
179 .B /128
180 when
181 .I maskstr
182 is
183 .BR nil .
184 .PP
185 All three functions return -1 on errors.
186 .PP
187 .I V4parseip
188 converts a string pointed to by
189 .I str
190 to a 4-byte V4 IP address starting at
191 .IR ipaddr .
192 .PP
193 .I Myipaddr
194 returns the first valid IP address in
195 the IP stack rooted at
196 .IR net .
197 .PP
198 .I Parseether
199 converts a string pointed to by
200 .I str
201 to a 6-byte Ethernet address starting at
202 .IR eaddr .
203 .I Myetheraddr
204 reads the Ethernet address string from file
205 .IB dev /addr
206 and parses it into
207 .IR eaddr .
208 Both routines return a negative number on errors.
209 .PP
210 .I Maskip
211 places the bit-wise AND of the IP addresses pointed
212 to by its first two arguments into the buffer pointed
213 to by the third.
214 .PP
215 .I Equivip
216 returns non-zero if the IP addresses pointed to by its two
217 arguments are equal.
218 .I Equivip4
219 operates on v4 addresses,
220 .I equivip6
221 operates on v6 addresses.
222 .PP
223 .I Defmask
224 returns the standard class A, B, or C mask for
225 .I ipaddr .
226 .PP
227 .I Isv4
228 returns non-zero if the V6 address is in the V4 space, that is,
229 if it starts with
230 .BR 0:0:0:0:0:0:FFFF .
231 .I V4tov6
232 converts the 4-byte V4 address,
233 .IR v4ip ,
234 to a V6 address and puts the result in
235 .IR v6ip .
236 .I V6tov4
237 converts the V6 address,
238 .IR v6ip ,
239 to a 4-byte V4 address and puts the result in
240 .IR v4ip .
241 .PP
242 .IR Hnputs ,
243 .I hnputl
244 and
245 .I hnputv
246 are used to store 16-bit, 32-bit, and 64-bit integers, respectively, into IP big-endian form.
247 .IR Nhgets ,
248 .I nhgetl
249 and
250 .I nhgetv
251 convert big-endian 2, 4 and 8 byte quantities into integers (or
252 .IR uvlong s).
253 .PP
254 .I Pctlbsum
255 returns the one's complement checksum used in IP protocols, typically invoked as
256 .IP
257 .EX
258 hnputs(hdr->cksum, ~ptclbsum(data, len) & 0xffff);
259 .EE
260 .PP
261 A number of standard IP addresses in V6 format are also defined.  They are:
262 .TF IPv4allrouter
263 .TP
264 .B IPv4bcast
265 the V4 broadcast address
266 .TP
267 .B IPv4allsys
268 the V4 all systems multicast address
269 .TP
270 .B IPv4allrouter
271 the V4 all routers multicast address
272 .TP
273 .B IPallbits
274 the V6 all bits on address
275 .TP
276 .B IPnoaddr
277 the V6 null address, all zeros
278 .TP
279 .B v4prefix
280 the IP V6 prefix to all embedded V4 addresses
281 .PD
282 .PP
283 .I Readipifc
284 returns information about
285 a particular interface
286 .RI ( index
287 >= 0)
288 or all IP interfaces
289 .RI ( index
290 < 0)
291 configured under a mount point
292 .IR net ,
293 default
294 .BR /net .
295 Each interface is described by one
296 .I Ipifc
297 structure which in turn points to a linked list of
298 .IR Iplifc
299 structures describing the addresses assigned
300 to this interface.
301 If the list
302 .IR ifc
303 is supplied,
304 that list is freed.
305 Thus, subsequent calls can be used
306 to free the list returned by the previous call.
307 .I Ipifc
308 is:
309 .PP
310 .EX
311 typedef struct Ipifc
312 {
313         Ipifc   *next;
314         Iplifc  *lifc;          /* local addressses */
315
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 */
320
321         uchar   sendra6;        /* on == send router adv */
322         uchar   recvra6;        /* on == rcv router adv */
323
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 */
329 } Ipifc;
330 .EE
331 .PP
332 .I Iplifc
333 is:
334 .PP
335 .EX
336 struct Iplifc
337 {
338         Iplifc  *next;
339
340         uchar   ip[IPaddrlen];
341         uchar   mask[IPaddrlen];
342         uchar   net[IPaddrlen];         /* ip & mask */
343         ulong   preflt;                 /* preferred lifetime */
344         ulong   validlt;                /* valid lifetime */
345 };
346 .EE
347 .PP
348 .I Ipv6rp
349 is:
350 .PP
351 .EX
352 struct Ipv6rp
353 {
354         int     mflag;
355         int     oflag;
356         int     maxraint;       /* max route adv interval */
357         int     minraint;       /* min route adv interval */
358         int     linkmtu;
359         int     reachtime;
360         int     rxmitra;
361         int     ttl;
362         int     routerlt;       
363 };
364 .EE
365 .PP
366 .I Dev
367 contains the first 64 bytes of the device configured with this
368 interface.
369 .I Net
370 is
371 .IB ip & mask
372 if the network is multipoint or
373 the remote address if the network is
374 point to point.
375 .SH SOURCE
376 .B /sys/src/libip
377 .SH SEE ALSO
378 .IR print (2),
379 .IR ip (3)