345 lines
18 KiB
HTML
345 lines
18 KiB
HTML
<head>
|
|
<title>ip(3) - Plan 9 from User Space</title>
|
|
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
|
|
</head>
|
|
<body bgcolor=#ffffff>
|
|
<table border=0 cellpadding=0 cellspacing=0 width=100%>
|
|
<tr height=10><td>
|
|
<tr><td width=20><td>
|
|
<tr><td width=20><td><b>IP(3)</b><td align=right><b>IP(3)</b>
|
|
<tr><td width=20><td colspan=2>
|
|
<br>
|
|
<p><font size=+1><b>NAME </b></font><br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
eipfmt, parseip, parseipmask, v4parseip, v4parsecidr, parseether,
|
|
myipaddr, myetheraddr, maskip, equivip, defmask, isv4, v4tov6,
|
|
v6tov4, nhgetl, nhgets, nhgetv, hnputl, hnputs, hnputv, ptclbsum,
|
|
readipifc – Internet protocol<br>
|
|
|
|
</table>
|
|
<p><font size=+1><b>SYNOPSIS </b></font><br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
<tt><font size=+1>#include <u.h><br>
|
|
#include <libc.h><br>
|
|
#include <ip.h>
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>int eipfmt(Fmt*)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>ulong parseip(uchar *ipaddr, char *str)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>ulong parseipmask(uchar *ipaddr, char *str)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>char* v4parseip(uchar *ipaddr, char *str)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>ulong v4parsecidr(uchar *addr, uchar *mask, char *str)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>int parseether(uchar *eaddr, char *str)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>int myetheraddr(uchar *eaddr, char *dev)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>int myipaddr(uchar *ipaddr, char *net)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>void maskip(uchar *from, uchar *mask, uchar *to)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>int equivip(uchar *ipaddr1, uchar *ipaddr2)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>uchar* defmask(uchar *ipaddr)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>int isv4(uchar *ipaddr)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>void v4tov6(uchar *ipv6, uchar *ipv4)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>void v6tov4(uchar *ipv4, uchar *ipv6)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>ushort nhgets(void *p)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>uint nhgetl(void *p)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>uvlong nhgetv(void *p)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>void hnputs(void *p, ushort v)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>void hnputl(void *p, uint v)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>void hnputv(void *p, uvlong v)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>ushort ptclbsum(uchar *a, int n)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>Ipifc* readipifc(char *net, Ipifc *ifc, int index)
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>uchar IPv4bcast[IPaddrlen];
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>uchar IPv4allsys[IPaddrlen];
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>uchar IPv4allrouter[IPaddrlen];
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>uchar IPallbits[IPaddrlen];
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>uchar IPnoaddr[IPaddrlen];
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>uchar v4prefix[IPaddrlen];<br>
|
|
</font></tt>
|
|
</table>
|
|
<p><font size=+1><b>DESCRIPTION </b></font><br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
These routines are used by Internet Protocol (IP) programs to
|
|
manipulate IP and Ethernet addresses. Plan 9, by default, uses
|
|
V6 format IP addresses. Since V4 addresses fit into the V6 space,
|
|
all IP addresses can be represented. IP addresses are stored as
|
|
a string of 16 <tt><font size=+1>unsigned chars</font></tt>, Ethernet addresses as 6
|
|
<tt><font size=+1>unsigned chars</font></tt>. Either V4 or V6 string representation can be used
|
|
for IP addresses. For V4 addresses, the representation can be
|
|
(up to) 4 decimal integers from 0 to 255 separated by periods.
|
|
For V6 addresses, the representation is (up to) 8 hex integers
|
|
from 0x0 to 0xFFFF separated by colons. Strings of 0
|
|
integers can be elided using two colons. For example, <tt><font size=+1>FFFF::1111</font></tt>
|
|
is equivalent to <tt><font size=+1>FFFF:0:0:0:0:0:0:1111</font></tt>. The string representation
|
|
for IP masks is a superset of the address representation. It includes
|
|
slash notation that indicates the number of leading 1 bits in
|
|
the mask. Thus, a V4 class C mask can be
|
|
represented as <tt><font size=+1>FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FF00</font></tt>, <tt><font size=+1>255.255.255.0</font></tt>,
|
|
or <tt><font size=+1>/120.</font></tt> The string representation of Ethernet addresses is exactly
|
|
12 hexadecimal digits.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>Eipfmt</i> is a <a href="../man3/print.html"><i>print</i>(3)</a> formatter for Ethernet (verb <tt><font size=+1>E</font></tt>) addresses,
|
|
IP V6 (verb <tt><font size=+1>I</font></tt>) addresses, IP V4 (verb <tt><font size=+1>V</font></tt>) addresses, and IP V6
|
|
(verb <tt><font size=+1>M</font></tt>) masks.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>Parseip</i> converts a string pointed to by <i>str</i> to a 16-byte IP address
|
|
starting at <i>ipaddr</i>. As a concession to backwards compatibility,
|
|
if the string is a V4 address, the return value is an unsigned
|
|
long integer containing the big-endian V4 address. If not, the
|
|
return value is 6. <i>Parseipmask</i> converts a string pointed to by
|
|
<i>str
|
|
</i>to a 6-byte IP mask starting at <i>ipaddr</i>. It too returns an unsigned
|
|
long big-endian V4 address or 6. Both routines return -1 on errors.
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>V4parseip</i> converts a string pointed to by <i>str</i> to a 4-byte V4 IP
|
|
address starting at <i>ipaddr</i>.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>V4parsecidr</i> converts a string of the form addr/mask, pointed to
|
|
by <i>str</i>, to a 4-byte V4 IP address starting at <i>ipaddr</i> and a 4-byte
|
|
V4 IP mask starting at <i>mask</i>.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>Myipaddr</i> returns the first valid IP address in the IP stack rooted
|
|
at <i>net</i>.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>Parseether</i> converts a string pointed to by <i>str</i> to a 6-byte Ethernet
|
|
address starting at <i>eaddr</i>. <i>Myetheraddr</i> reads the Ethernet address
|
|
string from file <i>dev</i><tt><font size=+1>/1/stats</font></tt> and parses it into <i>eaddr</i>. Both routines
|
|
return a negative number on errors.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>Maskip</i> places the bit-wise AND of the IP addresses pointed to
|
|
by its first two arguments into the buffer pointed to by the third.
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>Equivip</i> returns non-zero if the IP addresses pointed to by its
|
|
two arguments are equal.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>Defmask</i> returns the standard class A, B, or C mask for <i>ipaddr</i>.
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>Isv4</i> returns non-zero if the V6 address is in the V4 space, that
|
|
is, if it starts with <tt><font size=+1>0:0:0:0:0:0:FFFF</font></tt>. <i>V4tov6</i> converts the V4
|
|
address, <i>v4ip</i>, to a V6 address and puts the result in <i>v6ip</i>. <i>V6tov4</i>
|
|
converts the V6 address, <i>v6ip</i>, to a V4 address and puts the result
|
|
in <i>v4ip</i>.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>Hnputs</i>, <i>hnputl</i>, and <i>hnputv</i> are used to store 16-, 32-, and 64-bit
|
|
integers into IP big-endian form. <i>Nhgets</i>, <i>nhgetl</i>, and <i>nhgetv</i> convert
|
|
big-endian 2-, 4-, and 8-byte quantities into integers.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>Pctlbsum</i> returns the one’s complement checksum used in IP protocols,
|
|
typically invoked as<br>
|
|
<tt><font size=+1>hnputs(hdr−>cksum, ~ptclbsum(data, len) & 0xffff);<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
A number of standard IP addresses in V6 format are also defined.
|
|
They are:<br>
|
|
<tt><font size=+1>IPv4bcast<br>
|
|
</font></tt>
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
the V4 broadcast address<br>
|
|
|
|
</table>
|
|
<tt><font size=+1>IPv4allsys<br>
|
|
</font></tt>
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
the V4 all systems multicast address<br>
|
|
|
|
</table>
|
|
<tt><font size=+1>IPv4allrouter<br>
|
|
</font></tt>
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
the V4 all routers multicast address<br>
|
|
|
|
</table>
|
|
<tt><font size=+1>IPallbits<br>
|
|
</font></tt>
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
the V6 all bits on address<br>
|
|
|
|
</table>
|
|
<tt><font size=+1>IPnoaddr<br>
|
|
</font></tt>
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
the V6 null address, all zeros<br>
|
|
|
|
</table>
|
|
<tt><font size=+1>v4prefix<br>
|
|
</font></tt>
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
the IP V6 prefix to all embedded V4 addresses
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
|
|
</table>
|
|
<i>Readipifc</i> returns information about a particular interface (<i>index
|
|
</i>>= 0) or all IP interfaces (<i>index </i>< 0) configured under a mount
|
|
point <i>net</i>, default <tt><font size=+1>/net</font></tt>. Each interface is described by one <i>Ipifc</i>
|
|
structure which in turn points to a linked list of <i>Iplifc</i> structures
|
|
describing the addresses assigned to this interface. If the list
|
|
<i>ifc</i> is supplied, that list is freed. Thus, subsequent calls can
|
|
be used to free the list returned by the previous call. <i>Ipifc</i>
|
|
is:
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<tt><font size=+1>typedef struct Ipifc<br>
|
|
{<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
Ipifc *next;<br>
|
|
Iplifc *lifc; /* local addressses */<br>
|
|
/* per ip interface */<br>
|
|
int index; /* number of interface in ipifc dir */<br>
|
|
char dev[64]; /* associated physical device */<br>
|
|
int mtu; /* max transfer unit */<br>
|
|
long validlt; /* valid life time */<br>
|
|
long preflt; /* preferred life time */<br>
|
|
uchar sendra6; /* on == send router adv */<br>
|
|
uchar recvra6; /* on == rcv router adv */<br>
|
|
ulong pktin; /* packets read */<br>
|
|
ulong pktout; /* packets written */<br>
|
|
ulong errin; /* read errors */<br>
|
|
ulong errout; /* write errors */<br>
|
|
Ipv6rp rp; /* route advertisement params */<br>
|
|
|
|
</table>
|
|
} Ipifc;<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<i>Iplifc</i> is:
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<tt><font size=+1>struct Iplifc<br>
|
|
{<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
Iplifc *next;<br>
|
|
uchar ip[IPaddrlen];<br>
|
|
uchar mask[IPaddrlen];<br>
|
|
uchar net[IPaddrlen]; /* ip & mask */<br>
|
|
ulong preflt; /* preferred lifetime */<br>
|
|
ulong validlt; /* valid lifetime */<br>
|
|
|
|
</table>
|
|
};<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<i>Ipv6rp</i> is: struct Ipv6rp { int mflag; int oflag; int maxraint;
|
|
/* max route adv interval */ int minraint; /* min route adv interval
|
|
*/ int linkmtu; int reachtime; int rxmitra; int ttl; int routerlt;
|
|
};
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>Dev</i> contains the first 64 bytes of the device configured with
|
|
this interface. <i>Net</i> is <i>ip</i><tt><font size=+1>&</font></tt><i>mask</i> if the network is multipoint or
|
|
the remote address if the network is point to point.<br>
|
|
|
|
</table>
|
|
<p><font size=+1><b>SOURCE </b></font><br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
<tt><font size=+1>/usr/local/plan9/src/libip<br>
|
|
</font></tt>
|
|
</table>
|
|
<p><font size=+1><b>SEE ALSO </b></font><br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
<a href="../man3/print.html"><i>print</i>(3)</a><br>
|
|
|
|
</table>
|
|
|
|
<td width=20>
|
|
<tr height=20><td>
|
|
</table>
|
|
<!-- TRAILER -->
|
|
<table border=0 cellpadding=0 cellspacing=0 width=100%>
|
|
<tr height=15><td width=10><td><td width=10>
|
|
<tr><td><td>
|
|
<center>
|
|
<a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a>
|
|
</center>
|
|
</table>
|
|
<!-- TRAILER -->
|
|
</body></html>
|