NAME

hostport -- support of host/port tuple specifications according to RFC 2396


SYNOPSIS

   #include <afblib/hostport.h>
   typedef struct hostport {
      // parameters for socket()
      int domain;
      int protocol;
      // parameters for bind() or connect()
      struct sockaddr_storage addr;
      int namelen;
   } hostport;
   bool parse_hostport(char* input, hostport* hp, in_port_t defaultport);


DESCRIPTION

parse_hostport supports the textual specification of hosts, either in domain style or as numerical IP address, and an optional port number. The term hostport was coined within RFC 2396 which provides the generic syntax for Uniform Resource Identifiers (URI). This syntax was extended by RFC 2732 to support IPv6 addresses which were already specified in RFC 2373. (IPv6 addresses are, however, in the current implementation not yet supported.)

Following syntax is supported:

   hostport        = host [ ":" port ]
   host            = hostname | IPv4address
   hostname        = { domainlabel "." } toplabel [ "." ]
   domainlabel     = alphanum | alphanum { alphanum  |  "-"  }
                     alphanum
   toplabel        = alpha | alpha { alphanum | "-" } alphanum
   IPv4address     = { digit } "."  { digit } "." { digit } "." { digit }

parse_hostport expects in input a string that conforms to the given syntax and returns, in case of success, a hostport structure that can be used for subsequent calls of socket and bind or connect. A default port can be specified using defaultport. This port is taken if no port is specified within input.


DIAGNOSTICS

parse_hostport returns true in case of success, and false otherwise.


BUGS

Support of IPv6 addresses is not yet included.


AUTHOR

Andreas F. Borchert