Oberon || Library || Module Index || Search Engine || Definition || Module


Ulm's Oberon Library:
IPv6Addresses


NAME

IPv6Addresses - support of IPv6 addresses

SYNOPSIS

CONST nbytes = 16;
TYPE Address = ARRAY nbytes OF CHAR;
TYPE PortNumber = IPv4Addresses.PortNumber;
TYPE SocketAddress =
      RECORD
         (Objects.ObjectRec)
         host: Address;
         portnum: PortNumber;
      END;


CONST addrlen = 32; (* size of struct sockaddr_in6 in <sys/socket.h> *) TYPE SysAddress = ARRAY addrlen OF BYTE;

CONST invalidInputChar = 0; CONST multipleDoubleColons = 1; CONST unexpectedEOF = 2; CONST valueOutOfRange = 3; CONST tripleColon = 4; CONST errors = 5; TYPE ErrorCode = SHORTINT; (* invalidInputChar... *) TYPE ErrorEvent = POINTER TO ErrorEventRec; TYPE ErrorEventRec = RECORD (Events.EventRec) errorcode: ErrorCode; pos: Streams.Count; END; VAR errormsg: ARRAY errors OF Events.Message; VAR error: Events.EventType;

PROCEDURE GetPort(address: SocketAddress) : INTEGER; PROCEDURE SetPort(VAR address: SocketAddress; portnum: INTEGER); PROCEDURE IsAnyAddr(address: Address) : BOOLEAN; PROCEDURE SetAnyAddr(VAR address: Address);

PROCEDURE ConvertToSys(address: SocketAddress; VAR sysaddr: SysAddress); PROCEDURE ConvertFromSys(sysaddr: SysAddress; VAR address: SocketAddress);

PROCEDURE ReadText(s: Streams.Stream; VAR ipaddr: Address) : BOOLEAN; PROCEDURE WriteText(s: Streams.Stream; ipaddr: Address); PROCEDURE CreateAddress(VAR ipaddr: Address; text: ARRAY OF CHAR);

DESCRIPTION

IPv6Addresses provides support for IPv6 addresses. SocketAddress represents IPv6 addresses in an easily accessible way. Note however, that the fields host and portnum must be kept or are to be interpreted in network order, i.e. in big-endian byte order. The routines GetPort and SetPort can be used to convert the port number from and to network order. SetAnyAddr zeroes address and IsAnyAddr tests if address consists of zeroes only.

SysAddress represents IPv6 addresses in an internal form which can be passed to the operations of SysSockets. ConvertToSys and ConvertFromSys allow IPv6 addresses to be converted to and from the internal form.

IPv6 addresses in a textual representation that conforms to RFC 1884, section 2.2, paragraphs 1 and 2 (but not 3) can be read by ReadText. WriteText prints ipaddr in the compressed notation to s. CreateAddress allows to create an IPv6 address directly from a string that is accepted by ReadText.

DIAGNOSTICS

ReadText generates following error events and relates them to s (see RelatedEvents) in case of syntax errors:
invalidInputChar
The text representation of an IPv6 address is not yet complete but a character was found which is neither a colon nor a hexadecimal digit.
multipleDoubleColons
More than one ``::'' construct was found.
unexpectedEOF
End of the input stream was detected while the textual representation of the IPv6 address was not yet complete.
valueOutOfRange
One of the values did not fit into 16 bit, i.e. exceeded 0FFFFH.
tripleColon
Three or more consecutive colons where found.
Note that the stream position pos that is given in the error events is to be interpreted relative to the stream position where ReadText starts reading.

CreateAddress asserts that text is accepted by ReadText.

SEE ALSO

IPv4Addresses
support of IPv4 addresses
SysSockets
system calls for sockets

Edited by: borchert, last change: 2006/08/09, revision: 1.4, converted to HTML: 2006/08/09

Oberon || Library || Module Index || Search Engine || Definition || Module