OSSP CVS Repository

ossp - Check-in [1002]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 1002
Date: 2001-Sep-13 22:13:08 (local)
2001-Sep-13 20:13:08 (UTC)
User:rse
Branch:
Comment: Implement sa_getremote() and sa_getlocal()
Tickets:
Inspections:
Files:
ossp-pkg/l2/l2_ut_sa.c      1.8 -> 1.9     42 inserted, 4 deleted
ossp-pkg/l2/l2_ut_sa.h      1.4 -> 1.5     2 inserted, 2 deleted

ossp-pkg/l2/l2_ut_sa.c 1.8 -> 1.9

--- l2_ut_sa.c   2001/09/13 20:07:17     1.8
+++ l2_ut_sa.c   2001/09/13 20:13:08     1.9
@@ -582,7 +582,7 @@
 #ifdef AF_INET6
         struct sockaddr_in6 sa6;
 #endif
-    } sa4a6;
+    } sa_buf;
     socklen_t sa_len;
     int s;
 
@@ -602,10 +602,10 @@
         if (n <= 0)
             return SA_ERR_SYS;
     }
-    sa_len = sizeof(sa4a6);
-    if ((s = accept(sa->sSocket, (struct sockaddr *)&sa4a6, &sa_len)) == -1)
+    sa_len = sizeof(sa_buf);
+    if ((s = accept(sa->sSocket, (struct sockaddr *)&sa_buf, &sa_len)) == -1)
         return SA_ERR_SYS;
-    if ((rv = sa_s2a(caddr, (struct sockaddr *)&sa4a6, sa_len)) != SA_OK)
+    if ((rv = sa_s2a(caddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK)
         return rv;
     if ((rv = sa_create(csa)) != SA_OK) {
         free(*caddr);
@@ -615,6 +615,44 @@
     return SA_OK;
 }
 
+sa_rc_t sa_getremote(sa_t *sa, sa_addr_t **raddr)
+{
+    sa_rc_t rv;
+    union {
+        struct sockaddr_in sa4;
+#ifdef AF_INET6
+        struct sockaddr_in6 sa6;
+#endif
+    } sa_buf;
+    socklen_t sa_len;
+
+    sa_len = sizeof(sa_buf);
+    if (getpeername(sa->sSocket, (struct sockaddr *)&sa_buf, &sa_len) < 0)
+        return SA_ERR_SYS;
+    if ((rv = sa_s2a(raddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK)
+        return rv;
+    return SA_OK;
+}
+
+sa_rc_t sa_getlocal(sa_t *sa, sa_addr_t **laddr)
+{
+    sa_rc_t rv;
+    union {
+        struct sockaddr_in sa4;
+#ifdef AF_INET6
+        struct sockaddr_in6 sa6;
+#endif
+    } sa_buf;
+    socklen_t sa_len;
+
+    sa_len = sizeof(sa_buf);
+    if (getsockname(sa->sSocket, (struct sockaddr *)&sa_buf, &sa_len) < 0)
+        return SA_ERR_SYS;
+    if ((rv = sa_s2a(laddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK)
+        return rv;
+    return SA_OK;
+}
+
 static int sa_read_raw(sa_t *sa, char *cpBuf, int nBufLen)
 {
     int rv;


ossp-pkg/l2/l2_ut_sa.h 1.4 -> 1.5

--- l2_ut_sa.h   2001/09/13 20:07:17     1.4
+++ l2_ut_sa.h   2001/09/13 20:13:08     1.5
@@ -65,8 +65,8 @@
 sa_rc_t sa_listen   (sa_t *sa, int backlog);
 sa_rc_t sa_accept   (sa_t *sa, sa_addr_t **caddr, sa_t **csa);
 
-sa_rc_t sa_getremote(sa_t *sa, sa_addr_t *raddr);
-sa_rc_t sa_getlocal (sa_t *sa, sa_addr_t *laddr);
+sa_rc_t sa_getremote(sa_t *sa, sa_addr_t **raddr);
+sa_rc_t sa_getlocal (sa_t *sa, sa_addr_t **laddr);
 
 sa_rc_t sa_read     (sa_t *sa, char *buf, size_t buflen, size_t *bufdone);
 sa_rc_t sa_readfrom (sa_t *sa, char *buf, size_t buflen, size_t *bufdone, sa_addr_t *addr);

CVSTrac 2.0.1