INN commit: trunk (6 files)

INN Commit rra at isc.org
Mon Sep 19 21:03:20 UTC 2011


    Date: Monday, September 19, 2011 @ 14:03:19
  Author: eagle
Revision: 9379

Stop using INADDR_LOOPBACK

It looks like the byte order of INADDR_LOOPBACK is indeterminate and may
require htonl on some systems and not on others.  Avoid the issue by
not using it and instead just using htonl(0x7f000001UL).

Modified:
  trunk/frontends/ovdb_server.c
  trunk/include/portable/socket.h
  trunk/lib/getaddrinfo.c
  trunk/storage/ovdb/ovdb.c
  trunk/tests/lib/getaddrinfo-t.c
  trunk/tests/lib/network-t.c

---------------------------+
 frontends/ovdb_server.c   |    2 +-
 include/portable/socket.h |    5 -----
 lib/getaddrinfo.c         |    5 ++++-
 storage/ovdb/ovdb.c       |    2 +-
 tests/lib/getaddrinfo-t.c |    4 ++--
 tests/lib/network-t.c     |    4 ++--
 6 files changed, 10 insertions(+), 12 deletions(-)

Modified: frontends/ovdb_server.c
===================================================================
--- frontends/ovdb_server.c	2011-09-13 18:47:23 UTC (rev 9378)
+++ frontends/ovdb_server.c	2011-09-19 21:03:19 UTC (rev 9379)
@@ -659,7 +659,7 @@
 #else
     sa.sin_family = AF_INET;
     sa.sin_port = htons(OVDB_SERVER_PORT);
-    sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+    sa.sin_addr.s_addr = htonl(0x7f000001UL);
     
     ret = bind(listensock, (struct sockaddr *)&sa, sizeof sa);
 

Modified: include/portable/socket.h
===================================================================
--- include/portable/socket.h	2011-09-13 18:47:23 UTC (rev 9378)
+++ include/portable/socket.h	2011-09-19 21:03:19 UTC (rev 9379)
@@ -95,11 +95,6 @@
 typedef int socket_type;
 #endif
 
-/* Some systems don't define INADDR_LOOPBACK. */
-#ifndef INADDR_LOOPBACK
-# define INADDR_LOOPBACK 0x7f000001UL
-#endif
-
 /* Defined by RFC 3493, used to store a generic address.  Note that this
    doesn't do the alignment mangling that RFC 3493 does; it's not clear if
    that should be added.... */

Modified: lib/getaddrinfo.c
===================================================================
--- lib/getaddrinfo.c	2011-09-13 18:47:23 UTC (rev 9378)
+++ lib/getaddrinfo.c	2011-09-19 21:03:19 UTC (rev 9379)
@@ -378,7 +378,10 @@
     else {
         if (servname == NULL)
             return EAI_NONAME;
-        addr.s_addr = (flags & AI_PASSIVE) ? INADDR_ANY : INADDR_LOOPBACK;
+        if ((flags & AI_PASSIVE) == AI_PASSIVE)
+            addr.s_addr = INADDR_ANY;
+        else
+            addr.s_addr = htonl(0x7f000001UL);
         ai = gai_addrinfo_new(socktype, NULL, addr, port);
         if (ai == NULL)
             return EAI_MEMORY;

Modified: storage/ovdb/ovdb.c
===================================================================
--- storage/ovdb/ovdb.c	2011-09-13 18:47:23 UTC (rev 9378)
+++ storage/ovdb/ovdb.c	2011-09-19 21:03:19 UTC (rev 9379)
@@ -282,7 +282,7 @@
 #else
     sa.sin_family = AF_INET;
     sa.sin_port = 0;
-    sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+    sa.sin_addr.s_addr = htonl(0x7f000001UL);
     bind(clientfd, (struct sockaddr *) &sa, sizeof sa);
     sa.sin_port = htons(OVDB_SERVER_PORT);
     r = connect(clientfd, (struct sockaddr *) &sa, sizeof sa);

Modified: tests/lib/getaddrinfo-t.c
===================================================================
--- tests/lib/getaddrinfo-t.c	2011-09-13 18:47:23 UTC (rev 9378)
+++ tests/lib/getaddrinfo-t.c	2011-09-19 21:03:19 UTC (rev 9379)
@@ -73,7 +73,7 @@
     is_int(sizeof(struct sockaddr_in), ai->ai_addrlen, "...right addrlen");
     saddr = (struct sockaddr_in *) ai->ai_addr;
     is_int(htons(25), saddr->sin_port, "...right port");
-    ok(saddr->sin_addr.s_addr == INADDR_LOOPBACK, "...right address");
+    ok(saddr->sin_addr.s_addr == htonl(0x7f000001UL), "...right address");
     test_freeaddrinfo(ai);
 
     memset(&hints, 0, sizeof(hints));
@@ -111,7 +111,7 @@
        "valid AI_NUMERICSERV");
     saddr = (struct sockaddr_in *) ai->ai_addr;
     is_int(htons(25), saddr->sin_port, "...right port");
-    ok(saddr->sin_addr.s_addr == INADDR_LOOPBACK, "...right address");
+    ok(saddr->sin_addr.s_addr == htonl(0x7f000001UL), "...right address");
     test_freeaddrinfo(ai);
 
     ok(test_getaddrinfo(NULL, NULL, NULL, &ai) == EAI_NONAME, "EAI_NONAME");

Modified: tests/lib/network-t.c
===================================================================
--- tests/lib/network-t.c	2011-09-13 18:47:23 UTC (rev 9378)
+++ tests/lib/network-t.c	2011-09-19 21:03:19 UTC (rev 9379)
@@ -112,7 +112,7 @@
     client = network_accept_any(fds, count, saddr, &slen);
     listener_handler(client);
     is_int(AF_INET, saddr->sa_family, "...address family is IPv4");
-    is_int(htonl(INADDR_LOOPBACK),
+    is_int(htonl(0x7f000001UL),
            ((struct sockaddr_in *) saddr)->sin_addr.s_addr,
            "...and client address is 127.0.0.1");
     free(saddr);
@@ -342,7 +342,7 @@
             memset(&sin, 0, sizeof(sin));
             sin.sin_family = AF_INET;
             sin.sin_port = htons(11119);
-            sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+            sin.sin_addr.s_addr = htonl(0x7f000001UL);
             if (connect(fd, (struct sockaddr *) &sin, sizeof(sin)) < 0)
                 _exit(1);
             out = fdopen(fd, "w");




More information about the inn-committers mailing list