plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

ip.3 (7110B)


      1 .TH IP 3
      2 .SH NAME
      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
      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 ulong	parseip(uchar *ipaddr, char *str)
     16 .PP
     17 .B
     18 ulong	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	equivip(uchar *ipaddr1, uchar *ipaddr2)
     40 .PP
     41 .B
     42 uchar*	defmask(uchar *ipaddr)
     43 .PP
     44 .B
     45 int	isv4(uchar *ipaddr)
     46 .PP
     47 .B
     48 void	v4tov6(uchar *ipv6, uchar *ipv4)
     49 .PP
     50 .B
     51 void	v6tov4(uchar *ipv4, uchar *ipv6)
     52 .PP
     53 .B
     54 ushort	nhgets(void *p)
     55 .PP
     56 .B
     57 uint	nhgetl(void *p)
     58 .PP
     59 .B
     60 uvlong	nhgetv(void *p)
     61 .PP
     62 .B
     63 void	hnputs(void *p, ushort v)
     64 .PP
     65 .B
     66 void	hnputl(void *p, uint v)
     67 .PP
     68 .B
     69 void	hnputv(void *p, uvlong v)
     70 .PP
     71 .B
     72 ushort	ptclbsum(uchar *a, int n)
     73 .PP
     74 .B
     75 Ipifc*	readipifc(char *net, Ipifc *ifc, int index)
     76 .PP
     77 .B
     78 uchar	IPv4bcast[IPaddrlen];
     79 .PP
     80 .B
     81 uchar	IPv4allsys[IPaddrlen];
     82 .PP
     83 .B
     84 uchar	IPv4allrouter[IPaddrlen];
     85 .PP
     86 .B
     87 uchar	IPallbits[IPaddrlen];
     88 .PP
     89 .B
     90 uchar	IPnoaddr[IPaddrlen];
     91 .PP
     92 .B
     93 uchar	v4prefix[IPaddrlen];
     94 .SH DESCRIPTION
     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
    100 .B unsigned
    101 .BR chars ,
    102 Ethernet
    103 addresses as 6
    104 .B unsigned
    105 .BR chars .
    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.
    112 For example,
    113 .B FFFF::1111
    114 is equivalent to
    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 ,
    121 .BR 255.255.255.0 ,
    122 or
    123 .BR /120.
    124 The string representation of Ethernet addresses is exactly
    125 12 hexadecimal digits.
    126 .PP
    127 .I Eipfmt
    128 is a
    129 .MR print (3)
    130 formatter for Ethernet (verb
    131 .BR E )
    132 addresses,
    133 IP V6 (verb
    134 .BR I )
    135 addresses,
    136 IP V4 (verb
    137 .BR V )
    138 addresses,
    139 and IP V6 (verb
    140 .BR M )
    141 masks.
    142 .PP
    143 .I Parseip
    144 converts a string pointed to by
    145 .I str
    146 to a 16-byte IP address starting at
    147 .IR ipaddr .
    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.
    152 .I Parseipmask
    153 converts a string pointed to by
    154 .I str
    155 to a 6-byte IP mask starting at
    156 .IR ipaddr .
    157 It too returns an unsigned long big-endian V4 address or 6.
    158 Both routines return -1 on errors.
    159 .PP
    160 .I V4parseip
    161 converts a string pointed to by
    162 .I str
    163 to a 4-byte V4 IP address starting at
    164 .IR ipaddr .
    165 .PP
    166 .I V4parsecidr
    167 converts a string of the form
    168 addr/mask, pointed to by
    169 .IR str ,
    170 to a 4-byte V4 IP address starting at
    171 .I ipaddr
    172 and a 4-byte V4 IP mask starting at
    173 .IR mask .
    174 .PP
    175 .I Myipaddr
    176 returns the first valid IP address in
    177 the IP stack rooted at
    178 .IR net .
    179 .PP
    180 .I Parseether
    181 converts a string pointed to by
    182 .I str
    183 to a 6-byte Ethernet address starting at
    184 .IR eaddr .
    185 .I Myetheraddr
    186 reads the Ethernet address string from file
    187 .IB dev /1/stats
    188 and parses it into
    189 .IR eaddr .
    190 Both routines return a negative number on errors.
    191 .PP
    192 .I Maskip
    193 places the bit-wise AND of the IP addresses pointed
    194 to by its first two arguments into the buffer pointed
    195 to by the third.
    196 .PP
    197 .I Equivip
    198 returns non-zero if the IP addresses pointed to by its two
    199 arguments are equal.
    200 .PP
    201 .I Defmask
    202 returns the standard class A, B, or C mask for
    203 .IR ipaddr .
    204 .PP
    205 .I Isv4
    206 returns non-zero if the V6 address is in the V4 space, that is,
    207 if it starts with
    208 .BR 0:0:0:0:0:0:FFFF .
    209 .I V4tov6
    210 converts the V4 address,
    211 .IR v4ip ,
    212 to a V6 address and puts the result in
    213 .IR v6ip .
    214 .I V6tov4
    215 converts the V6 address,
    216 .IR v6ip ,
    217 to a V4 address and puts the result in
    218 .IR v4ip .
    219 .PP
    220 .IR Hnputs ,
    221 .IR hnputl ,
    222 and
    223 .I hnputv
    224 are used to store 16-, 32-, and 64-bit integers into IP big-endian form.
    225 .IR Nhgets ,
    226 .IR nhgetl ,
    227 and
    228 .I nhgetv
    229 convert big-endian 2-, 4-, and 8-byte quantities into integers.
    230 .PP
    231 .I Pctlbsum
    232 returns the one's complement checksum used in IP protocols, typically invoked as
    233 .EX
    234 hnputs(hdr->cksum, ~ptclbsum(data, len) & 0xffff);
    235 .EE
    236 .PP
    237 A number of standard IP addresses in V6 format are also defined.  They
    238 are:
    239 .IP \f5IPv4bcast
    240 the V4 broadcast address
    241 .IP \f5IPv4allsys
    242 the V4 all systems multicast address
    243 .IP \f5IPv4allrouter
    244 the V4 all routers multicast address
    245 .IP \f5IPallbits
    246 the V6 all bits on address
    247 .IP \f5IPnoaddr
    248 the V6 null address, all zeros
    249 .IP \f5v4prefix
    250 the IP V6 prefix to all embedded V4 addresses
    251 .PP
    252 .I Readipifc
    253 returns information about
    254 a particular interface  (\fIindex\fP >= 0)
    255 or all IP interfaces (\fIindex\fP < 0)
    256 configured under a
    257 mount point
    258 .IR net ,
    259 default
    260 .BR /net .
    261 Each interface is described by one
    262 .I Ipifc
    263 structure which in turn points to a linked list of
    264 .IR Iplifc
    265 structures describing the addresses assigned
    266 to this interface.
    267 If the list
    268 .IR ifc
    269 is supplied,
    270 that list is freed.
    271 Thus, subsequent calls can be used
    272 to free the list returned by the previous call.
    273 .I Ipifc
    274 is:
    275 .PP
    276 .EX
    277 typedef struct Ipifc
    278 {
    279 	Ipifc	*next;
    280 	Iplifc	*lifc;		/* local addressses */
    281 
    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 */
    286 
    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 */
    291 
    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 */
    297 } Ipifc;
    298 .EE
    299 .PP
    300 .I Iplifc
    301 is:
    302 .PP
    303 .EX
    304 struct Iplifc
    305 {
    306 	Iplifc	*next;
    307 
    308 	uchar	ip[IPaddrlen];
    309 	uchar	mask[IPaddrlen];
    310 	uchar	net[IPaddrlen];		/* ip & mask */
    311 	ulong	preflt;			/* preferred lifetime */
    312 	ulong	validlt;		/* valid lifetime */
    313 };
    314 .EE
    315 .PP
    316 .I Ipv6rp
    317 is:
    318 struct Ipv6rp
    319 {
    320 	int	mflag;
    321 	int	oflag;
    322 	int 	maxraint;	/* max route adv interval */
    323 	int	minraint;	/* min route adv interval */
    324 	int	linkmtu;
    325 	int	reachtime;
    326 	int	rxmitra;
    327 	int	ttl;
    328 	int	routerlt;	
    329 };
    330 .PP
    331 .I Dev
    332 contains the first 64 bytes of the device configured with this
    333 interface.
    334 .I Net
    335 is
    336 .IB ip & mask
    337 if the network is multipoint or
    338 the remote address if the network is
    339 point to point.
    340 .SH SOURCE
    341 .B \*9/src/libip
    342 .SH SEE ALSO
    343 .MR print (3)