OSSP CVS Repository

ossp - Difference in ossp-pkg/l2/l2_ut_sa.c versions 1.26 and 1.27
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/l2/l2_ut_sa.c 1.26 -> 1.27

--- l2_ut_sa.c   2005/01/24 15:03:18     1.26
+++ l2_ut_sa.c   2005/02/02 12:26:44     1.27
@@ -210,13 +210,14 @@
 
 /* system call table */
 typedef struct {
-    SA_SC_DECLARE_3(int,     connect,  int, const struct sockaddr *, socklen_t)
-    SA_SC_DECLARE_3(int,     accept,   int, struct sockaddr *, socklen_t *)
-    SA_SC_DECLARE_5(int,     select,   int, fd_set *, fd_set *, fd_set *, struct timeval *)
-    SA_SC_DECLARE_3(ssize_t, read,     int, void *, size_t)
-    SA_SC_DECLARE_3(ssize_t, write,    int, const void *, size_t)
-    SA_SC_DECLARE_6(ssize_t, recvfrom, int, void *, size_t, int, struct sockaddr *, socklen_t *)
-    SA_SC_DECLARE_6(ssize_t, sendto,   int, const void *, size_t, int, const struct sockaddr *, socklen_t)
+    SA_SC_DECLARE_3(int,              connect,       int, const struct sockaddr *, socklen_t)
+    SA_SC_DECLARE_3(int,              accept,        int, struct sockaddr *, socklen_t *)
+    SA_SC_DECLARE_5(int,              select,        int, fd_set *, fd_set *, fd_set *, struct timeval *)
+    SA_SC_DECLARE_3(ssize_t,          read,          int, void *, size_t)
+    SA_SC_DECLARE_3(ssize_t,          write,         int, const void *, size_t)
+    SA_SC_DECLARE_6(ssize_t,          recvfrom,      int, void *, size_t, int, struct sockaddr *, socklen_t *)
+    SA_SC_DECLARE_6(ssize_t,          sendto,        int, const void *, size_t, int, const struct sockaddr *, socklen_t)
+    SA_SC_DECLARE_1(struct hostent *, gethostbyname, const char *name)
 } sa_syscall_tab_t;
 
 /* socket option information */
@@ -497,8 +498,8 @@
     struct servent *se;
     int bIPv6;
     int bNumeric;
-    char *cpHost;
-    char *cpPort;
+    const char *cpHost;
+    const char *cpPort;
     char *cpProto;
     unsigned int nPort;
     const char *cpPath;
@@ -559,7 +560,7 @@
     }
     else if (strncmp(uri, "inet://", 7) == 0) {
         /* parse URI into host, port and protocol parts */
-        cpHost = (char *)(uri+7);
+        cpHost = uri+7;
         bIPv6 = FALSE;
         if (cpHost[0] == '[') {
             /* IPv6 address (see RFC2732) */
@@ -652,7 +653,7 @@
             sf = AF_INET6;
         }
 #endif
-        else if ((he = gethostbyname(cpHost)) != NULL) {
+        else if ((he = SA_SC_CALL_1(sa, gethostbyname, cpHost)) != NULL) {
             if (he->h_addrtype == AF_INET) {
                 sa4.sin_family = AF_INET;
                 sa4.sin_port = htons(nPort);
@@ -940,13 +941,13 @@
         return SA_OK;
 
 #if defined(SO_RCVTIMEO) && defined(USE_SO_RCVTIMEO) && defined(SO_SNDTIMEO) && defined(USE_SO_SNDTIMEO)
-    if (SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_READ])) {
+    if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_READ])) {
         if (setsockopt(sa->fdSocket, SOL_SOCKET, SO_RCVTIMEO,
                        (const void *)(&sa->tvTimeout[SA_TIMEOUT_READ]),
                        (socklen_t)(sizeof(sa->tvTimeout[SA_TIMEOUT_READ]))) < 0)
             return SA_RC(SA_ERR_SYS);
     }
