Oberon || Library || Module Index || Search Engine || Definition || Module
TYPE HostPort = POINTER TO HostPortRec; TYPE HostPortRec = RECORD (Disciplines.ObjectRec) port: INTEGER; host: DNSRecords.Name; END; TYPE IPv4HostPort = POINTER TO IPv4HostPortRec; TYPE IPv4HostPortRec = RECORD (HostPortRec) address: IPv4Addresses.SocketAddress; END; TYPE IPv6HostPort = POINTER TO IPv6HostPortRec; TYPE IPv6HostPortRec = RECORD (HostPortRec) address: IPv6Addresses.SocketAddress; END;
TYPE AddIPv4Address = PROCEDURE (service: Disciplines.Object; address: IPv4Addresses.SocketAddress) : BOOLEAN; TYPE AddIPv6Address = PROCEDURE (service: Disciplines.Object; address: IPv6Addresses.SocketAddress) : BOOLEAN; TYPE Interface = POINTER TO InterfaceRec; TYPE InterfaceRec = RECORD (Objects.ObjectRec) addIPv4Address: AddIPv4Address; addIPv6Address: AddIPv6Address; END;
CONST unexpectedEOF = 0; CONST closingBracketMissing = 1; CONST hostnameTooLong = 2; CONST tooManyDots = 3; CONST invalidPort = 4; CONST errors = 5; TYPE ErrorCode = SHORTINT; (* unexpectedEOF... *) TYPE ErrorEvent = POINTER TO ErrorEventRec; TYPE ErrorEventRec = RECORD (Events.EventRec) errorcode: ErrorCode; END; VAR errormsg: ARRAY errors OF Events.Message; VAR error: Events.EventType;
PROCEDURE SetDefaultPort(s: Streams.Stream; port: INTEGER); PROCEDURE SetPort(s: Streams.Stream; port: INTEGER);
PROCEDURE ReadText(s: Streams.Stream; VAR hostport: HostPort) : BOOLEAN; PROCEDURE WriteText(s: Streams.Stream; hostport: HostPort);
PROCEDURE CreateAddress(VAR address: Networks.Address; hostport: HostPort);
PROCEDURE ReadAddress(s: Streams.Stream; VAR address: Networks.Address) : BOOLEAN;
PROCEDURE Init(service: Disciplines.Object; if: Interface); PROCEDURE Add(service: Disciplines.Object; hostport: HostPort) : BOOLEAN; PROCEDURE ReadAndAdd(s: Streams.Stream; service: Disciplines.Object) : BOOLEAN;
Following syntax is given by RFCs 2396 and 2732:
SetDefaultPort sets the default port of a specification for the given input stream if the port is omitted. SetPort causes ReadText not to look for a port in the input specification and to take the given value instead.
Read host/port tuples are represented by HostPort objects which come in two extensions: IPv4HostPort and IPv6HostPort. The common fields host and port are close to the actual input seen by ReadText, i.e. if a numerical IP address was given, host provides the corresponding text represenation (without the brackets in case of IPv6 addresses). The extensions provide the associated address specifications which can be passed on to IPv4TCPSockets, IPv6TCPSockets, InetTCP, Inet6TCP, or, after a conversion to the internal format, to SysSockets. HostPort objects are to be created only by ReadText.
ReadText parses a hostport specification from the given input specification, and, if successful, creates a HostPort object for it. WriteText prints a textual representation of hostport to s which is close to the original input.
CreateAddress uses InetTCP or Inet6TCP to create an abstract network address object of Networks. ReadAddress combines ReadText and CreateAddress.
To ease the specification of IPv4 or IPv6 addresses to other modules, an interface is provided which allows Add to pass on the address to the corresponding procedure. For this to work, the module that accepts addresses has to define an interface consisting of addIPv4Address and addIPv6Address and to associate it with its newly created object using Init. Afterwards, client modules are free to use Add or ReadAndAdd to pass hostport specifications to an object.
UnixArguments.Fetch(args); RelatedEvents.Forward(args, server); HostPorts.SetDefaultPort(args, 53); IF ~HostPorts.ReadAndAdd(args, server) THEN Conclusions.Conclude(server, Errors.fatal, ""); END;
Oberon || Library || Module Index || Search Engine || Definition || Module