Charles.Forsyth20060303-partialeea662d19 years agoHistory
334 lines · 7.4 KB · Text
RawDownload
.TH IP 2.SH NAMEIP \- Internet Protocol addresses and interfaces.SH SYNOPSIS.EXinclude "ip.m";ip := load IP IP->PATH;IPaddr: import IP; IPaddr: adt {   newv6:   fn(nil: array of byte): IPaddr;   newv4:   fn(nil: array of byte): IPaddr;   copy:    fn(nil: self IPaddr): IPaddr;   eq:      fn(nil: self IPaddr, v: IPaddr): int;   mask:    fn(nil: self IPaddr, m: IPaddr): IPaddr;   isv4:    fn(nil: self IPaddr): int;   ismulticast: fn(nil: self IPaddr): int;   isvalid: fn(nil: self IPaddr): int;    v4:      fn(nil: self IPaddr): array of byte;   v6:      fn(nil: self IPaddr): array of byte;   class:   fn(nil: self IPaddr): int;   classmask: fn(nil: self IPaddr): IPaddr;    parse:     fn(s: string): (int, IPaddr);   parsemask: fn(s: string): (int, IPaddr);   parsecidr: fn(s: string): (int, IPaddr, IPaddr);    text:     fn(nil: self IPaddr): string;   masktext: fn(nil: self IPaddr): string;}; v4bcast, v4allsys, v4allrouter, noaddr, allbits: IPaddr;selfv6, selfv4: IPaddr;v4prefix: array of byte; Ifcaddr: adt {   ip:   IPaddr;     # local interface address   mask: IPaddr;     # subnet mask   net:  IPaddr;     # ip & mask   preflt:  big;     # preferred life time   validlt: big;     # valid life time}; Ipifc: adt {   index:   int;     # /net/ipifc/N   dev:     string;  # bound device   addrs:   list of ref Ifcaddr;   sendra:  int;     # !=0, send router adverts   recvra:  int;     # !=0, receive router adverts   mtu:     int;   pktin:   big;     # packets in   pktout:  big;     # packets out   errin:   big;     # input errors   errout:  big;     # output errors   rp:      IPv6rp;  # IPv6 route advert parameters}; IPv6rp: adt {   mflag:   int;   oflag:   int;   maxraint: int;    # max route advert interval   minraint: int;    # min route advert interval   linkmtu:  int;   reachtime: int;   rxmitra:   int;   ttl:       int;   routerlt:  int;}; init: fn();readipifc:  fn(net: string, index: int): (list of ref Ipifc, string);.EE.SH DESCRIPTION.B IPprovides data types and operations that manipulate Internet Protocol addresses,and operations that convert between internal and textual address forms,for both IPv4 and IPv6.The textual forms are those defined by RFC2373.Briefly, an IPv6 address is 16 bytes, represented textually as a sequenceof 8 colon-separated hexadecimal values ranging from.B 0to.BR FFFF ,except that any one sequence of zeroes can be replaced by.BR :: .IPv4 addresses are embedded in the IPv6 space with a prefix of either.B 0:0:0:0:0:FFFF(for addresses of `IPv4-mapped' nodes), or.BR 0:0:0:0:0:0(for `IPv4-compatible' IPv6 nodes).See RFC2373 for the distinction.For convenience in working with such addresses, the textual syntaxallows the last 4 bytes of an IPv6 address to be specified using arestricted IPv4 syntax, allowing an address to end in four dot-separated decimal values(for example,.BR 0:0:0:0:0:FFFF:127.0.0.1for the IPv4 loopback address).The functions here also accept the common forms of IPv4 syntax with one or two valuesomitted (eg,.B 127.1for the loopback address),and accept IPv4 format for masks(eg,.BR 255.255.254.0 )..PP.B Initmust be called once before using any value or function of the module..PPAn Internet address or network mask  is represented by an.B IPaddrvalue.It has the following operations:.TP.BI IPaddr.newv6( a )Return an.B IPaddrrepresenting the IPv6 address stored in.I aas an array of 16 bytes.TP.BI IPaddr.newv4( a )Return an.B IPaddrrepresenting the IPv4 address stored in.I aas an array of 4 bytes.TP.BI IPaddr.parse( s )Return a tuple.BI ( ok , ip ).If.I okis 0,.I ipis an.B IPaddrrepresenting the address in textual format in the string.IR s ,which can be in either IPv4 or IPv6 syntax.If.I okis negative,.I swas invalid..TP.BI IPaddr.parsemask( s ).I Sis a text string defining a mask, in one of three forms:.BI / nbitswhere.I nbitsis the number of leading one bits in the mask, ranging from 0 to 128;an IPv4 mask (eg,.BR 255.255.254.0 );or an IPv6 mask.Return a tuple.BI ( ok , m )\fR.If.I okis 0,.I mis an.B IPaddrrepresenting the mask given by.IR s .If.I okis negative,.I swas invalid..TP.BI IPaddr.parsecidr( s ).I Sis an address-mask combination in Classless Inter-Domain Routing (CIDR) format:.IB ip-address / prefix-length,where.I ip-addressis an address in any form accepted by.B parseabove, and.I prefix-lengthis a decimal value giving the number of leftmost bits in.I ip-addressthat form the addressing prefix (ie, subnet prefix).Return a tuple.BI ( ok , ip , m\fR).If.I okis 0,.I ipand.I mare.B IPaddrvalues for the address and mask given by.IR s .If.I okis negative,.I sis invalid..TP.IB ip .copy()Return a copy of the value.I ip.TP.IB ip .eq( v )Return true (non-zero) if.I iprepresents the same address as.IR v ;return false (zero) otherwise..TP.IB ip .mask( m )Return the value.BI ( ip & m ) ,that is, address.I ipmasked by.I m.TP.IB ip .isv4()Return true if.I ipis an IPv4 address; return false ifotherwise (it can only be used on a full IPv6 network).TP.IB ip .v4()Return the value of.I ipas a 4-byte array in IPv4 representation if it can be so represented;if.I ipis not an IPv4 address, return nil..TP.IB ip .v6()Return the value of.I ipin IPv6 addressing format as an array of 16 bytes.TP.IB ip .class()If.I ipis an IPv4 address, return its class (0 to 3); if it is an IPv6 address, return 6..TP.IB ip .classmask()If.I ipis an IPv4 address, return the mask associated with its class; if.I ipis an IPv6 address, return a mask that is all ones..TP.IB ip .ismulticast()Return true if.I ipis a multicast or broadcast address..TP.IB ip .isvalid()Return true if.I ipis not the zero address in either IPv4 or IPv6 address space.TP.IB ip .text()Return a textual representation of the address.I ipin either IPv4 or IPv6 format as appropriate..TP.IB ip .masktext()Return a textual representation of the address.I ipas one of: an IPv4 mask;.BI / nwhere.I nis the number of leading 1 bits, as used in CIDR syntax; oras a full IPv6 textual address.The format used is appropriate to the structure of the value..PPThe module provides some predefined.B IPaddrvalues, mainly for common IPv4 addresses:.B v4bcast(broadcast address),.B v4allsys(all hosts multicast address),.B v4allrouter(all routers multicast address),.B selfv4(loopback in IPv4),.B selfv6(loopback in IPv6),.B noaddr(all zero address, used before a node has an address),.B v4noaddr(all zero address with IPv4 prefix),and.B allbits(address of all 1 bits).The 12-byte IPv6 prefix for IPv4 embedded addresses is provided inthe array of bytes.BR v4prefix ..PP.B Readipifcreturns a list of the host's IP interfacesand the attributes and addresses of each,read from the interface status files in.BR /net/ipifc .On an error, the string in the returned tuple contains a diagnostic and the list is nil.Each interface is represented by an.B Ipifcvalue, which contains a list of local interface addresses,.BR addrs .Each local address is represented by an.B Iplifcvalue in that list..SH FILES.TF /net/ipifc/N/status.TP.B /net/ipifcdirectory of IP interfaces.TP.BI /net/ipifc/ n /statusstatus and addresses of interface.I n.SH SOURCE.B /appl/lib/ip.b.SH SEE ALSO.IR ether (2),.IR ip (3).SH BUGS.B Readipifcis currently only usable in native Inferno.That will change shortly.