-    if (SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_WRITE])) {
+    if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_WRITE])) {
         if (setsockopt(sa->fdSocket, SOL_SOCKET, SO_SNDTIMEO,
                        (const void *)(&sa->tvTimeout[SA_TIMEOUT_WRITE]),
                        (socklen_t)(sizeof(sa->tvTimeout[SA_TIMEOUT_WRITE]))) < 0)
@@ -989,7 +990,7 @@
 #if defined(SO_LINGER)
                     struct linger linger;
                     linger.l_onoff  = (sa->optInfo[i].value == 0 ? 0 : 1);
-                    linger.l_linger = sa->optInfo[i].value;
+                    linger.l_linger = (sa->optInfo[i].value <= 0 ? 0 : sa->optInfo[i].value);
                     if (setsockopt(sa->fdSocket, SOL_SOCKET, SO_LINGER,
                                    (const void *)&linger,
                                    (socklen_t)sizeof(struct linger)) < 0)
@@ -1175,13 +1176,14 @@
     }
 
     /* init syscall object attributes */
-    SA_SC_ASSIGN(sa, connect,  connect,  NULL);
-    SA_SC_ASSIGN(sa, accept,   accept,   NULL);
-    SA_SC_ASSIGN(sa, select,   select,   NULL);
-    SA_SC_ASSIGN(sa, read,     read,     NULL);
-    SA_SC_ASSIGN(sa, write,    write,    NULL);
-    SA_SC_ASSIGN(sa, recvfrom, recvfrom, NULL);
-    SA_SC_ASSIGN(sa, sendto,   sendto,   NULL);
+    SA_SC_ASSIGN(sa, connect,       connect,       NULL);
+    SA_SC_ASSIGN(sa, accept,        accept,        NULL);
+    SA_SC_ASSIGN(sa, select,        select,        NULL);
+    SA_SC_ASSIGN(sa, read,          read,          NULL);
+    SA_SC_ASSIGN(sa, write,         write,         NULL);
+    SA_SC_ASSIGN(sa, recvfrom,      recvfrom,      NULL);
+    SA_SC_ASSIGN(sa, sendto,        sendto,        NULL);
+    SA_SC_ASSIGN(sa, gethostbyname, gethostbyname, NULL);
 
     /* pass object to caller */
     *sap = sa;
@@ -1339,7 +1341,7 @@
         }
         case SA_OPTION_LINGER: {
 #if defined(SO_LINGER)
-            int amount = ((int)va_arg(ap, int) ? 1 : 0);
+            int amount = (int)va_arg(ap, int);
             sa->optInfo[SA_OPTION_LINGER].value = amount;
             sa->optInfo[SA_OPTION_LINGER].todo = TRUE;
 #else
@@ -1404,13 +1406,14 @@
     /* assign system call */
     rv = SA_OK;
     switch (id) {
-        case SA_SYSCALL_CONNECT:  SA_SC_ASSIGN(sa, connect,  fptr, fctx); break;
-        case SA_SYSCALL_ACCEPT:   SA_SC_ASSIGN(sa, accept,   fptr, fctx); break;
-        case SA_SYSCALL_SELECT:   SA_SC_ASSIGN(sa, select,   fptr, fctx); break;
-        case SA_SYSCALL_READ:     SA_SC_ASSIGN(sa, read,     fptr, fctx); break;
-        case SA_SYSCALL_WRITE:    SA_SC_ASSIGN(sa, write,    fptr, fctx); break;
-        case SA_SYSCALL_RECVFROM: SA_SC_ASSIGN(sa, recvfrom, fptr, fctx); break;
-        case SA_SYSCALL_SENDTO:   SA_SC_ASSIGN(sa, sendto,   fptr, fctx); break;
+        case SA_SYSCALL_CONNECT:       SA_SC_ASSIGN(sa, connect,       fptr, fctx); break;
+        case SA_SYSCALL_ACCEPT:        SA_SC_ASSIGN(sa, accept,        fptr, fctx); break;
+        case SA_SYSCALL_SELECT:        SA_SC_ASSIGN(sa, select,        fptr, fctx); break;
+        case SA_SYSCALL_READ:          SA_SC_ASSIGN(sa, read,          fptr, fctx); break;
+        case SA_SYSCALL_WRITE:         SA_SC_ASSIGN(sa, write,         fptr, fctx); break;
+        case SA_SYSCALL_RECVFROM:      SA_SC_ASSIGN(sa, recvfrom,      fptr, fctx); break;
+        case SA_SYSCALL_SENDTO:        SA_SC_ASSIGN(sa, sendto,        fptr, fctx); break;
+        case SA_SYSCALL_GETHOSTBYNAME: SA_SC_ASSIGN(sa, gethostbyname, fptr, fctx); break;
         default: rv = SA_ERR_ARG;
     }
 
@@ -1453,6 +1456,7 @@
     socklen_t len;
     sa_rc_t rv;
     struct timeval *tv;
+    struct timeval tv_buf;
 
     /* argument sanity check(s) */
     if (sa == NULL || raddr == NULL)
@@ -1509,12 +1513,14 @@
     FD_ZERO(&wset);
     FD_SET(sa->fdSocket, &rset);
     FD_SET(sa->fdSocket, &wset);
-    if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_CONNECT]))
-        tv = &sa->tvTimeout[SA_TIMEOUT_CONNECT];
+    if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_CONNECT])) {
+        memcpy(&tv_buf, &sa->tvTimeout[SA_TIMEOUT_CONNECT], sizeof(struct timeval));
+        tv = &tv_buf;
+    }
     else
         tv = NULL;
     do {
-        n = SA_SC_CALL_5(sa, select, sa->fdSocket+1, &rset, &wset, NULL, tv);
+        n = SA_SC_CALL_5(sa, select, sa->fdSocket+1, &rset, &wset, (fd_set *)NULL, tv);
     } while (n == -1 && errno == EINTR);
 
     /* decide on return semantic */
