Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
.TH IP 2
2
.SH NAME
3
eipfmt, parseip, parseipmask, v4parseip, v4parsecidr, parseether, myipaddr, myetheraddr, maskip, equivip4, equivip6, ipcmp, 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)
19
.PP
20
.B
21
char*	v4parseip(uchar *ipaddr, char *str)
22
.PP
23
.B
24
ulong	v4parsecidr(uchar *addr, uchar *mask, 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
int	ipcmp(uchar *ipaddr1, uchar *ipaddr2)
46
.PP
47
.B
48
uchar*	defmask(uchar *ipaddr)
49
.PP
50
.B
51
int	isv4(uchar *ipaddr)
52
.PP
53
.B
54
void	v4tov6(uchar *ipv6, uchar *ipv4)
55
.PP
56
.B
57
void	v6tov4(uchar *ipv4, uchar *ipv6)
58
.PP
59
.B
60
ushort	nhgets(void *p)
61
.PP
62
.B
63
uint	nhgetl(void *p)
64
.PP
65
.B
66
uvlong	nhgetv(void *p)
67
.PP
68
.B
69
void	hnputs(void *p, ushort v)
70
.PP
71
.B
72
void	hnputl(void *p, uint v)
73
.PP
74
.B
75
void	hnputv(void *p, uvlong v)
76
.PP
77
.B
78
ushort	ptclbsum(uchar *a, int n)
79
.PP
80
.B
81
Ipifc*	readipifc(char *net, Ipifc *ifc, int index)
82
.PP
83
.B
84
uchar	IPv4bcast[IPaddrlen];
85
.PP
86
.B
87
uchar	IPv4allsys[IPaddrlen];
88
.PP
89
.B
90
uchar	IPv4allrouter[IPaddrlen];
91
.PP
92
.B
93
uchar	IPallbits[IPaddrlen];
94
.PP
95
.B
96
uchar	IPnoaddr[IPaddrlen];
97
.PP
98
.B
99
uchar	v4prefix[IPaddrlen];
100
.SH DESCRIPTION
101
These routines are used by Internet Protocol (IP) programs to
102
manipulate IP and Ethernet addresses.
103
Plan 9, by default, uses V6 format IP addresses.  Since V4
104
addresses fit into the V6 space, all IP addresses can be represented.
105
IP addresses are stored as a string of 16
106
.B unsigned
107
.BR chars ,
108
Ethernet
109
addresses as 6
110
.B unsigned
111
.BR chars .
112
Either V4 or V6 string representation can be used for IP addresses.
113
For V4 addresses, the representation can be (up to) 4 decimal
114
integers from 0 to 255 separated by periods.
115
For V6 addresses, the representation is (up to) 8 hex integers
116
from 0x0 to 0xFFFF separated by colons.
117
Strings of 0 integers can be elided using two colons.
118
For example,
119
.B FFFF::1111
120
is equivalent to
121
.BR FFFF:0:0:0:0:0:0:1111 .
122
The string representation for IP masks is a superset of the
123
address representation.  It includes slash notation that indicates
124
the number of leading 1 bits in the mask.  Thus, a
125
V4 class C mask can be represented as
126
.BR FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FF00 ,
127
.BR 255.255.255.0 ,
128
or
129
.BR /120.
130
The string representation of Ethernet addresses is exactly
131
12 hexadecimal digits.
132
.PP
133
.I Eipfmt
134
is a
135
.IR print (2)
136
formatter for Ethernet (verb
137
.BR E )
138
addresses,
139
IP V6 (verb
140
.BR I )
141
addresses,
142
IP V4 (verb
143
.BR V )
144
addresses,
145
and IP V6 (verb
146
.BR M )
147
masks.
148
.PP
149
.I Parseip
150
converts a string pointed to by
151
.I str
152
to a 16-byte IP address starting at
153
.IR ipaddr .
154
As a concession to backwards compatibility,
155
if the string is a V4 address, the return value
156
is an unsigned long integer containing the big-endian V4 address.
157
If not, the return value is 6.
158
.I Parseipmask
159
converts a string pointed to by
160
.I str
161
to a 6-byte IP mask starting at
162
.IR ipaddr .
163
It too returns an unsigned long big-endian V4 address or 6.
164
Both routines return -1 on errors.
165
.PP
166
.I V4parseip
167
converts a string pointed to by
168
.I str
169
to a 4-byte V4 IP address starting at
170
.IR ipaddr .
171
.PP
172
.I V4parsecidr
173
converts a string of the form
174
addr/mask, pointed to by
175
.IR str ,
176
to a 4-byte V4 IP address starting at
177
.I ipaddr
178
and a 4-byte V4 IP mask starting at
179
.IR mask .
180
.PP
181
.I Myipaddr
182
returns the first valid IP address in
183
the IP stack rooted at
184
.IR net .
185
.PP
186
.I Parseether
187
converts a string pointed to by
188
.I str
189
to a 6-byte Ethernet address starting at
190
.IR eaddr .
191
.I Myetheraddr
192
reads the Ethernet address string from file
193
.IB dev /addr
194
and parses it into
195
.IR eaddr .
196
Both routines return a negative number on errors.
197
.PP
198
.I Maskip
199
places the bit-wise AND of the IP addresses pointed
200
to by its first two arguments into the buffer pointed
201
to by the third.
202
.PP
203
.I Equivip
204
returns non-zero if the IP addresses pointed to by its two
205
arguments are equal.
206
.I Equivip4
207
operates on v4 addresses,
208
.I equivip6
209
operates on v6 addresses.
210
.I Ipcmp
211
is a macro that compares V6 addresses per
212
.IR memcmp (2)).
213
.PP
214
.I Defmask
215
returns the standard class A, B, or C mask for
216
.IR ipaddr .
217
.PP
218
.I Isv4
219
returns non-zero if the V6 address is in the V4 space, that is,
220
if it starts with
221
.BR 0:0:0:0:0:0:FFFF .
222
.I V4tov6
223
converts the 4-byte V4 address,
224
.IR v4ip ,
225
to a V6 address and puts the result in
226
.IR v6ip .
227
.I V6tov4
228
converts the V6 address,
229
.IR v6ip ,
230
to a 4-byte V4 address and puts the result in
231
.IR v4ip .
232
.PP
233
.IR Hnputs ,
234
.I hnputl
235
and
236
.I hnputv
237
are used to store 16-bit, 32-bit, and 64-bit integers, respectively, into IP big-endian form.
238
.IR Nhgets ,
239
.I nhgetl
240
and
241
.I nhgetv
242
convert big-endian 2, 4 and 8 byte quantities into integers (or
243
.IR uvlong s).
244
.PP
245
.I Pctlbsum
246
returns the one's complement checksum used in IP protocols, typically invoked as
247
.IP
248
.EX
249
hnputs(hdr->cksum, ~ptclbsum(data, len) & 0xffff);
250
.EE
251
.PP
252
A number of standard IP addresses in V6 format are also defined.  They are:
253
.TF IPv4allrouter
254
.TP
255
.B IPv4bcast
256
the V4 broadcast address
257
.TP
258
.B IPv4allsys
259
the V4 all systems multicast address
260
.TP
261
.B IPv4allrouter
262
the V4 all routers multicast address
263
.TP
264
.B IPallbits
265
the V6 all bits on address
266
.TP
267
.B IPnoaddr
268
the V6 null address, all zeros
269
.TP
270
.B v4prefix
271
the IP V6 prefix to all embedded V4 addresses
272
.PD
273
.PP
274
.I Readipifc
275
returns information about
276
a particular interface
277
.RI ( index
278
>= 0)
279
or all IP interfaces
280
.RI ( index
281
< 0)
282
configured under a mount point
283
.IR net ,
284
default
285
.BR /net .
286
Each interface is described by one
287
.I Ipifc
288
structure which in turn points to a linked list of
289
.IR Iplifc
290
structures describing the addresses assigned
291
to this interface.
292
If the list
293
.IR ifc
294
is supplied,
295
that list is freed.
296
Thus, subsequent calls can be used
297
to free the list returned by the previous call.
298
.I Ipifc
299
is:
300
.PP
301
.EX
302
typedef struct Ipifc
303
{
304
	Ipifc	*next;
305
	Iplifc	*lifc;		/* local addressses */
306
 
307
	/* per ip interface */
308
	int	index;		/* number of interface in ipifc dir */
309
	char	dev[64];	/* associated physical device */
310
 	int	mtu;		/* max transfer unit */
311
 
312
	uchar	sendra6;	/* on == send router adv */
313
	uchar	recvra6;	/* on == rcv router adv */
314
 
315
	ulong	pktin;		/* packets read */
316
	ulong	pktout;		/* packets written */
317
	ulong	errin;		/* read errors */
318
	ulong	errout;		/* write errors */
319
	Ipv6rp	rp;		/* route advertisement params */
320
} Ipifc;
321
.EE
322
.PP
323
.I Iplifc
324
is:
325
.PP
326
.EX
327
struct Iplifc
328
{
329
	Iplifc	*next;
330
 
331
	uchar	ip[IPaddrlen];
332
	uchar	mask[IPaddrlen];
333
	uchar	net[IPaddrlen];		/* ip & mask */
334
	ulong	preflt;			/* preferred lifetime */
335
	ulong	validlt;		/* valid lifetime */
336
};
337
.EE
338
.PP
339
.I Ipv6rp
340
is:
341
.PP
342
.EX
343
struct Ipv6rp
344
{
345
	int	mflag;
346
	int	oflag;
347
	int 	maxraint;	/* max route adv interval */
348
	int	minraint;	/* min route adv interval */
349
	int	linkmtu;
350
	int	reachtime;
351
	int	rxmitra;
352
	int	ttl;
353
	int	routerlt;	
354
};
355
.EE
356
.PP
357
.I Dev
358
contains the first 64 bytes of the device configured with this
359
interface.
360
.I Net
361
is
362
.IB ip & mask
363
if the network is multipoint or
364
the remote address if the network is
365
point to point.
366
.SH SOURCE
367
.B /sys/src/libip
368
.SH SEE ALSO
369
.IR print (2),
370
.IR ip (3)