Socket abstraction
\s-1OSSP\s0 sa \s-11.2.5 (02-Oct-2005)\s0
sa_rc_t, sa_addr_t, sa_t.
sa_addr_create, sa_addr_destroy.
sa_addr_u2a, sa_addr_s2a, sa_addr_a2u, sa_addr_a2s, sa_addr_match.
sa_create, sa_destroy.
sa_type, sa_timeout, sa_buffer, sa_option, sa_syscall.
sa_bind, sa_connect, sa_listen, sa_accept, sa_getremote, sa_getlocal, sa_shutdown.
sa_getfd, sa_read, sa_readln, sa_write, sa_writef, sa_flush.
sa_recv, sa_send, sa_sendf.
sa_error.
\s-1OSSP\s0 sa is an abstraction library for the Unix Socket networking application programming interface (\s-1API\s0), featuring stream and datagram oriented communication over Unix Domain and Internet Domain (\s-1TCP\s0 and \s-1UDP\s0) sockets.
It provides the following key features:
Although there are various Open Source libraries available which provide a similar abstraction approach, they all either lack important features or unfortunately depend on other companion libraries. \s-1OSSP\s0 sa fills this gap by providing all important features (see following points) as a stand-alone and fully self-contained library. This way \s-1OSSP\s0 sa can be trivially embedded as a sub-library into other libraries. It especially provides additional support for namespace-safe embedding of its \s-1API\s0 in order to avoid symbol conflicts (see \*(C`SA_PREFIX\*(C' in sa.h).
Most of the ugliness in the Unix Socket \s-1API\s0 is the necessity to have to deal with the various address structures (\*(C`struct sockaddr_xx\*(C') which exist because of both the different communication types and addressing schemes. \s-1OSSP\s0 sa fully hides this by providing an abstract and opaque address type (\*(C`sa_addr_t\*(C') together with utility functions which allow one to convert from the traditional \*(C`struct sockaddr\*(C' or \s-1URI\s0 specification to the \*(C`sa_addr_t\*(C' and vice versa without having to deal with special cases related to the underlying particular \*(C`struct sockaddr_xx\*(C'. \s-1OSSP\s0 sa support Unix Domain and both IPv4 and IPv6 Internet Domain addressing.
Some other subtle details in the Unix Socket \s-1API\s0 make the life hard in practice: \*(C`socklen_t\*(C' and \*(C`ssize_t\*(C'. These two types originally were (and on some platforms still are) plain integers or unsigned integers while \s-1POSIX\s0 later introduced own types for them (and even revised these types after some time again). This is nasty, because for 100% type-correct \s-1API\s0 usage (especially important on 64-bit machines where pointers to different integer types make trouble), every application has to check whether the newer types exists, and if not provide own definitions which map to the still actually used integer type on the underlying platform. \s-1OSSP\s0 sa hides most of this in its \s-1API\s0 and for \*(C`socklen_t\*(C' provides a backward-compatibility definition. Instead of \*(C`ssize_t\*(C' it can use \*(C`size_t\*(C' because \s-1OSSP\s0 sa does not use traditional Unix return code semantics.
Each I/O function in \s-1OSSP\s0 sa is aware of timeouts (set by sa_timeout\|(3)), i.e., all I/O operations return \*(C`SA_ERR_TMT\*(C' if the timeout expired before the I/O operation was able to succeed. This allows one to easily program less-blocking network services. \s-1OSSP\s0 sa internally implements these timeouts either through the \*(C`SO_\*(C'{\*(C`SND\*(C',\*(C`RCV\*(C'}\*(C`TIMEO\*(C' feature on more modern Socket implementations or through traditional select\|(2). This way high performance is achieved on modern platforms while the full functionality still is available on older platforms.
If \s-1OSSP\s0 sa is used for stream communication, internally all I/O operations can be performed through input and/or output buffers (set by sa_buffer\|(3)) for achieving higher I/O performance by doing I/O operations on larger aggregated messages and with less required system calls. Additionally if \s-1OSSP\s0 sa is used for stream communication, for convenience reasons line-oriented reading (sa_readln\|(3)) and formatted writing (see sa_writef\|(3)) is provided, modelled after \s-1STDIO\s0's fgets\|(3) and fprintf\|(3). Both features fully leverage from the I/O buffering.
\s-1OSSP\s0 sa uses three data types in its \s-1API:\s0
This is an exported enumerated integer type with the following possible values:
SA_OK Everything Ok SA_ERR_ARG Invalid Argument SA_ERR_USE Invalid Use Or Context SA_ERR_MEM Not Enough Memory SA_ERR_MTC Matching Failed SA_ERR_EOF End Of Communication SA_ERR_TMT Communication Timeout SA_ERR_SYS Operating System Error (see errno) SA_ERR_IMP Implementation Not Available SA_ERR_INT Internal Error
This is an opaque data type representing a socket address. Only pointers to this abstract data type are used in the \s-1API\s0.
This is an opaque data type representing a socket. Only pointers to this abstract data type are used in the \s-1API\s0.
\s-1OSSP\s0 sa provides a bunch of \s-1API\s0 functions, all modelled after the same prototype:
\*(C`sa_rc_t\*(C' sa_name\*(C`(sa_\*(C'[\*(C`addr_\*(C']\*(C`_t *,\*(C' ...\*(C`)\*(C'
This means, every function returns \*(C`sa_rc_t\*(C' to indicate its success (\*(C`SA_OK\*(C') or failure (\*(C`SA_ERR_\*(C'\s-1XXX\s0) by returning a return code (the corresponding describing text can be determined by passing this return code to sa_error\|(3)). Each function name starts with the common prefix \*(C`sa_\*(C' and receives a \*(C`sa_t\*(C' (or \*(C`sa_addr_t\*(C') object handle on which it operates as its first argument.
\$1
This \s-1API\s0 part provides operations for the creation and destruction of address abstraction \*(C`sa_addr_t\*(C'. Create a socket address abstraction object. The object is stored in saa on success. Example: \*(C`sa_addr_t *saa; sa_addr_create(&saa);\*(C' Destroy a socket address abstraction object. The object saa is invalid after this call succeeded. Example: \*(C`sa_addr_destroy(saa);\*(C' This \s-1API\s0 part provides operations for working with the address abstraction \*(C`sa_addr_t\*(C'. Import an address into by converting from an \s-1URI\s0 specification to the corresponding address abstraction. The supported syntax for uri is: "\*(C`unix:\*(C'path" for Unix Domain addresses and "\*(C`inet://\*(C'addr\*(C`:\*(C'port[\*(C`#\*(C'protocol]" for Internet Domain addresses. In the \s-1URI\s0, path can be an absolute or relative filesystem path to an existing or not-existing file. addr can be an IPv4 address in dotted decimal notation ("127.0.0.1\*(L"), an IPv6 address in colon-separated (optionally abbreviated) hexadecimal notation (\*(R"\*(C`::1\*(C'\*(L") or a to-be-resolved hostname (\*(R"\*(C`localhost.example.com\*(C'"). port has to be either a decimal port in the range 1...65535 or a port name ("\*(C`smtp\*(C'"). If port is specified as a name, it is resolved as a \s-1TCP\s0 port by default. To force resolving a port name via a particular protocol, protocol can be specified as either "\*(C`tcp\*(C'\*(L" or \*(R"\*(C`udp\*(C'". The result is stored in saa on success. Example: \*(C`sa_addr_u2a(saa, "inet://192.168.0.1:smtp");\*(C' Import an address by converting from a traditional \*(C`struct sockaddr\*(C' object to the corresponding address abstraction. The accepted addresses for sabuf are: \*(C`struct sockaddr_un\*(C' (\*(C`AF_LOCAL\*(C'), \*(C`struct sockaddr_in\*(C' (\*(C`AF_INET\*(C') and \*(C`struct sockaddr_in6\*(C' (\*(C`AF_INET6\*(C'). The salen is the corresponding \*(C`sizeof(...)\*(C' of the particular underyling structure. The result is stored in saa on success. Example: \*(C`sockaddr_in in; sa_addr_s2a(saa, (struct sockaddr *)&in, (socklen_t)sizeof(in));\*(C' Export an address by converting from the address abstraction to the corresponding \s-1URI\s0 specification. The result is a string of the form "\*(C`unix:\*(C'path" for Unix Domain addresses and "\*(C`inet://\*(C'addr\*(C`:\*(C'port" for Internet Domain addresses. Notice that addr and port are returned in numerical (unresolved) way. Additionally, because usually one cannot map bidirectionally between \s-1TCP\s0 or \s-1UDP\s0 port names and the numerical value, there is no distinction between \s-1TCP\s0 and \s-1UDP\s0 here. The result is stored in uri on success. The caller has to free\|(3) the uri buffer later. Example: \*(C`char *uri; sa_addr_a2u(saa, &uri);\*(C' Export an address by converting from the address abstraction to the corresponding traditional \*(C`struct sockaddr\*(C' object. The result is one of the following particular underlying address structures: \*(C`struct sockaddr_un\*(C' (\*(C`AF_LOCAL\*(C'), \*(C`struct sockaddr_in\*(C' (\*(C`AF_INET\*(C') and \*(C`struct sockaddr_in6\*(C' (\*(C`AF_INET6\*(C'). The result is stored in sabuf and salen on success. The caller has to free\|(3) the sabuf buffer later. Example: \*(C`struct sockaddr sabuf, socklen_t salen; sa_addr_a2s(saa, &sa, &salen);\*(C' Match two address abstractions up to a specified prefix. This compares the addresses saa1 and saa2 by only taking the prefix part of length prefixlen into account. prefixlen is number of filesystem path characters for Unix Domain addresses and number of bits for Internet Domain addresses. In case of Internet Domain addresses, the addresses are matched in network byte order and the port (counting as an additional bit/item of length 1) is virtually appended to the address for matching. Specifying prefixlen as \*(C`-1\*(C' means matching the whole address (but without the virtually appended port) without having to know how long the underlying address representation (length of path for Unix Domain addresses, 32+1 [IPv4] or 128+1 [IPv6] for Internet Domain addresses) is. Specifying prefixlen as \*(C`-2\*(C' is equal to \*(C`-1\*(C' but additionally the port is matched, too. This especially can be used to implement Access Control Lists (\s-1ACL\s0) without having to fiddle around with the underlying representation. For this, make saa1 the to be checked address and saa2 plus prefixlen the \s-1ACL\s0 pattern as shown in the following example. Example: sa_addr_t *srv_sa; sa_addr_t *clt_saa; sa_t *clt_sa; sa_addr_t *acl_saa; char *acl_addr = "192.168.0.0"; int acl_len = 24; ... sa_addr_u2a(&acl_saa, "inet://%s:0", acl_addr); ... while (sa_accept(srv_sa, &clt_saa, &clt_sa) == SA_OK) { if (sa_addr_match(clt_saa, acl_saa, acl_len) != SA_OK) { /* connection refused */ ... sa_addr_destroy(clt_saa); sa_destroy(clt_sa); continue; } ... } ... This \s-1API\s0 part provides operations for the creation and destruction of socket abstraction \*(C`sa_t\*(C'. Create a socket abstraction object. The object is stored in sa on success. Example: \*(C`sa_t *sa; sa_create(&sa);\*(C' Destroy a socket abstraction object. The object sa is invalid after this call succeeded. Example: \*(C`sa_destroy(sa);\*(C' This \s-1API\s0 part provides operations for parameterizing the socket abstraction \*(C`sa_t\*(C'. Assign a particular communication protocol type to the socket abstraction object. A socket can only be assigned a single protocol type at any time. Nevertheless one can switch the type of a socket abstraction object at any time in order to reuse it for a different communication. Just keep in mind that switching the type will stop a still ongoing communication by closing the underlying socket. Possible values for type are \*(C`SA_TYPE_STREAM\*(C' (stream communication) and \*(C`SA_TYPE_DATAGRAM\*(C' (datagram communication). The default communication protocol type is \*(C`SA_TYPE_STREAM\*(C'. Example: \*(C`sa_type(sa, SA_TYPE_STREAM);\*(C' Assign one or more communication timeouts to the socket abstraction object. Possible values for id are: \*(C`SA_TIMEOUT_ACCEPT\*(C' (affecting sa_accept\|(3)), \*(C`SA_TIMEOUT_CONNECT\*(C' (affecting sa_connect\|(3)), \*(C`SA_TIMEOUT_READ\*(C' (affecting sa_read\|(3), sa_readln\|(3) and sa_recv\|(3)) and \*(C`SA_TIMEOUT_WRITE\*(C' (affecting sa_write\|(3), sa_writef\|(3), sa_send\|(3), and sa_sendf\|(3)). Additionally you can set all four timeouts at once by using \*(C`SA_TIMEOUT_ALL\*(C'. The default is that no communication timeouts are used which is equal to sec=0/usec=0. Example: \*(C`sa_timeout(sa, SA_TIMEOUT_ALL, 30, 0);\*(C' Assign I/O communication buffers to the socket abstraction object. Possible values for id are: \*(C`SA_BUFFER_READ\*(C' (affecting sa_read\|(3) and sa_readln\|(3)) and \*(C`SA_BUFFER_WRITE\*(C' (affecting sa_write\|(3) and sa_writef\|(3)). The default is that no communication buffers are used which is equal to size=0. Example: \*(C`sa_buffer(sa, SA_BUFFER_READ, 16384);\*(C' Adjust various options of the socket abstraction object. The adjusted option is controlled by id. The number and type of the expected following argument(s) are dependent on the particular option. Currently the following options are implemented (option arguments in parenthesis): \*(C`SA_OPTION_NAGLE\*(C' (\*(C`int\*(C' yesno) for enabling (yesno=1) or disabling (yesno == 0) Nagle's Algorithm (see \s-1RFC898\s0 and \*(C`TCP_NODELAY\*(C' of setsockopt\|(2)). \*(C`SA_OPTION_LINGER\*(C' (\*(C`int\*(C' amount) for enabling (amount == seconds != 0) or disabling (amount == 0) lingering on close (see \*(C`SO_LINGER\*(C' of setsockopt\|(2)). Notice: using seconds > 0 results in a regular (maximum of seconds lasting) lingering on close while using seconds < 0 results in the special case of a \s-1TCP\s0 \s-1RST\s0 based connection termination on close. \*(C`SA_OPTION_REUSEADDR\*(C' (\*(C`int\*(C' yesno) for enabling (yesno == 1) or disabling (yesno == 0) the reusability of the address on binding via sa_bind\|(3) (see \*(C`SO_REUSEADDR\*(C' of setsockopt\|(2)). \*(C`SA_OPTION_REUSEPORT\*(C' (\*(C`int\*(C' yesno) for enabling (yesno == 1) or disabling (yesno == 0) the reusability of the port on binding via sa_bind\|(3) (see \*(C`SO_REUSEPORT\*(C' of setsockopt\|(2)). \*(C`SA_OPTION_NONBLOCK\*(C' (\*(C`int\*(C' yesno) for enabling (yesno == 1) or disabling (yesno == 0) non-blocking I/O mode (see \*(C`O_NONBLOCK\*(C' of fcntl\|(2)). Example: \*(C`sa_option(sa, SA_OPTION_NONBLOCK, 1);\*(C' Divert I/O communication related system calls to user supplied callback functions. This allows you to override mostly all I/O related system calls \s-1OSSP\s0 sa internally performs while communicating. This can be used to adapt \s-1OSSP\s0 sa to different run-time environments and requirements without having to change the source code. Usually this is used to divert the system calls to the variants of a user-land multithreading facility like \s-1GNU\s0 Pth. The function supplied as fptr is required to fulfill the \s-1API\s0 of the replaced system call, i.e., it has to have the same prototype (if fctx is \*(C`NULL\*(C'). If fctx is not \*(C`NULL\*(C', this prototype has to be extended to accept an additional first argument of type \*(C`void *\*(C' which receives the value of fctx. It is up to the callback function whether to pass the call through to the replaced actual system call or not. Possible values for id are (expected prototypes behind fptr are given in parenthesis): \s-1SA_SYSCALL_CONNECT\s0: "\*(C`int (*)([void *,] int, const struct sockaddr *, socklen_t)\*(C'", see connect\|(2). \s-1SA_SYSCALL_ACCEPT\s0: "\*(C`int (*)([void *,] int, struct sockaddr *, socklen_t *)\*(C'", see accept\|(2). \s-1SA_SYSCALL_SELECT\s0: "\*(C`int (*)([void *,] int, fd_set *, fd_set *, fd_set *, struct timeval *)\*(C'", see select\|(2). \s-1SA_SYSCALL_READ\s0: "\*(C`ssize_t (*)([void *,] int, void *, size_t)\*(C'", see read\|(2). \s-1SA_SYSCALL_WRITE\s0: "\*(C`ssize_t (*)([void *,] int, const void *, size_t)\*(C'", see write\|(2). \s-1SA_SYSCALL_RECVFROM\s0: "\*(C`ssize_t (*)([void *,] int, void *, size_t, int, struct sockaddr *, socklen_t *)\*(C'", see recvfrom\|(2). \s-1SA_SYSCALL_SENDTO\s0: "\*(C`ssize_t (*)([void *,] int, const void *, size_t, int, const struct sockaddr *, socklen_t)\*(C'", see sendto\|(2). Example: ssize_t trace_read(void *ctx, int fd, void *buf, size_t len) { FILE *fp = (FILE *)ctx; ssize_t rv; int errno_saved; rv = read(fd, buf, len); errno_saved = errno; fprintf(fp, "read(%d, %lx, %d) = %d\n", fd, (long)buf, len, rv); errno = errno_saved; return rv; } ... FILE *trace_fp = ...; sa_syscall(sa, SA_SC_READ, trace_read, trace_fp); ... This \s-1API\s0 part provides connection operations for stream-oriented data communication through the socket abstraction \*(C`sa_t\*(C'. Bind socket abstraction object to a local protocol address. This assigns the local protocol address laddr. When a socket is created, it exists in an address family space but has no protocol address assigned. This call requests that laddr be used as the local address. For servers this is the address they later listen on (see sa_listen\|(3)) for incoming connections, for clients this is the address used for outgoing connections (see sa_connect\|(3)). Internally this directly maps to bind\|(2). Example: \*(C`sa_bind(sa, laddr);\*(C' Initiate an outgoing connection on a socket abstraction object. This performs a connect to the remote address raddr. If the socket is of type \*(C`SA_TYPE_DATAGRAM\*(C', this call specifies the peer with which the socket is to be associated; this address is that to which datagrams are to be sent, and the only address from which datagrams are to be received. If the socket is of type \*(C`SA_TYPE_STREAM\*(C', this call attempts to make a connection to the remote socket. Internally this directly maps to connect\|(2). Example: \*(C`sa_connect(sa, raddr);\*(C' Listen for incoming connections on a socket abstraction object. A willingness to accept incoming connections and a queue limit for incoming connections are specified by this call. The backlog argument defines the maximum length the queue of pending connections may grow to. Internally this directly maps to listen\|(2). Example: \*(C`sa_listen(sa, 128);\*(C' Accept incoming connection on a socket abstraction object. This accepts an incoming connection by extracting the first connection request on the queue of pending connections. It creates a new socket abstraction object (returned in csa) and a new socket address abstraction object (returned in caddr) describing the connection. The caller has to destroy these objects later. If no pending connections are present on the queue, it blocks the caller until a connection is present. Example: sa_addr_t *clt_saa; sa_t *clt_sa; ... while (sa_accept(srv_sa, &clt_saa, &clt_sa) == SA_OK) { ... } Get address abstraction of remote side of communication. This determines the address of the communication peer and creates a new socket address abstraction object (returned in raddr) describing the peer address. The application has to destroy raddr later with sa_addr_destroy\|(3). Internally this maps to getpeername\|(2). Example: \*(C`sa_addr_t *raddr; sa_getremote(sa, &raddr);\*(C' Get address abstraction of local side of communication. This determines the address of the local communication side and creates a new socket address abstraction object (returned in laddr) describing the local address. The application has to destroy laddr later with sa_addr_destroy\|(3). Internally this maps to getsockname\|(2). Example: \*(C`sa_addr_t *laddr; sa_getlocal(sa, &laddr);\*(C' Shut down part of the full-duplex connection. This performs a shut down of the connection described in sa. The flags string can be either "\*(C`r\*(C'\*(L" (indicating the read channel of the communication is shut down only), \*(R"\*(C`w\*(C'\*(L" (indicating the write channel of the communication is shut down only), or \*(R"\*(C`rw\*(C'" (indicating both the read and write channels of the communication are shut down). Internally this directly maps to shutdown\|(2). Example: \*(C`sa_shutdown(sa, "w");\*(C' This \s-1API\s0 part provides I/O operations for stream-oriented data communication through the socket abstraction \*(C`sa_t\*(C'. Get underlying socket filedescriptor. This peeks into the underlying socket filedescriptor \s-1OSSP\s0 sa allocated internally for the communication. This can be used for adjusting the socket communication (via fcntl\|(2), setsockopt\|(2), etc) directly. Think twice before using this, then think once more. After all that, think again. With enough thought, the need for directly manipulating the underlying socket can often be eliminated. At least remember that all your direct socket operations fully by-pass \s-1OSSP\s0 sa and this way can leads to nasty side-effects. Example: \*(C`int fd; sa_getfd(sa, &fd);\*(C' Read a chunk of data from socket into own buffer. This reads from the socket (optionally through the internal read buffer) up to a maximum of buflen bytes into buffer buf. The actual number of read bytes is stored in bufdone. This internally maps to read\|(2). Example: \*(C`char buf[1024]; size_t n; sa_read(sa, buf, sizeof(buf), &n);\*(C' Read a line of data from socket into own buffer. This reads from the socket (optionally through the internal read buffer) up to a maximum of buflen bytes into buffer buf, but only as long as no line terminating newline character (0x0a) was found. The line terminating newline character is stored in the buffer plus a (not counted) terminating \*(C`NUL\*(C' character ('\*(C`\0\*(C''), too. The actual number of read bytes is stored in bufdone. This internally maps to sa_read\|(3). Keep in mind that for efficiency reasons, line-oriented I/O usually always should be performed with read buffer (see sa_option\|(3) and \*(C`SA_BUFFER_READ\*(C'). Without such a read buffer, the performance is cruel, because single character read\|(2) operations would be performed on the underlying socket. Example: \*(C`char buf[1024]; size_t n; sa_readln(sa, buf, sizeof(buf), &n);\*(C' Write a chunk of data to socket from own buffer. This writes to the socket (optionally through the internal write buffer) buflen bytes from buffer buf. In case of a partial write, the actual number of written bytes is stored in bufdone. This internally maps to write\|(2). Example: \*(C`sa_write(sa, cp, strlen(cp), NULL);\*(C' Write formatted data data to socket. This formats a string according to the printf\|(3)-style format specification fmt and sends the result to the socket (optionally through the internal write buffer). In case of a partial socket write, the not written data of the formatted string is internally discarded. Hence using a write buffer is strongly recommended here (see sa_option\|(3) and \*(C`SA_BUFFER_WRITE\*(C'). This internally maps to sa_write\|(3). The underlying string formatting engine is just a minimal one and for security and independence reasons intentionally not directly based on s[n]printf\|(3). It understands only the following format specifications: "\*(C`%%\*(C'\*(L", \*(R"%c" (\*(C`char\*(C'), "%s" (\*(C`char *\*(C') and "%d" (\*(C`int\*(C') without any precision and padding possibilities. It is intended for minimal formatting only. If you need more sophisticated formatting, you have to format first into an own buffer via s[n]printf\|(3) and then write this to the socket via sa_write\|(3) instead. Example: \*(C`sa_writef(sa, "%s=%d\n", cp, i);\*(C' Flush still pending outgoing data to socket. This writes all still pending outgoing data for the internal write buffer (see sa_option\|(3) and \*(C`SA_BUFFER_WRITE\*(C') to the socket. This internally maps to write\|(2). Example: \*(C`sa_flush(sa);\*(C' This \s-1API\s0 part provides I/O operations for datagram-oriented data communication through the socket abstraction \*(C`sa_t\*(C'. Receive a chunk of data from remote address via socket into own buffer. This receives from the remote address specified in raddr via the socket up to a maximum of buflen bytes into buffer buf. The actual number of received bytes is stored in bufdone. This internally maps to recvfrom\|(2). Example: \*(C`char buf[1024]; size_t n; sa_recv(sa, buf, sizeof(buf), &n, saa);\*(C' Send a chunk of data to remote address via socket from own buffer. This sends to the remote address specified in raddr via the socket buflen bytes from buffer buf. The actual number of sent bytes is stored in bufdone. This internally maps to sendto\|(2). Example: \*(C`sa_send(sa, buf, strlen(buf), NULL, saa);\*(C' Send formatted data data to remote address via socket. This formats a string according to the printf\|(3)-style format specification fmt and sends the result to the socket as a single piece of data chunk. In case of a partial socket write, the not written data of the formatted string is internally discarded. The underlying string formatting engine is just a minimal one and for security and independence reasons intentionally not directly based on s[n]printf\|(3). It understands only the following format specifications: "\*(C`%%\*(C'\*(L", \*(R"%c" (\*(C`char\*(C'), "%s" (\*(C`char *\*(C') and "%d" (\*(C`int\*(C') without any precision and padding possibilities. It is intended for minimal formatting only. If you need more sophisticated formatting, you have to format first into an own buffer via s[n]printf\|(3) and then send this to the remote address via sa_send\|(3) instead. Example: \*(C`sa_sendf(sa, saa, "%s=%d\n", cp, i);\*(C' This \s-1API\s0 part provides error handling operations only. Return the string representation corresponding to the return code value rv. The returned string has to be treated read-only by the application and is not required to be deallocated.
R. Gilligan, S. Thomson, J. Bound, W. Stevens: \*(L"Basic Socket Interface Extensions for IPv6\*(R", \s-1RFC\s0 2553, March 1999.
W. Stevens: \*(L"Advanced Sockets \s-1API\s0 for IPv6\*(R", \s-1RFC\s0 2292, February 1998.
R. Fielding, L. Masinter, T. Berners-Lee: \*(L"Uniform Resource Identifiers: Generic Syntax\*(R", \s-1RFC\s0 2396, August 1998.
R. Hinden, S. Deering: \*(L"\s-1IP\s0 Version 6 Addressing Architecture\*(R", \s-1RFC\s0 2373, July 1998.
R. Hinden, B. Carpenter, L. Masinter: \*(L"Format for Literal IPv6 Addresses in \s-1URL\s0's\*(R", \s-1RFC\s0 2732, December 1999. Stuart Sechrest: \*(L"An Introductory 4.4BSD Interprocess Communication Tutorial\*(R", FreeBSD 4.4 (/usr/share/doc/psd/20.ipctut/).
Samuel J. Leffler, Robert S. Fabry, William N. Joy, Phil Lapsley: \*(L"An Advanced 4.4BSD Interprocess Communication Tutorial\*(R", FreeBSD 4.4 (/usr/share/doc/psd/21.ipc/).
Craig Metz: \*(L"Protocol Independence Using the Sockets \s-1API\s0\*(R", http://www.usenix.org/publications/library/proceedings/usenix2000/freenix/metzprotocol.html, \s-1USENIX\s0 Annual Technical Conference, June 2000. socket\|(2), accept\|(2), bind\|(2), connect\|(2), getpeername\|(2), getsockname\|(2), getsockopt\|(2), ioctl\|(2), listen\|(2), read\|(2), recv\|(2), select\|(2), send\|(2), shutdown\|(2), socketpair\|(2), write\|(2), getprotoent\|(3), protocols\|(4).
\s-1OSSP\s0 sa was invented in August 2001 by Ralf S. Engelschall <[email protected]> under contract with Cable & Wireless <http://www.cw.com/> for use inside the \s-1OSSP\s0 project. Its creation was prompted by the requirement to implement an \s-1SMTP\s0 logging channel for the \s-1OSSP\s0 l2 library. Its initial code was derived from a predecessor sub-library originally written for socket address abstraction inside the \s-1OSSP\s0 lmtp2nntp tool.
Ralf S. Engelschall [email protected] www.engelschall.com