@@ -1588,6 +1594,7 @@
 #endif
     } sa_buf;
     socklen_t sa_size;
+    struct timeval tv;
     int s;
     int i;
 
@@ -1607,9 +1614,9 @@
     if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_ACCEPT])) {
         FD_ZERO(&fds);
         FD_SET(sa->fdSocket, &fds);
+        memcpy(&tv, &sa->tvTimeout[SA_TIMEOUT_ACCEPT], sizeof(struct timeval));
         do {
-            n = SA_SC_CALL_5(sa, select, sa->fdSocket+1, &fds, NULL, NULL,
-                             &sa->tvTimeout[SA_TIMEOUT_ACCEPT]);
+            n = SA_SC_CALL_5(sa, select, sa->fdSocket+1, &fds, (fd_set *)NULL, (fd_set *)NULL, &tv);
         } while (n == -1 && errno == EINTR);
         if (n == 0)
             return SA_RC(SA_ERR_TMT);
@@ -1650,6 +1657,7 @@
     SA_SC_COPY((*csa), sa, write);
     SA_SC_COPY((*csa), sa, recvfrom);
     SA_SC_COPY((*csa), sa, sendto);
+    SA_SC_COPY((*csa), sa, gethostbyname);
 
     /* copy-over original timeout values */
     for (i = 0; i < (int)(sizeof(sa->tvTimeout)/sizeof(sa->tvTimeout[0])); i++) {
@@ -1759,6 +1767,7 @@
     int rv;
 #if !(defined(SO_RCVTIMEO) && defined(USE_SO_RCVTIMEO) && defined(SO_SNDTIMEO) && defined(USE_SO_SNDTIMEO))
     fd_set fds;
+    struct timeval tv;
 #endif
 
     /* if timeout is enabled, perform explicit/smart blocking instead
@@ -1767,9 +1776,9 @@
     if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_READ])) {
         FD_ZERO(&fds);
         FD_SET(sa->fdSocket, &fds);
+        memcpy(&tv, &sa->tvTimeout[SA_TIMEOUT_READ], sizeof(struct timeval));
         do {
-            rv = SA_SC_CALL_5(sa, select, sa->fdSocket+1, &fds, NULL, NULL,
-                              &sa->tvTimeout[SA_TIMEOUT_READ]);
+            rv = SA_SC_CALL_5(sa, select, sa->fdSocket+1, &fds, (fd_set *)NULL, (fd_set *)NULL, &tv);
         } while (rv == -1 && errno == EINTR);
         if (rv == 0) {
             errno = ETIMEDOUT;
@@ -1938,6 +1947,7 @@
     int rv;
 #if !(defined(SO_RCVTIMEO) && defined(USE_SO_RCVTIMEO) && defined(SO_SNDTIMEO) && defined(USE_SO_SNDTIMEO))
     fd_set fds;
+    struct timeval tv;
 #endif
 
     /* if timeout is enabled, perform explicit/smart blocking instead
@@ -1946,9 +1956,9 @@
     if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_WRITE])) {
         FD_ZERO(&fds);
         FD_SET(sa->fdSocket, &fds);
+        memcpy(&tv, &sa->tvTimeout[SA_TIMEOUT_WRITE], sizeof(struct timeval));
         do {
-            rv = SA_SC_CALL_5(sa, select, sa->fdSocket+1, NULL, &fds, NULL,
-                              &sa->tvTimeout[SA_TIMEOUT_WRITE]);
+            rv = SA_SC_CALL_5(sa, select, sa->fdSocket+1, (fd_set *)NULL, &fds, (fd_set *)NULL, &tv);
         } while (rv == -1 && errno == EINTR);
         if (rv == 0) {
             errno = ETIMEDOUT;
@@ -2173,6 +2183,7 @@
     ssize_t n;
     int k;
     fd_set fds;
+    struct timeval tv;
 
     /* argument sanity check(s) */
     if (sa == NULL || buf == NULL || buflen == 0 || raddr == NULL)
@@ -2191,9 +2202,9 @@
     if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_READ])) {
         FD_ZERO(&fds);
         FD_SET(sa->fdSocket, &fds);
+        memcpy(&tv, &sa->tvTimeout[SA_TIMEOUT_READ], sizeof(struct timeval));
         do {
-            k = SA_SC_CALL_5(sa, select, sa->fdSocket+1, &fds, NULL, NULL,
-                             &sa->tvTimeout[SA_TIMEOUT_READ]);
+            k = SA_SC_CALL_5(sa, select, sa->fdSocket+1, &fds, (fd_set *)NULL, (fd_set *)NULL, &tv);
         } while (k == -1 && errno == EINTR);
         if (k == 0)
             errno = ETIMEDOUT;
@@ -2229,6 +2240,7 @@
     int k;
     fd_set fds;
     sa_rc_t rv;
+    struct timeval tv;
 
     /* argument sanity check(s) */
     if (sa == NULL || buf == NULL || buflen == 0 || raddr == NULL)
@@ -2248,9 +2260,9 @@
     if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_WRITE])) {
         FD_ZERO(&fds);
         FD_SET(sa->fdSocket, &fds);
+        memcpy(&tv, &sa->tvTimeout[SA_TIMEOUT_WRITE], sizeof(struct timeval));
         do {
-            k = SA_SC_CALL_5(sa, select, sa->fdSocket+1, NULL, &fds, NULL,
-                             &sa->tvTimeout[SA_TIMEOUT_WRITE]);
+            k = SA_SC_CALL_5(sa, select, sa->fdSocket+1, (fd_set *)NULL, &fds, (fd_set *)NULL, &tv);
         } while (k == -1 && errno == EINTR);
         if (k == 0)
             errno = ETIMEDOUT;
@@ -2273,6 +2285,7 @@
 sa_rc_t sa_sendf(sa_t *sa, sa_addr_t *raddr, const char *cpFmt, ...)
 {
     va_list ap;
+    va_list apbak;
     int nBuf;
     char *cpBuf;
     sa_rc_t rv;
@@ -2284,9 +2297,10 @@
 
     /* format string into temporary buffer */
     va_start(ap, cpFmt);
+    va_copy(apbak, ap);
     if ((nBuf = sa_mvsnprintf(NULL, 0, cpFmt, ap)) == -1)
         return SA_RC(SA_ERR_FMT);
-    va_end(ap);
+    va_copy(ap, apbak);
     if ((nBuf+1) > (int)sizeof(caBuf)) {
         /* requires a larger buffer, so allocate dynamically */
         if ((cpBuf = (char *)malloc((size_t)(nBuf+1))) == NULL)
@@ -2296,7 +2310,6 @@
         /* fits into small buffer, so allocate statically */
         cpBuf = caBuf;
     }
-    va_start(ap, cpFmt);
     rv = SA_OK;
     if (sa_mvsnprintf(cpBuf, (size_t)(nBuf+1), cpFmt, ap) == -1)
         rv = SA_ERR_FMT;

CVSTrac 2.0.1