[xiph-cvs] cvs commit: net sock.c

Michael Smith msmith at xiph.org
Fri Feb 14 03:14:55 PST 2003



msmith      03/02/14 06:14:55

  Modified:    .        sock.c
  Log:
  Fix formatting of ip addresses so that v6 sockets are logged correctly.

Revision  Changes    Path
1.17      +9 -5      net/sock.c

Index: sock.c
===================================================================
RCS file: /usr/local/cvsroot/net/sock.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- sock.c	13 Feb 2003 11:51:35 -0000	1.16
+++ sock.c	14 Feb 2003 11:14:55 -0000	1.17
@@ -668,15 +668,19 @@
         ret = accept(serversock, (struct sockaddr *)&sa, &slen);
 
         if (ret >= 0 && ip != NULL) {
-        /* inet_ntoa is not reentrant, we should protect this */
 #ifdef HAVE_IPV6
-        if(inet_ntop(AF_INET, &((struct sockaddr_in *)&sa)->sin_addr, 
-                    ip, len) <= 0)
-        {
-            inet_ntop(AF_INET6, &((struct sockaddr_in6 *)&sa)->sin6_addr,
+        if(((struct sockaddr_in *)&sa)->sin_family == AF_INET) 
+            inet_ntop(AF_INET, &((struct sockaddr_in *)&sa)->sin_addr,
+                    ip, len);
+        else if(((struct sockaddr_in6 *)&sa)->sin6_family == AF_INET6) 
+            inet_ntop(AF_INET6, &((struct sockaddr_in6 *)&sa)->sin6_addr, 
                     ip, len);
+        else {
+            strncpy(ip, "ERROR", len-1);
+            ip[len-1] = 0;
         }
 #else
+        /* inet_ntoa is not reentrant, we should protect this */
                 strncpy(ip, inet_ntoa(sa.sin_addr), len);
 #endif
                 sock_set_nolinger(ret);

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list