--- sa.c 2002/01/29 12:48:28 1.54
+++ sa.c 2002/01/30 16:43:00 1.55
@@ -53,6 +53,19 @@
/* include own API header */
#include "sa.h"
+/* unique library identifier */
+const char sa_id[] = "OSSP sa";
+
+/* support for OSSP ex based exception throwing */
+#ifdef WITH_EX
+#include "ex.h"
+#define SA_RC(rv) \
+ ( (rv) != SA_OK && (ex_catching && !ex_shielding) \
+ ? (ex_throw(sa_id, NULL, (rv)), (rv)) : (rv) )
+#else
+#define SA_RC(rv) (rv)
+#endif /* WITH_EX */
+
/* boolean values */
#ifndef FALSE
#define FALSE (0)
@@ -400,11 +413,11 @@
/* argument sanity check(s) */
if (saap == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* allocate and initialize new address object */
if ((saa = (sa_addr_t *)malloc(sizeof(sa_addr_t))) == NULL)
- return SA_ERR_MEM;
+ return SA_RC(SA_ERR_MEM);
saa->nFamily = 0;
saa->saBuf = NULL;
saa->slBuf = 0;
@@ -420,7 +433,7 @@
{
/* argument sanity check(s) */
if (saa == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* free address objects and sub-object(s) */
if (saa->saBuf != NULL)
@@ -458,7 +471,7 @@
/* argument sanity check(s) */
if (saa == NULL || uri == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* on-the-fly create or just take over URI */
va_start(ap, uri);
@@ -485,12 +498,12 @@
/* fill-in socket address structure */
n = strlen(cpPath);
if (n == 0)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
if ((n+1) > sizeof(un.sun_path))
- return SA_ERR_MEM;
+ return SA_RC(SA_ERR_MEM);
if (cpPath[0] != '/') {
if (getcwd(un.sun_path, sizeof(un.sun_path)-(n+1)) == NULL)
- return SA_ERR_MEM;
+ return SA_RC(SA_ERR_MEM);
cp = un.sun_path + strlen(un.sun_path);
}
else
@@ -510,22 +523,22 @@
if (cpHost[0] == '[') {
/* IPv6 address (see RFC2732) */
#ifndef AF_INET6
- return SA_ERR_IMP;
+ return SA_RC(SA_ERR_IMP);
#else
bIPv6 = TRUE;
cpHost++;
if ((cp = strchr(cpHost, ']')) == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
*cp++ = '\0';
if (*cp != ':')
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
cp++;
#endif
}
else {
/* IPv4 address or hostname */
if ((cp = strrchr(cpHost, ':')) == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
*cp++ = '\0';
}
cpPort = cp;
@@ -548,7 +561,7 @@
nPort = (unsigned int)atoi(cpPort);
else {
if ((se = getservbyname(cpPort, cpProto)) == NULL)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
nPort = ntohs(se->s_port);
}
@@ -598,19 +611,19 @@
}
#endif
else
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
}
else
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
}
else
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* fill-in result address structure */
if (saa->saBuf != NULL)
free(saa->saBuf);
if ((saa->saBuf = (struct sockaddr *)malloc(sl)) == NULL)
- return SA_ERR_MEM;
+ return SA_RC(SA_ERR_MEM);
memcpy(saa->saBuf, sa, sl);
saa->slBuf = sl;
saa->nFamily = sf;
@@ -623,7 +636,7 @@
{
/* argument sanity check(s) */
if (saa == NULL || sabuf == NULL || salen == 0)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* make sure we import only supported addresses */
if (!( sabuf->sa_family == AF_LOCAL
@@ -632,13 +645,13 @@
|| sabuf->sa_family == AF_INET6
#endif
))
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* create result address structure */
if (saa->saBuf != NULL)
free(saa->saBuf);
if ((saa->saBuf = (struct sockaddr *)malloc(salen)) == NULL)
- return SA_ERR_MEM;
+ return SA_RC(SA_ERR_MEM);
memcpy(saa->saBuf, sabuf, salen);
saa->slBuf = salen;
@@ -662,7 +675,7 @@
/* argument sanity check(s) */
if (saa == NULL || uri == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* export object contents */
if (saa->nFamily == AF_LOCAL) {
@@ -693,7 +706,7 @@
}
#endif
else
- return SA_ERR_INT;
+ return SA_RC(SA_ERR_INT);
/* pass result to caller */
*uri = strdup(uribuf);
@@ -706,11 +719,11 @@
{
/* argument sanity check(s) */
if (saa == NULL || sabuf == NULL || salen == 0)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* export underlying address structure */
if ((*sabuf = (struct sockaddr *)malloc(saa->slBuf)) == NULL)
- return SA_ERR_MEM;
+ return SA_RC(SA_ERR_MEM);
memmove(*sabuf, saa->saBuf, saa->slBuf);
*salen = saa->slBuf;
@@ -733,7 +746,7 @@
/* argument sanity check(s) */
if (saa1 == NULL || saa2 == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* short circuiting for wildcard matching */
if (prefixlen == 0)
@@ -749,12 +762,12 @@
l2 = strlen(((struct sockaddr_un *)saa2->saBuf)->sun_path) * 8;
if (prefixlen < 0) {
if (l1 != l2)
- return SA_ERR_MTC;
+ return SA_RC(SA_ERR_MTC);
nBits = l1;
}
else {
if (l1 < prefixlen || l2 < prefixlen)
- return SA_ERR_MTC;
+ return SA_RC(SA_ERR_MTC);
nBits = prefixlen;
}
}
@@ -781,9 +794,9 @@
}
for (i = 0; i < 10; i++)
if (ucp0[i] != 0x00)
- return SA_ERR_MTC;
+ return SA_RC(SA_ERR_MTC);
if (!(ucp0[10] == 0xFF && ucp0[11] == 0xFF))
- return SA_ERR_MTC;
+ return SA_RC(SA_ERR_MTC);
nBits = 32;
}
#endif
@@ -804,11 +817,11 @@
#endif
}
else
- return SA_ERR_INT;
+ return SA_RC(SA_ERR_INT);
/* make sure we do not compare than possible */
if (prefixlen > (nBits+1))
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* support equal matching (= all bits plus optionally port) */
bMatchPort = FALSE;
@@ -824,20 +837,20 @@
nBits = (prefixlen % 8);
if (nBytes > 0) {
if (memcmp(ucp1, ucp2, nBytes) != 0)
- return SA_ERR_MTC;
+ return SA_RC(SA_ERR_MTC);
}
if (nBits > 0) {
uc1 = ucp1[nBytes];
uc2 = ucp2[nBytes];
mask = (0xFF << (8-nBits)) & 0xFF;
if ((uc1 & mask) != (uc2 & mask))
- return SA_ERR_MTC;
+ return SA_RC(SA_ERR_MTC);
}
/* optionally perform additional port matching */
if (bMatchPort)
if (np1 != np2)
- return SA_ERR_MTC;
+ return SA_RC(SA_ERR_MTC);
return SA_OK;
}
@@ -851,13 +864,13 @@
if (setsockopt(sa->fdSocket, SOL_SOCKET, SO_RCVTIMEO,
&sa->tvTimeout[SA_TIMEOUT_READ],
sizeof(sa->tvTimeout[SA_TIMEOUT_READ])) < 0)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
}
if (SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_WRITE])) {
if (setsockopt(sa->fdSocket, SOL_SOCKET, SO_SNDTIMEO,
&sa->tvTimeout[SA_TIMEOUT_WRITE],
sizeof(sa->tvTimeout[SA_TIMEOUT_WRITE])) < 0)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
}
}
#endif
@@ -875,11 +888,11 @@
/* argument sanity check(s) */
if (sa == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* only perform operation if socket still does not exist */
if (sa->fdSocket != -1)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* determine socket type */
if (sa->eType == SA_TYPE_STREAM)
@@ -887,7 +900,7 @@
else if (sa->eType == SA_TYPE_DATAGRAM)
nType = SOCK_DGRAM;
else
- return SA_ERR_INT;
+ return SA_RC(SA_ERR_INT);
/* determine socket protocol */
if (nFamily == AF_LOCAL)
@@ -903,25 +916,25 @@
else if (nType == SOCK_DGRAM)
nProto = IPPROTO_UDP;
else
- return SA_ERR_INT;
+ return SA_RC(SA_ERR_INT);
#else
if (nType == SOCK_STREAM)
pe = getprotobyname("tcp");
else if (nType == SOCK_DGRAM)
pe = getprotobyname("udp");
else
- return SA_ERR_INT;
+ return SA_RC(SA_ERR_INT);
if (pe == NULL)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
nProto = pe->p_proto;
#endif
}
else
- return SA_ERR_INT;
+ return SA_RC(SA_ERR_INT);
/* create the underlying socket */
if ((sa->fdSocket = socket(nFamily, nType, nProto)) == -1)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
/* optionally set kernel timeouts */
sa_socket_settimeouts(sa);
@@ -934,11 +947,11 @@
{
/* argument sanity check(s) */
if (sa == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* check context */
if (sa->fdSocket == -1)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* close socket */
close(sa->fdSocket);
@@ -955,11 +968,11 @@
/* argument sanity check(s) */
if (sap == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* allocate and initialize socket object */
if ((sa = (sa_t *)malloc(sizeof(sa_t))) == NULL)
- return SA_ERR_MEM;
+ return SA_RC(SA_ERR_MEM);
/* init object attributes */
sa->eType = SA_TYPE_STREAM;
@@ -997,7 +1010,7 @@
{
/* argument sanity check(s) */
if (sa == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* kill underlying socket */
sa_socket_kill(sa);
@@ -1017,9 +1030,9 @@
{
/* argument sanity check(s) */
if (sa == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
if (!(type == SA_TYPE_STREAM || type == SA_TYPE_DATAGRAM))
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* kill underlying socket if type changes */
if (sa->eType != type)
@@ -1038,7 +1051,7 @@
/* argument sanity check(s) */
if (sa == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
if (id == SA_TIMEOUT_ALL) {
for (i = 0; i < (sizeof(sa->tvTimeout)/sizeof(sa->tvTimeout[0])); i++) {
@@ -1064,19 +1077,19 @@
/* argument sanity check(s) */
if (sa == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
if (id == SA_BUFFER_READ) {
/* configure read/incoming buffer */
if (sa->nReadLen > size)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
if (size > 0) {
if (sa->cpReadBuf == NULL)
cp = (char *)malloc(size);
else
cp = (char *)realloc(sa->cpReadBuf, size);
if (cp == NULL)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
sa->cpReadBuf = cp;
sa->nReadSize = size;
}
@@ -1090,14 +1103,14 @@
else if (id == SA_BUFFER_WRITE) {
/* configure write/outgoing buffer */
if (sa->nWriteLen > size)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
if (size > 0) {
if (sa->cpWriteBuf == NULL)
cp = (char *)malloc(size);
else
cp = (char *)realloc(sa->cpWriteBuf, size);
if (cp == NULL)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
sa->cpWriteBuf = cp;
sa->nWriteSize = size;
}
@@ -1109,7 +1122,7 @@
}
}
else
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
return SA_OK;
}
@@ -1122,7 +1135,7 @@
/* argument sanity check(s) */
if (sa == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* process option */
rv = SA_OK;
@@ -1209,7 +1222,7 @@
}
va_end(ap);
- return rv;
+ return SA_RC(rv);
}
/* override system call */
@@ -1219,7 +1232,7 @@
/* argument sanity check(s) */
if (sa == NULL || fptr == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* assign system call */
rv = SA_OK;
@@ -1234,7 +1247,7 @@
default: rv = SA_ERR_ARG;
}
- return rv;
+ return SA_RC(rv);
}
/* bind socket to a local address */
@@ -1245,12 +1258,12 @@
/* argument sanity check(s) */
if (sa == NULL || laddr == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* lazy creation of underlying socket */
if (sa->fdSocket == -1)
if ((rv = sa_socket_init(sa, laddr->nFamily)) != SA_OK)
- return rv;
+ return SA_RC(rv);
/* remove a possibly existing old Unix Domain socket on filesystem */
if (laddr->nFamily == AF_LOCAL) {
@@ -1260,7 +1273,7 @@
/* perform bind operation on underlying socket */
if (bind(sa->fdSocket, laddr->saBuf, laddr->slBuf) == -1)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
return SA_OK;
}
@@ -1275,16 +1288,16 @@
/* argument sanity check(s) */
if (sa == NULL || raddr == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* connecting is only possible for stream communication */
if (sa->eType != SA_TYPE_STREAM)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* lazy creation of underlying socket */
if (sa->fdSocket == -1)
if ((rv = sa_socket_init(sa, raddr->nFamily)) != SA_OK)
- return rv;
+ return SA_RC(rv);
rv = SA_OK;
if (SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_CONNECT])) {
@@ -1352,7 +1365,7 @@
rv = SA_ERR_SYS;
}
}
- return rv;
+ return SA_RC(rv);
}
/* listen on socket for connections */
@@ -1360,19 +1373,19 @@
{
/* argument sanity check(s) */
if (sa == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* listening is only possible for stream communication */
if (sa->eType != SA_TYPE_STREAM)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* at least sa_bind() has to be already performed */
if (sa->fdSocket == -1)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* perform listen operation on underlying socket */
if (listen(sa->fdSocket, backlog) == -1)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
return SA_OK;
}
@@ -1396,15 +1409,15 @@
/* argument sanity check(s) */
if (sa == NULL || caddr == NULL || csa == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* accepting connections is only possible for stream communication */
if (sa->eType != SA_TYPE_STREAM)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* at least sa_listen() has to be already performed */
if (sa->fdSocket == -1)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* if timeout is enabled, perform a smart-blocking wait */
if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_ACCEPT])) {
@@ -1415,28 +1428,28 @@
&sa->tvTimeout[SA_TIMEOUT_ACCEPT]);
} while (n == -1 && errno == EINTR);
if (n == 0)
- return SA_ERR_TMT;
+ return SA_RC(SA_ERR_TMT);
if (n <= 0)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
}
/* perform accept operation on underlying socket */
sa_len = sizeof(sa_buf);
if ((s = SA_SC_CALL_3(sa, accept, sa->fdSocket, (struct sockaddr *)&sa_buf, &sa_len)) == -1)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
/* create result address object */
if ((rv = sa_addr_create(caddr)) != SA_OK)
- return rv;
+ return SA_RC(rv);
if ((rv = sa_addr_s2a(*caddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK) {
sa_addr_destroy(*caddr);
- return rv;
+ return SA_RC(rv);
}
/* create result socket object */
if ((rv = sa_create(csa)) != SA_OK) {
sa_addr_destroy(*caddr);
- return rv;
+ return SA_RC(rv);
}
/* fill-in child socket */
@@ -1474,27 +1487,27 @@
/* argument sanity check(s) */
if (sa == NULL || raddr == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* peers exist only for stream communication */
if (sa->eType != SA_TYPE_STREAM)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* at least sa_connect() or sa_accept() has to be already performed */
if (sa->fdSocket == -1)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* determine remote address of underlying socket */
sa_len = sizeof(sa_buf);
if (getpeername(sa->fdSocket, (struct sockaddr *)&sa_buf, &sa_len) < 0)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
/* create result address object */
if ((rv = sa_addr_create(raddr)) != SA_OK)
- return rv;
+ return SA_RC(rv);
if ((rv = sa_addr_s2a(*raddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK) {
sa_addr_destroy(*raddr);
- return rv;
+ return SA_RC(rv);
}
return SA_OK;
@@ -1514,23 +1527,23 @@
/* argument sanity check(s) */
if (sa == NULL || laddr == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* at least sa_bind() has to be already performed */
if (sa->fdSocket == -1)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* determine local address of underlying socket */
sa_len = sizeof(sa_buf);
if (getsockname(sa->fdSocket, (struct sockaddr *)&sa_buf, &sa_len) < 0)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
/* create result address object */
if ((rv = sa_addr_create(laddr)) != SA_OK)
- return rv;
+ return SA_RC(rv);
if ((rv = sa_addr_s2a(*laddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK) {
sa_addr_destroy(*laddr);
- return rv;
+ return SA_RC(rv);
}
return SA_OK;
@@ -1541,11 +1554,11 @@
{
/* argument sanity check(s) */
if (sa == NULL || fd == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* if still no socket exists, say this explicitly */
if (sa->fdSocket == -1)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* pass socket to caller */
*fd = sa->fdSocket;
@@ -1600,15 +1613,15 @@
/* argument sanity check(s) */
if (sa == NULL || cpBuf == NULL || nBufReq == 0)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* reading is only possible for stream communication */
if (sa->eType != SA_TYPE_STREAM)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* at least a connection has to exist */
if (sa->fdSocket == -1)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* perform read operation */
rv = SA_OK;
@@ -1684,7 +1697,7 @@
if (nBufRes != NULL)
*nBufRes = (size_t)res;
- return rv;
+ return SA_RC(rv);
}
/* read data from socket until [CR]LF (convinience function) */
@@ -1697,15 +1710,15 @@
/* argument sanity check(s) */
if (sa == NULL || cpBuf == NULL || nBufReq == 0)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* reading is only possible for stream communication */
if (sa->eType != SA_TYPE_STREAM)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* at least a connection has to exist */
if (sa->fdSocket == -1)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* we just perform a plain sa_read() per character, because if
buffers are enabled, this is not as stupid as it looks at the first
@@ -1729,7 +1742,7 @@
if (nBufRes != NULL)
*nBufRes = res;
- return rv;
+ return SA_RC(rv);
}
/* internal raw write operation */
@@ -1779,15 +1792,15 @@
/* argument sanity check(s) */
if (sa == NULL || cpBuf == NULL || nBufReq == 0)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* writing is only possible for stream communication */
if (sa->eType != SA_TYPE_STREAM)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* at least a connection has to exist */
if (sa->fdSocket == -1)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
rv = SA_OK;
if (sa->nWriteSize == 0) {
@@ -1832,7 +1845,7 @@
if (nBufRes != NULL)
*nBufRes = (size_t)res;
- return rv;
+ return SA_RC(rv);
}
/* output callback function context for sa_writef() */
@@ -1861,15 +1874,15 @@
/* argument sanity check(s) */
if (sa == NULL || cpFmt == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* writing is only possible for stream communication */
if (sa->eType != SA_TYPE_STREAM)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* at least a connection has to exist */
if (sa->fdSocket == -1)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* format string into temporary buffer */
va_start(ap, cpFmt);
@@ -1889,15 +1902,15 @@
/* argument sanity check(s) */
if (sa == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* flushing is only possible for stream communication */
if (sa->eType != SA_TYPE_STREAM)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* at least a connection has to exist */
if (sa->fdSocket == -1)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* try to flush buffer */
rv = SA_OK;
@@ -1915,7 +1928,7 @@
}
sa->nWriteLen = 0;
}
- return rv;
+ return SA_RC(rv);
}
/* shutdown a socket connection */
@@ -1925,15 +1938,15 @@
/* argument sanity check(s) */
if (sa == NULL || flags == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* shutdown is only possible for stream communication */
if (sa->eType != SA_TYPE_STREAM)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* at least a connection has to exist */
if (sa->fdSocket == -1)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* determine flags for shutdown(2) */
how = 0;
@@ -1944,11 +1957,11 @@
else if (strcmp(flags, "rw") == 0)
how = SHUT_RDWR;
else
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* perform shutdown operation on underlying socket */
if (shutdown(sa->fdSocket, how) == -1)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
return SA_OK;
}
@@ -1969,15 +1982,15 @@
/* argument sanity check(s) */
if (sa == NULL || buf == NULL || buflen == 0 || raddr == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* receiving is only possible for datagram communication */
if (sa->eType != SA_TYPE_DATAGRAM)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* at least a sa_bind() has to be performed */
if (sa->fdSocket == -1)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* if timeout is enabled, perform explicit/smart blocking instead
of implicitly/hard blocking in the recvfrom(2) system call */
@@ -1991,14 +2004,14 @@
if (n == 0)
errno = ETIMEDOUT;
if (n <= 0)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
}
/* perform receive operation on underlying socket */
sa_len = sizeof(sa_buf);
if ((n = SA_SC_CALL_6(sa, recvfrom, sa->fdSocket, buf, buflen, 0,
(struct sockaddr *)&sa_buf, &sa_len)) == -1)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
/* create result address object */
if ((rv = sa_addr_create(raddr)) != SA_OK)
@@ -2024,11 +2037,11 @@
/* argument sanity check(s) */
if (sa == NULL || buf == NULL || buflen == 0 || raddr == NULL)
- return SA_ERR_ARG;
+ return SA_RC(SA_ERR_ARG);
/* sending is only possible for datagram communication */
if (sa->eType != SA_TYPE_DATAGRAM)
- return SA_ERR_USE;
+ return SA_RC(SA_ERR_USE);
/* lazy creation of underlying socket */
if (sa->fdSocket == -1)
@@ -2047,12 +2060,12 @@
if (n == 0)
errno = ETIMEDOUT;
if (n <= 0)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
}
/* perform send operation on underlying socket */
if ((n = SA_SC_CALL_6(sa, sendto, sa->fdSocket, buf, buflen, 0, raddr->saBuf, raddr->slBuf)) == -1)
- return SA_ERR_SYS;
+ return SA_RC(SA_ERR_SYS);
/* pass actual number of sent bytes to caller */
if (bufdone != NULL)
|