The low-level format of the addresses are different depending on the mode of communication you have chosen. A function is provided by each of the lower layers to map a user-friendly string-form address to the binary form required by the lower layers.
void *cs_straddr(COMSTACK handle, const char *str);
The format for TCP/IP and SSL addresses is:
<host> [ ':' <portnum> ]
The hostname can be either a domain name or an IP address. The port number, if omitted, defaults to 210.
For TCP/IP and SSL transport modes, the special hostname "@" is mapped to any local address (the manifest constant INADDR_ANY). It is used to establish local listening endpoints in the server role.
For UNIX sockets, the format of an address is the socket filename.
When a connection has been established, you can use
char *cs_addrstr(COMSTACK h);
to retrieve the host name of the peer system. The function returns a pointer to a static area, which is overwritten on the next call to the function.
A fairly recent addition to the COMSTACK module is the utility function
COMSTACK cs_create_host (const char *str, int blocking, void **vp);
which is just a wrapper for cs_create
and
cs_straddr
. The str
is similar to that described for cs_straddr
but with a prefix denoting the COMSTACK type. Prefixes supported
are tcp:, unix: and
ssl: for TCP/IP, UNIX and SSL respectively.
If no prefix is given, then TCP/IP is used.
The blocking
is passed to
function cs_create
. The third parameter
vp
is a pointer to COMSTACK stack type
specific values.
For SSL (ssl_type) vp
is an already create
OpenSSL CTX. For TCP/IP and UNIX vp
is unused (can be set to NULL.