INN commit: trunk (11 files)

INN Commit rra at isc.org
Thu Aug 18 13:38:03 UTC 2011


    Date: Thursday, August 18, 2011 @ 06:38:03
  Author: iulius
Revision: 9345

update network librairies from rra-c-util 3.7

* Change the prototype of network_bind_all to use (unsigned int *) instead
of (signed int *) for the count argument.

* Adapt nnrpd to use unsigned int for lfdcount, and innd to use unsigned int
for chanlimit.

* Add the network_accept_any function.  (Currently unused.)

* Define the socket_type type and INVALID_SOCKET.

* Update dependencies.

* Fix a typo in a comment in lib/network.c.

* Update the test suite to use network-t.c from rra-c-util 3.7.

Modified:
  trunk/authprogs/Makefile
  trunk/include/inn/network.h
  trunk/include/portable/socket.h
  trunk/innd/Makefile
  trunk/innd/rc.c
  trunk/innfeed/Makefile
  trunk/lib/Makefile
  trunk/lib/network.c
  trunk/nnrpd/Makefile
  trunk/nnrpd/nnrpd.c
  trunk/tests/lib/network-t.c

---------------------------+
 authprogs/Makefile        |    7 
 include/inn/network.h     |   15 +
 include/portable/socket.h |   48 +++
 innd/Makefile             |   42 +--
 innd/rc.c                 |   22 -
 innfeed/Makefile          |   11 
 lib/Makefile              |    9 
 lib/network.c             |   65 ++++-
 nnrpd/Makefile            |   25 +-
 nnrpd/nnrpd.c             |   44 +--
 tests/lib/network-t.c     |  547 ++++++++++++++++++++++++++++----------------
 11 files changed, 554 insertions(+), 281 deletions(-)

Modified: authprogs/Makefile
===================================================================
--- authprogs/Makefile	2011-08-16 14:33:18 UTC (rev 9344)
+++ authprogs/Makefile	2011-08-18 13:38:03 UTC (rev 9345)
@@ -96,9 +96,10 @@
 ident.o: ident.c ../include/config.h ../include/inn/defines.h \
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
   ../include/config.h ../include/inn/messages.h ../include/inn/defines.h \
-  ../include/inn/network.h ../include/inn/libinn.h libauth.h \
-  ../include/portable/socket.h ../include/config.h \
-  ../include/portable/getaddrinfo.h ../include/portable/getnameinfo.h
+  ../include/inn/network.h ../include/portable/socket.h \
+  ../include/config.h ../include/portable/getaddrinfo.h \
+  ../include/portable/getnameinfo.h ../include/inn/libinn.h libauth.h \
+  ../include/portable/socket.h
 libauth.o: libauth.c ../include/config.h ../include/inn/defines.h \
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
   ../include/config.h ../include/portable/socket.h ../include/config.h \

Modified: include/inn/network.h
===================================================================
--- include/inn/network.h	2011-08-16 14:33:18 UTC (rev 9344)
+++ include/inn/network.h	2011-08-18 13:38:03 UTC (rev 9345)
@@ -11,6 +11,7 @@
 #define INN_NETWORK_H 1
 
 #include <inn/defines.h>
+#include "portable/socket.h"
 #include <sys/types.h>          /* socklen_t */
 
 /* Forward declarations to avoid unnecessary includes. */
@@ -42,8 +43,20 @@
    just one socket will be created and bound to the IPv4 wildcard address.
    fds will be set to an array containing the resulting file descriptors, with
    count holding the count returned. */
-void network_bind_all(unsigned short port, int **fds, int *count);
+void network_bind_all(unsigned short port, int **fds, unsigned int *count);
 
+/*
+ * Accept an incoming connection from any file descriptor in an array.  This
+ * is a blocking accept that will wait until there is an incoming connection,
+ * unless interrupted by receipt of a signal.  Returns the new socket or
+ * INVALID_SOCKET, and fills out the arguments with the address of the remote
+ * client.  If the wait for a connection was interrupted by a signal, returns
+ * INVALID_SOCKET with errno set to EINTR.
+ */
+socket_type network_accept_any(socket_type fds[], unsigned int count,
+                               struct sockaddr *addr, socklen_t *addrlen)
+    __attribute__((__nonnull__(1)));
+
 /* Create a socket and connect it to the remote service given by the linked
    list of addrinfo structs.  Returns the new file descriptor on success and
    -1 on failure, with the error left in errno.  Takes an optional source

Modified: include/portable/socket.h
===================================================================
--- include/portable/socket.h	2011-08-16 14:33:18 UTC (rev 9344)
+++ include/portable/socket.h	2011-08-18 13:38:03 UTC (rev 9345)
@@ -47,6 +47,54 @@
 extern const char *     inet_ntop(int, const void *, char *, socklen_t);
 #endif
 
+/*
+ * Used for portability to Windows, which requires different functions be
+ * called to close sockets, send data to or read from sockets, and get socket
+ * errors than the regular functions and variables.  Windows also uses SOCKET
+ * to store socket descriptors instead of an int.
+ *
+ * socket_init must be called before socket functions are used and
+ * socket_shutdown at the end of the program.  socket_init may return failure,
+ * but this interface doesn't have a way to retrieve the exact error.
+ *
+ * socket_close, socket_read, and socket_write must be used instead of the
+ * standard functions.  On Windows, closesocket must be called instead of
+ * close for sockets and recv and send must always be used instead of read and
+ * write.
+ *
+ * When reporting errors from socket functions, use socket_errno and
+ * socket_strerror instead of errno and strerror.  When setting errno to
+ * something for socket errors (to preserve errors through close, for
+ * example), use socket_set_errno instead of just assigning to errno.
+ *
+ * Socket file descriptors must be passed and stored in variables of type
+ * socket_type rather than an int.  Use INVALID_SOCKET for invalid socket file
+ * descriptors rather than -1, and compare to INVALID_SOCKET when testing
+ * whether operations succeed.
+ */
+#ifdef _WIN32
+int socket_init(void);
+# define socket_shutdown()      WSACleanup()
+# define socket_close(fd)       closesocket(fd)
+# define socket_read(fd, b, s)  recv((fd), (b), (s), 0)
+# define socket_write(fd, b, s) send((fd), (b), (s), 0)
+# define socket_errno           WSAGetLastError()
+# define socket_set_errno(e)    WSASetLastError(e)
+const char *socket_strerror(int);
+typedef SOCKET socket_type;
+#else
+# define socket_init()          1
+# define socket_shutdown()      /* empty */
+# define socket_close(fd)       close(fd)
+# define socket_read(fd, b, s)  read((fd), (b), (s))
+# define socket_write(fd, b, s) write((fd), (b), (s))
+# define socket_errno           errno
+# define socket_set_errno(e)    errno = (e)
+# define socket_strerror(e)     strerror(e)
+# define INVALID_SOCKET         -1
+typedef int socket_type;
+#endif
+
 /* Some systems don't define INADDR_LOOPBACK. */
 #ifndef INADDR_LOOPBACK
 # define INADDR_LOOPBACK 0x7f000001UL

Modified: innd/Makefile
===================================================================
--- innd/Makefile	2011-08-16 14:33:18 UTC (rev 9344)
+++ innd/Makefile	2011-08-18 13:38:03 UTC (rev 9345)
@@ -95,13 +95,14 @@
 chan.o: chan.c ../include/config.h ../include/inn/defines.h \
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
   ../include/config.h ../include/inn/innconf.h ../include/inn/defines.h \
-  ../include/inn/network.h innd.h ../include/portable/time.h \
-  ../include/config.h ../include/portable/socket.h \
-  ../include/portable/getaddrinfo.h ../include/portable/getnameinfo.h \
-  ../include/inn/buffer.h ../include/inn/history.h \
-  ../include/inn/messages.h ../include/inn/timer.h \
-  ../include/inn/libinn.h ../include/inn/nntp.h ../include/inn/paths.h \
-  ../include/inn/storage.h ../include/inn/options.h
+  ../include/inn/network.h ../include/portable/socket.h \
+  ../include/config.h ../include/portable/getaddrinfo.h \
+  ../include/portable/getnameinfo.h innd.h ../include/portable/time.h \
+  ../include/portable/socket.h ../include/inn/buffer.h \
+  ../include/inn/history.h ../include/inn/messages.h \
+  ../include/inn/timer.h ../include/inn/libinn.h ../include/inn/nntp.h \
+  ../include/inn/paths.h ../include/inn/storage.h \
+  ../include/inn/options.h
 icd.o: icd.c ../include/config.h ../include/inn/defines.h \
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
   ../include/config.h ../include/portable/mmap.h ../include/config.h \
@@ -199,7 +200,8 @@
   ../include/inn/paths.h ../include/inn/storage.h \
   ../include/inn/options.h
 python.o: python.c ../include/config.h ../include/inn/defines.h \
-  ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
+  ../include/inn/system.h ../include/inn/options.h \
+  ../include/clibrary.h \
   ../include/config.h ../include/inn/innconf.h ../include/inn/defines.h \
   ../include/inn/wire.h innd.h ../include/portable/time.h \
   ../include/config.h ../include/portable/socket.h \
@@ -213,12 +215,12 @@
   ../include/config.h ../include/portable/socket.h ../include/config.h \
   ../include/portable/getaddrinfo.h ../include/portable/getnameinfo.h \
   ../include/inn/innconf.h ../include/inn/defines.h \
-  ../include/inn/network.h ../include/inn/vector.h innd.h \
-  ../include/portable/time.h ../include/inn/buffer.h \
-  ../include/inn/history.h ../include/inn/messages.h \
-  ../include/inn/timer.h ../include/inn/libinn.h ../include/inn/nntp.h \
-  ../include/inn/paths.h ../include/inn/storage.h \
-  ../include/inn/options.h
+  ../include/inn/network.h ../include/portable/socket.h \
+  ../include/inn/vector.h innd.h ../include/portable/time.h \
+  ../include/inn/buffer.h ../include/inn/history.h \
+  ../include/inn/messages.h ../include/inn/timer.h \
+  ../include/inn/libinn.h ../include/inn/nntp.h ../include/inn/paths.h \
+  ../include/inn/storage.h ../include/inn/options.h
 site.o: site.c ../include/config.h ../include/inn/defines.h \
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
   ../include/config.h ../include/inn/innconf.h ../include/inn/defines.h \
@@ -234,12 +236,12 @@
   ../include/config.h ../include/portable/socket.h ../include/config.h \
   ../include/portable/getaddrinfo.h ../include/portable/getnameinfo.h \
   ../include/inn/network.h ../include/inn/defines.h \
-  ../include/inn/innconf.h ../include/inn/version.h innd.h \
-  ../include/portable/time.h ../include/inn/buffer.h \
-  ../include/inn/history.h ../include/inn/messages.h \
-  ../include/inn/timer.h ../include/inn/libinn.h ../include/inn/nntp.h \
-  ../include/inn/paths.h ../include/inn/storage.h \
-  ../include/inn/options.h ../include/innperl.h
+  ../include/portable/socket.h ../include/inn/innconf.h \
+  ../include/inn/version.h innd.h ../include/portable/time.h \
+  ../include/inn/buffer.h ../include/inn/history.h \
+  ../include/inn/messages.h ../include/inn/timer.h \
+  ../include/inn/libinn.h ../include/inn/nntp.h ../include/inn/paths.h \
+  ../include/inn/storage.h ../include/inn/options.h ../include/innperl.h
 util.o: util.c ../include/config.h ../include/inn/defines.h \
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
   ../include/config.h ../include/inn/innconf.h ../include/inn/defines.h \

Modified: innd/rc.c
===================================================================
--- innd/rc.c	2011-08-16 14:33:18 UTC (rev 9344)
+++ innd/rc.c	2011-08-18 13:38:03 UTC (rev 9345)
@@ -64,7 +64,7 @@
 static char		*RCnnrpd = NULL;
 static char		*RCnntpd = NULL;
 static CHANNEL		**RCchan;
-static int		chanlimit;
+static unsigned int	chanlimit;
 static REMOTEHOST_DATA	*RCpeerlistfile;
 static REMOTEHOST	*RCpeerlist;
 static int		RCnpeerlist;
@@ -425,6 +425,7 @@
     struct sockaddr_storage	remote;
     socklen_t		size;
     int                 i;
+    unsigned int        j;
     REMOTEHOST          *rp;
     CHANNEL		*new;
     char		*name;
@@ -437,12 +438,12 @@
     char		buff[SMBUF];
     char                addr[INET6_ADDRSTRLEN];
 
-    for (i = 0 ; i < chanlimit ; i++) {
-	if (RCchan[i] == cp) {
+    for (j = 0 ; j < chanlimit ; j++) {
+	if (RCchan[j] == cp) {
 	    break;
 	}
     }
-    if (i == chanlimit) {
+    if (j == chanlimit) {
 	syslog(L_ERROR, "%s internal RCreader wrong channel 0x%p",
 		LogName, (void *)cp);
 	return;
@@ -1736,7 +1737,7 @@
 RCsetup(void)
 {
     CHANNEL *rc;
-    int count, i, start;
+    unsigned int count, i, start;
     int *fds;
     bool okay;
 
@@ -1810,12 +1811,13 @@
 void
 RCclose(void)
 {
-    REMOTEHOST	*rp;
-    int		i;
+    REMOTEHOST   *rp;
+    int          i;
+    unsigned int j;
 
-    for (i = 0 ; i < chanlimit ; i++) {
-	if (RCchan[i] != NULL) {
-	    CHANclose(RCchan[i], CHANname(RCchan[i]));
+    for (j = 0 ; j < chanlimit ; j++) {
+	if (RCchan[j] != NULL) {
+	    CHANclose(RCchan[j], CHANname(RCchan[j]));
 	} else {
 	    break;
 	}

Modified: innfeed/Makefile
===================================================================
--- innfeed/Makefile	2011-08-16 14:33:18 UTC (rev 9344)
+++ innfeed/Makefile	2011-08-18 13:38:03 UTC (rev 9345)
@@ -123,8 +123,8 @@
   ../include/portable/getaddrinfo.h ../include/portable/getnameinfo.h \
   ../include/portable/time.h ../include/inn/innconf.h \
   ../include/inn/messages.h ../include/inn/network.h \
-  ../include/inn/libinn.h article.h misc.h buffer.h configfile.h \
-  connection.h endpoint.h host.h
+  ../include/portable/socket.h ../include/inn/libinn.h article.h misc.h \
+  buffer.h configfile.h connection.h endpoint.h host.h
 endpoint.o: endpoint.c innfeed.h ../include/inn/timer.h \
   ../include/inn/defines.h ../include/inn/system.h ../include/config.h \
   ../include/inn/defines.h ../include/inn/options.h ../include/clibrary.h \
@@ -139,9 +139,10 @@
   ../include/portable/socket.h ../include/config.h \
   ../include/portable/getaddrinfo.h ../include/portable/getnameinfo.h \
   ../include/inn/innconf.h ../include/inn/messages.h \
-  ../include/inn/network.h ../include/inn/version.h \
-  ../include/inn/libinn.h article.h misc.h buffer.h configfile.h \
-  connection.h endpoint.h host.h innlistener.h tape.h
+  ../include/inn/network.h ../include/portable/socket.h \
+  ../include/inn/version.h ../include/inn/libinn.h article.h misc.h \
+  buffer.h configfile.h connection.h endpoint.h host.h innlistener.h \
+  tape.h
 imap_connection.o: imap_connection.c ../include/config.h \
   ../include/inn/defines.h ../include/inn/system.h \
   ../include/inn/options.h ../include/clibrary.h ../include/config.h \

Modified: lib/Makefile
===================================================================
--- lib/Makefile	2011-08-16 14:33:18 UTC (rev 9344)
+++ lib/Makefile	2011-08-18 13:38:03 UTC (rev 9345)
@@ -217,7 +217,7 @@
   ../include/portable/time.h ../include/portable/wait.h \
   ../include/inn/innconf.h ../include/inn/defines.h \
   ../include/inn/messages.h ../include/inn/network.h \
-  ../include/inn/libinn.h
+  ../include/portable/socket.h ../include/inn/libinn.h
 newsuser.o: newsuser.c ../include/config.h ../include/inn/defines.h \
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
   ../include/config.h ../include/inn/innconf.h ../include/inn/defines.h \
@@ -229,8 +229,8 @@
   ../include/portable/getaddrinfo.h ../include/portable/getnameinfo.h \
   ../include/portable/time.h ../include/inn/buffer.h \
   ../include/inn/defines.h ../include/inn/innconf.h \
-  ../include/inn/network.h ../include/inn/nntp.h ../include/inn/vector.h \
-  ../include/inn/libinn.h
+  ../include/inn/network.h ../include/portable/socket.h \
+  ../include/inn/nntp.h ../include/inn/vector.h ../include/inn/libinn.h
 numbers.o: numbers.c ../include/config.h ../include/inn/defines.h \
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
   ../include/config.h ../include/inn/libinn.h ../include/inn/defines.h
@@ -249,7 +249,8 @@
   ../include/config.h ../include/portable/socket.h ../include/config.h \
   ../include/portable/getaddrinfo.h ../include/portable/getnameinfo.h \
   ../include/inn/innconf.h ../include/inn/defines.h \
-  ../include/inn/libinn.h ../include/inn/network.h ../include/inn/nntp.h
+  ../include/inn/libinn.h ../include/inn/network.h \
+  ../include/portable/socket.h ../include/inn/nntp.h
 reservedfd.o: reservedfd.c ../include/config.h ../include/inn/defines.h \
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
   ../include/config.h ../include/inn/libinn.h ../include/inn/defines.h

Modified: lib/network.c
===================================================================
--- lib/network.c	2011-08-16 14:33:18 UTC (rev 9344)
+++ lib/network.c	2011-08-18 13:38:03 UTC (rev 9345)
@@ -50,8 +50,9 @@
 network_set_reuseaddr(int fd)
 {
     int flag = 1;
+    const void *flagaddr = &flag;
 
-    if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag)) < 0)
+    if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, flagaddr, sizeof(flag)) < 0)
         syswarn("cannot mark bind address reusable");
 }
 #endif
@@ -252,7 +253,7 @@
         syswarn("cannot set IPv6 socket to v6only");
 #endif
 
-    /* Accept "any" or "all" in the bind address to mean 0.0.0.0. */
+    /* Accept "any" or "all" in the bind address to mean ::. */
     if (!strcmp(address, "any") || !strcmp(address, "all"))
         address = "::";
 
@@ -301,10 +302,11 @@
 */
 #if HAVE_INET6
 void
-network_bind_all(unsigned short port, int **fds, int *count)
+network_bind_all(unsigned short port, int **fds, unsigned int *count)
 {
     struct addrinfo hints, *addrs, *addr;
-    int error, fd, size;
+    unsigned int size;
+    int error, fd;
     char service[16], name[INET6_ADDRSTRLEN];
 
     *count = 0;
@@ -363,7 +365,7 @@
 }
 #else /* HAVE_INET6 */
 void
-network_bind_all(unsigned short port, int **fds, int *count)
+network_bind_all(unsigned short port, int **fds, unsigned int *count)
 {
     int fd;
 
@@ -379,7 +381,56 @@
 }
 #endif /* HAVE_INET6 */
 
+/*
+ * Given an array of file descriptors and the length of that array (the same
+ * data that's returned by network_bind_all), wait for an incoming connection
+ * on any of those sockets, accept the connection with accept(), and return
+ * the new file descriptor.
+ *
+ * This is essentially a replacement for accept() with a single socket for
+ * daemons that are listening to multiple separate bound sockets, possibly
+ * because they need to listen to specific interfaces or possibly because
+ * they're listening for both IPv4 and IPv6 connections.
+ *
+ * Returns the new socket on success or INVALID_SOCKET on failure.  On
+ * success, fills out the arguments with the address and address length of the
+ * accepted client.  No error will be reported, so the caller should do that
+ * Note that INVALID_SOCKET may be returned if the timeout is interrupted by a
+ * signal, which is not, precisely speaking, an error condition.  In this
+ * case, errno will be set to EINTR.
+*/
+socket_type
+network_accept_any(socket_type fds[], unsigned int count,
+                   struct sockaddr *addr, socklen_t *addrlen)
+{
+    fd_set readfds;
+    socket_type maxfd, fd;
+    unsigned int i;
+    int status;
 
+    FD_ZERO(&readfds);
+    maxfd = -1;
+    for (i = 0; i < count; i++) {
+        FD_SET(fds[i], &readfds);
+        if (fds[i] > maxfd)
+            maxfd = fds[i];
+    }
+    status = select(maxfd + 1, &readfds, NULL, NULL, NULL);
+    if (status < 0)
+        return INVALID_SOCKET;
+    fd = INVALID_SOCKET;
+    for (i = 0; i < count; i++)
+        if (FD_ISSET(fds[i], &readfds)) {
+            fd = fds[i];
+            break;
+        }
+    if (fd == INVALID_SOCKET)
+        return INVALID_SOCKET;
+    else
+        return accept(fd, addr, addrlen);
+}
+
+
 /*
 **  Binds the given socket to an appropriate source address for its family,
 **  using innconf information or the provided source address.  Returns true on
@@ -718,7 +769,7 @@
             if (cidr > 32 || *end != '\0')
                 return false;
             for (bits = 0, i = 0; i < cidr; i++)
-                bits |= (1 << (31 - i));
+                bits |= (1UL << (31 - i));
             addr_mask = htonl(bits);
         } else if (inet_aton(mask, &tmp))
             addr_mask = tmp.s_addr;
@@ -745,7 +796,7 @@
                 return false;
         } else {
             for (addr_mask = 0, bits = 0; bits < cidr % 8; bits++)
-                addr_mask |= (1 << (7 - bits));
+                addr_mask |= (1UL << (7 - bits));
             if ((a6.s6_addr[i] & addr_mask) != (b6.s6_addr[i] & addr_mask))
                 return false;
         }

Modified: nnrpd/Makefile
===================================================================
--- nnrpd/Makefile	2011-08-16 14:33:18 UTC (rev 9344)
+++ nnrpd/Makefile	2011-08-18 13:38:03 UTC (rev 9345)
@@ -163,13 +163,13 @@
   ../include/portable/getnameinfo.h ../include/portable/wait.h \
   ../include/inn/innconf.h ../include/inn/defines.h \
   ../include/inn/libinn.h ../include/inn/messages.h \
-  ../include/inn/network.h ../include/inn/newsuser.h ../include/config.h \
-  ../include/clibrary.h ../include/inn/ov.h ../include/inn/storage.h \
-  ../include/inn/options.h ../include/inn/history.h \
-  ../include/inn/version.h nnrpd.h ../include/portable/time.h \
-  ../include/inn/qio.h ../include/inn/nntp.h ../include/inn/paths.h \
-  ../include/inn/storage.h ../include/inn/vector.h ../include/inn/timer.h \
-  tls.h
+  ../include/inn/network.h ../include/portable/socket.h \
+  ../include/inn/newsuser.h ../include/config.h ../include/clibrary.h \
+  ../include/inn/ov.h ../include/inn/storage.h ../include/inn/options.h \
+  ../include/inn/history.h ../include/inn/version.h nnrpd.h \
+  ../include/portable/time.h ../include/inn/qio.h ../include/inn/nntp.h \
+  ../include/inn/paths.h ../include/inn/storage.h ../include/inn/vector.h \
+  ../include/inn/timer.h tls.h
 perl.o: perl.c ../include/config.h ../include/inn/defines.h \
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
   ../include/config.h ../include/inn/innconf.h ../include/inn/defines.h \
@@ -185,11 +185,11 @@
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
   ../include/config.h ../include/portable/wait.h ../include/config.h \
   ../include/conffile.h ../include/inn/network.h ../include/inn/defines.h \
-  ../include/inn/innconf.h ../include/innperl.h nnrpd.h \
   ../include/portable/socket.h ../include/portable/getaddrinfo.h \
-  ../include/portable/getnameinfo.h ../include/portable/time.h \
-  ../include/inn/qio.h ../include/inn/libinn.h ../include/inn/nntp.h \
-  ../include/inn/paths.h ../include/inn/storage.h \
+  ../include/portable/getnameinfo.h ../include/inn/innconf.h \
+  ../include/innperl.h nnrpd.h ../include/portable/socket.h \
+  ../include/portable/time.h ../include/inn/qio.h ../include/inn/libinn.h \
+  ../include/inn/nntp.h ../include/inn/paths.h ../include/inn/storage.h \
   ../include/inn/options.h ../include/inn/vector.h ../include/inn/timer.h
 post.o: post.c ../include/config.h ../include/inn/defines.h \
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
@@ -202,7 +202,8 @@
   ../include/inn/ov.h ../include/inn/storage.h ../include/inn/history.h \
   post.h
 python.o: python.c ../include/config.h ../include/inn/defines.h \
-  ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
+  ../include/inn/system.h ../include/inn/options.h \
+  ../include/clibrary.h \
   ../include/config.h ../include/inn/innconf.h ../include/inn/defines.h \
   nnrpd.h ../include/portable/socket.h ../include/config.h \
   ../include/portable/getaddrinfo.h ../include/portable/getnameinfo.h \

Modified: nnrpd/nnrpd.c
===================================================================
--- nnrpd/nnrpd.c	2011-08-16 14:33:18 UTC (rev 9344)
+++ nnrpd/nnrpd.c	2011-08-18 13:38:03 UTC (rev 9345)
@@ -845,7 +845,8 @@
     char		**av;
     int			ac;
     READTYPE		r;
-    int			i;
+    int                 i;
+    unsigned int        j;
     char                **v;
     char		*Reject;
     int			timeout;
@@ -857,7 +858,8 @@
     char                *ListenAddr6 = NULL;
     int			*lfds;
     fd_set              lfdset, lfdsetread;
-    int                 lfdcount, lfdreadcount;
+    unsigned int        lfdcount;
+    int                 lfdreadcount;
     bool                lfdokay;
     int                 lfdmax = 0;
     int                 fd = -1;
@@ -1011,8 +1013,8 @@
 
         /* Bail if we couldn't listen on any sockets. */
         lfdokay = false;
-        for (i = 0; i < lfdcount; i++) {
-            if (lfds[i] < 0)
+        for (j = 0; j < lfdcount; j++) {
+            if (lfds[j] < 0)
                 continue;
             lfdokay = true;
         }
@@ -1058,17 +1060,17 @@
         /* Initialize the listener file descriptors set. */
         FD_ZERO(&lfdset);
 
-        for (i = 0; i < lfdcount; i++) {
-            if (listen(lfds[i], 128) < 0) {
-                if (i != 0 && errno == EADDRINUSE)
+        for (j = 0; j < lfdcount; j++) {
+            if (listen(lfds[j], 128) < 0) {
+                if (j != 0 && errno == EADDRINUSE)
                     continue;
                 syslog(L_ERROR, "can't listen to socket");
             } else {
                 /* Remember the largest descriptor number
                  * that is to be tested by select(). */
-                FD_SET(lfds[i], &lfdset);
-                if (lfdmax < lfds[i])
-                    lfdmax = lfds[i];
+                FD_SET(lfds[j], &lfdset);
+                if (lfdmax < lfds[j])
+                    lfdmax = lfds[j];
             }
         }
 
@@ -1089,9 +1091,9 @@
                                                   NULL, NULL, NULL);
 
                             if (lfdreadcount > 0) {
-                                for (i = 0; i < lfdcount; i++) {
-                                    if (FD_ISSET(lfds[i], &lfdsetread)) {
-                                        fd = accept(lfds[i], NULL, NULL);
+                                for (j = 0; j < lfdcount; j++) {
+                                    if (FD_ISSET(lfds[j], &lfdsetread)) {
+                                        fd = accept(lfds[j], NULL, NULL);
                                         /* Only handle the first match.  Future
                                          * calls to select() will handle possible
                                          * other matches. */
@@ -1124,9 +1126,9 @@
                 lfdreadcount = select(lfdmax + 1, &lfdsetread, NULL, NULL, NULL);
 
                 if (lfdreadcount > 0) {
-                    for (i = 0; i < lfdcount; i++) {
-                        if (FD_ISSET(lfds[i], &lfdsetread)) {
-                            fd = accept(lfds[i], NULL, NULL);
+                    for (j = 0; j < lfdcount; j++) {
+                        if (FD_ISSET(lfds[j], &lfdsetread)) {
+                            fd = accept(lfds[j], NULL, NULL);
                             /* Only handle the first match.  Future calls
                              * to select() will handle possible other matches. */
                             if (fd >= 0)
@@ -1136,9 +1138,9 @@
                 }
 		if (fd < 0)
 		    continue;
-	    
-		for (i = 0; i <= (long) innconf->maxforks && (pid = fork()) < 0; i++) {
-		    if (i == (long) innconf->maxforks) {
+
+		for (j = 0; j <= innconf->maxforks && (pid = fork()) < 0; j++) {
+		    if (j == innconf->maxforks) {
 			syslog(L_FATAL, "can't fork (dropping connection): %m");
 			continue;
 		    }
@@ -1157,8 +1159,8 @@
 
 	/* Child process starts here. */
 	setproctitle("connected");
-        for (i = 0; i < lfdcount; i++) {
-            close(lfds[i]);
+        for (j = 0; j < lfdcount; j++) {
+            close(lfds[j]);
         }
 	dup2(fd, 0);
 	close(fd);

Modified: tests/lib/network-t.c
===================================================================
--- tests/lib/network-t.c	2011-08-16 14:33:18 UTC (rev 9344)
+++ tests/lib/network-t.c	2011-08-18 13:38:03 UTC (rev 9345)
@@ -1,6 +1,37 @@
-/* $Id$ */
-/* network test suite. */
+/*
+ * network test suite.
+ *
+ * $Id$
+ *
+ * The canonical version of this file is maintained in the rra-c-util package,
+ * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ *
+ * Written by Russ Allbery <rra at stanford.edu>
+ * Copyright 2005 Russ Allbery <rra at stanford.edu>
+ * Copyright 2009, 2010, 2011
+ *     The Board of Trustees of the Leland Stanford Junior University
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
 
+#define LIBTEST_NEW_FORMAT 1
+
 #include "config.h"
 #include "clibrary.h"
 #include "portable/socket.h"
@@ -14,46 +45,89 @@
 #include "inn/libinn.h"
 #include "libtest.h"
 
-/* The server portion of the test.  Listens to a socket and accepts a
-   connection, making sure what is printed on that connection matches what the
-   client is supposed to print. */
-static int
-listener(int fd, int n)
+/* Set this globally to 0 if IPv6 is available but doesn't work. */
+static int ipv6 = 1;
+
+/*
+ * The core of the listener.  Takes the return value of accept and handles our
+ * test protocol.
+ */
+static void
+listener_handler(socket_type client)
 {
-    int client;
     FILE *out;
     char buffer[512];
 
-    client = accept(fd, NULL, NULL);
-    close(fd);
-    if (client < 0) {
-        syswarn("cannot accept connection from socket");
-        ok_block(n, 2, false);
-        return n + 2;
+    if (client == INVALID_SOCKET) {
+        sysdiag("cannot accept connection from socket");
+        ok_block(2, 0, "...socket read test");
+        return;
     }
-    ok(n++, true);
+    ok(1, "...socket accept");
     out = fdopen(client, "r");
     if (fgets(buffer, sizeof(buffer), out) == NULL) {
-        syswarn("cannot read from socket");
-        ok(n++, false);
-        return n;
+        sysdiag("cannot read from socket");
+        ok(0, "...socket read");
     }
-    ok_string(n++, "socket test\r\n", buffer);
+    is_string("socket test\r\n", buffer, "...socket read");
     fclose(out);
-    return n;
 }
 
-/* Connect to the given host on port 11119 and send a constant string to a
-   socket, used to do the client side of the testing.  Takes the source
-   address as well to pass into network_connect_host. */
+
+/*
+ * The server portion of the test.  Listens to a socket and accepts a
+ * connection, making sure what is printed on that connection matches what the
+ * client is supposed to print.
+ */
 static void
+listener(socket_type fd)
+{
+    socket_type client;
+
+    client = accept(fd, NULL, NULL);
+    listener_handler(client);
+    close(fd);
+}
+
+
+/*
+ * A varient version of the server portion of the test.  Takes an array of
+ * sockets and the size of the sockets and accepts a connection on any of
+ * those sockets.
+ */
+static void
+listener_any(socket_type fds[], unsigned int count)
+{
+    socket_type client;
+    unsigned int i;
+    struct sockaddr_storage ss;
+    socklen_t sslen;
+
+    sslen = sizeof(ss);
+    client = network_accept_any(fds, count, (struct sockaddr *) &ss, &sslen);
+    listener_handler(client);
+    is_int(AF_INET, ss.ss_family, "...address family is IPv4");
+    is_int(htonl(INADDR_LOOPBACK),
+           ((struct sockaddr_in *) &ss)->sin_addr.s_addr,
+           "...and client address is 127.0.0.1");
+    for (i = 0; i < count; i++)
+        close(fds[i]);
+}
+
+
+/*
+ * Connect to the given host on port 11119 and send a constant string to a
+ * socket, used to do the client side of the testing.  Takes the source
+ * address as well to pass into network_connect_host.
+ */
+static void
 client(const char *host, const char *source)
 {
-    int fd;
+    socket_type fd;
     FILE *out;
 
     fd = network_connect_host(host, 11119, source);
-    if (fd < 0)
+    if (fd == INVALID_SOCKET)
         sysdie("connect failed");
     out = fdopen(fd, "w");
     if (out == NULL)
@@ -63,168 +137,203 @@
     _exit(0);
 }
 
-/* Bring up a server on port 11119 on the loopback address and test connecting
-   to it via IPv4.  Takes an optional source address to use for client
-   connections. */
-static int
-test_ipv4(int n, const char *source)
+
+/*
+ * Bring up a server on port 11119 on the loopback address and test connecting
+ * to it via IPv4.  Takes an optional source address to use for client
+ * connections.
+ */
+static void
+test_ipv4(const char *source)
 {
-    int fd;
+    socket_type fd;
     pid_t child;
 
     fd = network_bind_ipv4("127.0.0.1", 11119);
-    if (fd < 0)
-        sysdie("cannot create or bind socket");
+    if (fd == INVALID_SOCKET)
+        sysbail("cannot create or bind socket");
     if (listen(fd, 1) < 0) {
-        syswarn("cannot listen to socket");
-        ok(n++, false);
-        ok(n++, false);
-        ok(n++, false);
+        sysdiag("cannot listen to socket");
+        ok_block(3, 0, "IPv4 server test");
     } else {
-        ok(n++, true);
+        ok(1, "IPv4 server test");
         child = fork();
         if (child < 0)
-            sysdie("cannot fork");
-        else if (child == 0)
+            sysbail("cannot fork");
+        else if (child == 0) {
+            close(fd);
             client("127.0.0.1", source);
-        else {
-            n = listener(fd, n);
+        } else {
+            listener(fd);
             waitpid(child, NULL, 0);
         }
     }
-    return n;
 }
 
-/* Bring up a server on port 11119 on the loopback address and test connecting
-   to it via IPv6.  Takes an optional source address to use for client
-   connections. */
+
+/*
+ * Bring up a server on port 11119 on the loopback address and test connecting
+ * to it via IPv6.  Takes an optional source address to use for client
+ * connections.
+ */
 #ifdef HAVE_INET6
-static int
-test_ipv6(int n, const char *source)
+static void
+test_ipv6(const char *source)
 {
-    int fd;
+    socket_type fd;
     pid_t child;
 
     fd = network_bind_ipv6("::1", 11119);
-    if (fd < 0) {
-        if (errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT) {
-            skip_block(n, 3, "IPv6 not supported");
-            return n + 3;
+    if (fd == INVALID_SOCKET) {
+        if (errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT
+            || errno == EADDRNOTAVAIL) {
+            ipv6 = 0;
+            skip_block(3, "IPv6 not supported");
+            return;
         } else
-            sysdie("cannot create socket");
+            sysbail("cannot create socket");
     }
     if (listen(fd, 1) < 0) {
-        syswarn("cannot listen to socket");
-        ok_block(n, 3, false);
-        n += 3;
+        sysdiag("cannot listen to socket");
+        ok_block(3, 0, "IPv6 server test");
     } else {
-        ok(n++, true);
+        ok(1, "IPv6 server test");
         child = fork();
         if (child < 0)
-            sysdie("cannot fork");
-        else if (child == 0)
+            sysbail("cannot fork");
+        else if (child == 0) {
+            close(fd);
             client("::1", source);
-        else {
-            n = listener(fd, n);
+        } else {
+            listener(fd);
             waitpid(child, NULL, 0);
         }
     }
-    return n;
 }
 #else /* !HAVE_INET6 */
-static int
-test_ipv6(int n, const char *source UNUSED)
+static void
+test_ipv6(const char *source UNUSED)
 {
-    skip_block(n, 3, "IPv6 not supported");
-    return n + 3;
+    skip_block(3, "IPv6 not supported");
 }
 #endif /* !HAVE_INET6 */
 
-/* Bring up a server on port 11119 on all addresses and try connecting to it
-   via all of the available protocols.  Takes an optional source address to
-   use for client connections. */
-static int
-test_all(int n, const char *source_ipv4, const char *source_ipv6)
+
+/*
+ * Bring up a server on port 11119 on all addresses and try connecting to it
+ * via all of the available protocols.  Takes an optional source address to
+ * use for client connections.
+ */
+static void
+test_all(const char *source_ipv4, const char *source_ipv6 UNUSED)
 {
-    int *fds, count, fd, i;
+    socket_type *fds, fd;
+    unsigned int count, i;
     pid_t child;
     struct sockaddr_storage saddr;
     socklen_t size = sizeof(saddr);
 
     network_bind_all(11119, &fds, &count);
     if (count == 0)
-        sysdie("cannot create or bind socket");
+        sysbail("cannot create or bind socket");
     if (count > 2) {
-        warn("got more than two sockets, using just the first two");
+        diag("got more than two sockets, using just the first two");
         count = 2;
     }
     for (i = 0; i < count; i++) {
         fd = fds[i];
         if (listen(fd, 1) < 0) {
-            syswarn("cannot listen to socket %d", fd);
-            ok_block(n, 3, false);
-            n += 3;
+            sysdiag("cannot listen to socket %d", fd);
+            ok_block(3, 0, "all address server test");
         } else {
-            ok(n++, true);
+            ok(1, "all address server test (part %d)", i);
             child = fork();
             if (child < 0)
-                sysdie("cannot fork");
+                sysbail("cannot fork");
             else if (child == 0) {
                 if (getsockname(fd, (struct sockaddr *) &saddr, &size) < 0)
-                    sysdie("cannot getsockname");
+                    sysbail("cannot getsockname");
                 if (saddr.ss_family == AF_INET)
                     client("127.0.0.1", source_ipv4);
+#ifdef HAVE_INET6
                 else if (saddr.ss_family == AF_INET6)
                     client("::1", source_ipv6);
-                else {
-                    warn("unknown socket family %d", saddr.ss_family);
-                    skip_block(n, 2, "unknown socket family");
-                    n += 2;
-                }
+#endif
+                else
+                    skip_block(2, "unknown socket family %d", saddr.ss_family);
                 size = sizeof(saddr);
             } else {
-                n = listener(fd, n);
+                listener(fd);
                 waitpid(child, NULL, 0);
             }
         }
     }
-    if (count == 1) {
-        skip_block(n, 3, "only one listening socket");
-        n += 3;
+    if (count == 1)
+        skip_block(3, "only one listening socket");
+}
+
+
+/*
+ * Bring up a server on port 11119 on all addresses and try connecting to it
+ * via 127.0.0.1, using network_accept_any underneath.
+ */
+static void
+test_any(void)
+{
+    socket_type *fds;
+    unsigned int count, i;
+    pid_t child;
+
+    network_bind_all(11119, &fds, &count);
+    if (count == 0)
+        sysbail("cannot create or bind socket");
+    for (i = 0; i < count; i++)
+        if (listen(fds[i], 1) < 0) {
+            sysdiag("cannot listen to socket %d", fds[i]);
+            ok_block(2, 0, "accept any server test");
+        }
+    child = fork();
+    if (child < 0)
+        sysbail("cannot fork");
+    else if (child == 0)
+        client("127.0.0.1", NULL);
+    else {
+        listener_any(fds, count);
+        waitpid(child, NULL, 0);
     }
-    return n;
 }
 
-/* Bring up a server on port 11119 on the loopback address and test connecting
-   to it via IPv4 using network_connect_sockaddr.  Takes an optional source
-   address to use for client connections. */
-static int
-test_create_ipv4(int n, const char *source)
+
+/*
+ * Bring up a server on port 11119 on the loopback address and test connecting
+ * to it via IPv4 using network_client_create.  Takes an optional source
+ * address to use for client connections.
+ */
+static void
+test_create_ipv4(const char *source)
 {
-    int fd;
+    socket_type fd;
     pid_t child;
 
     fd = network_bind_ipv4("127.0.0.1", 11119);
-    if (fd < 0)
-        sysdie("cannot create or bind socket");
+    if (fd == INVALID_SOCKET)
+        sysbail("cannot create or bind socket");
     if (listen(fd, 1) < 0) {
-        syswarn("cannot listen to socket");
-        ok(n++, false);
-        ok(n++, false);
-        ok(n++, false);
+        sysdiag("cannot listen to socket");
+        ok_block(3, 0, "IPv4 network client");
     } else {
-        ok(n++, true);
+        ok(1, "IPv4 network client");
         child = fork();
         if (child < 0)
-            sysdie("cannot fork");
+            sysbail("cannot fork");
         else if (child == 0) {
             struct sockaddr_in sin;
             FILE *out;
 
             fd = network_client_create(PF_INET, SOCK_STREAM, source);
-            if (fd < 0)
+            if (fd == INVALID_SOCKET)
                 _exit(1);
-            memset(&sin, 0, sizeof sin);
+            memset(&sin, 0, sizeof(sin));
             sin.sin_family = AF_INET;
             sin.sin_port = htons(11119);
             sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
@@ -237,28 +346,31 @@
             fclose(out);
             _exit(0);
         } else {
-            n = listener(fd, n);
+            listener(fd);
             waitpid(child, NULL, 0);
         }
     }
-    return n;
 }
 
-/* Tests network_addr_compare.  Takes the test number, the expected result,
-   the two addresses, and the mask. */
+
+/*
+ * Tests network_addr_compare.  Takes the expected result, the two addresses,
+ * and the mask.
+ */
 static void
-ok_addr(int n, bool expected, const char *a, const char *b, const char *mask)
+ok_addr(int expected, const char *a, const char *b, const char *mask)
 {
     if (expected)
-        ok(n, network_addr_match(a, b, mask));
+        ok(network_addr_match(a, b, mask), "compare %s %s %s", a, b, mask);
     else
-        ok(n, !network_addr_match(a, b, mask));
+        ok(!network_addr_match(a, b, mask), "compare %s %s %s", a, b, mask);
 }
 
+
 int
 main(void)
 {
-    int n, status;
+    int status;
     struct addrinfo *ai, *ai4;
     struct addrinfo hints;
     char addr[INET6_ADDRSTRLEN];
@@ -270,140 +382,179 @@
     static const char *ipv6_addr = "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210";
 #endif
 
-    test_init(117);
+    plan(121);
 
-    n = test_ipv4(1, NULL);                     /* Tests  1-3.  */
-    n = test_ipv6(n, NULL);                     /* Tests  4-6.  */
-    n = test_all(n, NULL, NULL);                /* Tests  7-12. */
-    n = test_create_ipv4(n, NULL);              /* Tests 13-15. */
+    /*
+     * If IPv6 support appears to be available but doesn't work, we have to
+     * skip the test_all tests since they'll create a socket that we then
+     * can't connect to.  This is the case on Solaris 8 without IPv6
+     * configured.
+     */
+    test_ipv4(NULL);
+    test_ipv6(NULL);
+    if (ipv6)
+        test_all(NULL, NULL);
+    else
+        skip_block(6, "IPv6 not configured");
+    test_create_ipv4(NULL);
 
     /* This won't make a difference for loopback connections. */
-    n = test_ipv4(n, "127.0.0.1");              /* Tests 16-18. */
-    n = test_ipv6(n, "::1");                    /* Tests 19-21. */
-    n = test_all(n, "127.0.0.1", "::1");        /* Tests 22-27. */
-    n = test_create_ipv4(n, "127.0.0.1");       /* Tests 28-30. */
+    test_ipv4("127.0.0.1");
+    test_ipv6("::1");
+    if (ipv6)
+        test_all("127.0.0.1", "::1");
+    else
+        skip_block(6, "IPv6 not configured");
+    test_create_ipv4("127.0.0.1");
 
     /* We need an initialized innconf struct, but it doesn't need to contain
-       anything interesting. */
+     * anything interesting. */
     innconf = xcalloc(1, sizeof(struct innconf));
 
     /* This should be equivalent to the previous tests. */
     innconf->sourceaddress = xstrdup("all");
     innconf->sourceaddress6 = xstrdup("all");
-    n = test_ipv4(n, NULL);                     /* Tests 31-33. */
-    n = test_ipv6(n, NULL);                     /* Tests 34-36. */
-    n = test_all(n, NULL, NULL);                /* Tests 37-42. */
-    n = test_create_ipv4(n, NULL);              /* Tests 43-45. */
 
+    test_ipv4(NULL);
+    test_ipv6(NULL);
+    if (ipv6)
+        test_all(NULL, NULL);
+    else
+        skip_block(6, "IPv6 not configured");
+    test_create_ipv4(NULL);
+                            
     /* This won't make a difference for loopback connections. */
     free(innconf->sourceaddress);
     free(innconf->sourceaddress6);
     innconf->sourceaddress = xstrdup("127.0.0.1");
     innconf->sourceaddress6 = xstrdup("::1");
-    n = test_ipv4(n, NULL);                     /* Tests 46-48. */
-    n = test_ipv6(n, NULL);                     /* Tests 49-51. */
-    n = test_all(n, NULL, NULL);                /* Tests 52-57. */
-    n = test_create_ipv4(n, NULL);              /* Tests 58-60. */
+    test_ipv4(NULL);
+    test_ipv6(NULL);
+    if (ipv6)
+        test_all(NULL, NULL);
+    else
+        skip_block(6, "IPv6 not configured");
+    test_create_ipv4(NULL);
 
-    /* Now, test network_sockaddr_sprint, network_sockaddr_equal, and
-       network_sockaddr_port. */
+    /* Test network_accept_any. */
+    test_any();
+
+    /*
+     * Now, test network_sockaddr_sprint, network_sockaddr_equal, and
+     * network_sockaddr_port.
+     */
     memset(&hints, 0, sizeof(hints));
     hints.ai_flags = AI_NUMERICHOST;
     hints.ai_socktype = SOCK_STREAM;
     status = getaddrinfo("127.0.0.1", port, &hints, &ai4);
     if (status != 0)
-        die("getaddrinfo on 127.0.0.1 failed: %s", gai_strerror(status));
-    ok(61, network_sockaddr_sprint(addr, sizeof(addr), ai4->ai_addr));
-    ok_string(62, "127.0.0.1", addr);
-    ok_int(63, 119, network_sockaddr_port(ai4->ai_addr));
-    ok(64, network_sockaddr_equal(ai4->ai_addr, ai4->ai_addr));
+        bail("getaddrinfo on 127.0.0.1 failed: %s", gai_strerror(status));
+    ok(network_sockaddr_sprint(addr, sizeof(addr), ai4->ai_addr),
+       "sprint of 127.0.0.1");
+    is_string("127.0.0.1", addr, "...with right results");
+    is_int(119, network_sockaddr_port(ai4->ai_addr),
+           "sockaddr_port");
+    ok(network_sockaddr_equal(ai4->ai_addr, ai4->ai_addr), "sockaddr_equal");
     status = getaddrinfo("127.0.0.2", NULL, &hints, &ai);
     if (status != 0)
-        die("getaddrinfo on 127.0.0.2 failed: %s", gai_strerror(status));
-    ok(65, !network_sockaddr_equal(ai->ai_addr, ai4->ai_addr));
-    ok(66, !network_sockaddr_equal(ai4->ai_addr, ai->ai_addr));
+        bail("getaddrinfo on 127.0.0.2 failed: %s", gai_strerror(status));
+    ok(!network_sockaddr_equal(ai->ai_addr, ai4->ai_addr),
+       "sockaddr_equal of unequal addresses");
+    ok(!network_sockaddr_equal(ai4->ai_addr, ai->ai_addr),
+       "...and the other way around");
 
     /* The same for IPv6. */
 #ifdef HAVE_INET6
     status = getaddrinfo(ipv6_addr, port, &hints, &ai6);
     if (status != 0)
-        sysdie("getaddr on %s failed", ipv6_addr);
-    ok(67, network_sockaddr_sprint(addr, sizeof(addr), ai6->ai_addr));
+        bail("getaddr on %s failed: %s", ipv6_addr, gai_strerror(status));
+    ok(network_sockaddr_sprint(addr, sizeof(addr), ai6->ai_addr),
+       "sprint of IPv6 address");
     for (p = addr; *p != '\0'; p++)
         if (islower((unsigned char) *p))
             *p = toupper((unsigned char) *p);
-    ok_string(68, ipv6_addr, addr);
-    ok_int(69, 119, network_sockaddr_port(ai6->ai_addr));
-    ok(70, network_sockaddr_equal(ai6->ai_addr, ai6->ai_addr));
-    ok(71, !network_sockaddr_equal(ai4->ai_addr, ai6->ai_addr));
-    ok(72, !network_sockaddr_equal(ai6->ai_addr, ai4->ai_addr));
+    is_string(ipv6_addr, addr, "...with right results");
+    is_int(119, network_sockaddr_port(ai6->ai_addr), "sockaddr_port IPv6");
+    ok(network_sockaddr_equal(ai6->ai_addr, ai6->ai_addr),
+       "sockaddr_equal IPv6");
+    ok(!network_sockaddr_equal(ai4->ai_addr, ai6->ai_addr),
+       "...and not equal to IPv4");
+    ok(!network_sockaddr_equal(ai6->ai_addr, ai4->ai_addr),
+       "...other way around");
 
     /* Test IPv4 mapped addresses. */
     status = getaddrinfo("::ffff:7f00:1", NULL, &hints, &ai6);
     if (status != 0)
-        sysdie("getaddr on ::ffff:7f00:1 failed");
-    ok(73, network_sockaddr_sprint(addr, sizeof(addr), ai6->ai_addr));
-    ok_string(74, "127.0.0.1", addr);
-    ok(75, network_sockaddr_equal(ai4->ai_addr, ai6->ai_addr));
-    ok(76, network_sockaddr_equal(ai6->ai_addr, ai4->ai_addr));
-    ok(77, !network_sockaddr_equal(ai->ai_addr, ai6->ai_addr));
-    ok(78, !network_sockaddr_equal(ai6->ai_addr, ai->ai_addr));
+        bail("getaddr on ::ffff:7f00:1 failed: %s", gai_strerror(status));
+    ok(network_sockaddr_sprint(addr, sizeof(addr), ai6->ai_addr),
+       "sprint of IPv4-mapped address");
+    is_string("127.0.0.1", addr, "...with right IPv4 result");
+    ok(network_sockaddr_equal(ai4->ai_addr, ai6->ai_addr),
+       "sockaddr_equal of IPv4-mapped address");
+    ok(network_sockaddr_equal(ai6->ai_addr, ai4->ai_addr),
+       "...and other way around");
+    ok(!network_sockaddr_equal(ai->ai_addr, ai6->ai_addr),
+       "...but not some other address");
+    ok(!network_sockaddr_equal(ai6->ai_addr, ai->ai_addr),
+       "...and the other way around");
     freeaddrinfo(ai6);
 #else
-    skip_block(67, 12, "IPv6 not supported");
+    skip_block(12, "IPv6 not supported");
 #endif
 
     /* Check the domains of functions and their error handling. */
     ai4->ai_addr->sa_family = AF_UNIX;
-    ok(79, !network_sockaddr_equal(ai4->ai_addr, ai4->ai_addr));
-    ok_int(80, 0, network_sockaddr_port(ai4->ai_addr));
+    ok(!network_sockaddr_equal(ai4->ai_addr, ai4->ai_addr),
+       "equal not equal with address mismatches");
+    is_int(0, network_sockaddr_port(ai4->ai_addr),
+           "port meaningless for AF_UNIX");
 
     /* Tests for network_addr_compare. */
-    ok_addr( 81, true,  "127.0.0.1", "127.0.0.1",   NULL);
-    ok_addr( 82, false, "127.0.0.1", "127.0.0.2",   NULL);
-    ok_addr( 83, true,  "127.0.0.1", "127.0.0.0",   "31");
-    ok_addr( 84, false, "127.0.0.1", "127.0.0.0",   "32");
-    ok_addr( 85, false, "127.0.0.1", "127.0.0.0",   "255.255.255.255");
-    ok_addr( 86, true,  "127.0.0.1", "127.0.0.0",   "255.255.255.254");
-    ok_addr( 87, true,  "10.10.4.5", "10.10.4.255", "24");
-    ok_addr( 88, false, "10.10.4.5", "10.10.4.255", "25");
-    ok_addr( 89, true,  "10.10.4.5", "10.10.4.255", "255.255.255.0");
-    ok_addr( 90, false, "10.10.4.5", "10.10.4.255", "255.255.255.128");
-    ok_addr( 91, false, "129.0.0.0", "1.0.0.0",     "1");
-    ok_addr( 92, true,  "129.0.0.0", "1.0.0.0",     "0");
-    ok_addr( 93, true,  "129.0.0.0", "1.0.0.0",     "0.0.0.0");
+    ok_addr(1, "127.0.0.1", "127.0.0.1",   NULL);
+    ok_addr(0, "127.0.0.1", "127.0.0.2",   NULL);
+    ok_addr(1, "127.0.0.1", "127.0.0.0",   "31");
+    ok_addr(0, "127.0.0.1", "127.0.0.0",   "32");
+    ok_addr(0, "127.0.0.1", "127.0.0.0",   "255.255.255.255");
+    ok_addr(1, "127.0.0.1", "127.0.0.0",   "255.255.255.254");
+    ok_addr(1, "10.10.4.5", "10.10.4.255", "24");
+    ok_addr(0, "10.10.4.5", "10.10.4.255", "25");
+    ok_addr(1, "10.10.4.5", "10.10.4.255", "255.255.255.0");
+    ok_addr(0, "10.10.4.5", "10.10.4.255", "255.255.255.128");
+    ok_addr(0, "129.0.0.0", "1.0.0.0",     "1");
+    ok_addr(1, "129.0.0.0", "1.0.0.0",     "0");
+    ok_addr(1, "129.0.0.0", "1.0.0.0",     "0.0.0.0");
 
     /* Try some IPv6 addresses. */
 #ifdef HAVE_INET6
-    ok_addr( 94, true,  ipv6_addr,   ipv6_addr,     NULL);
-    ok_addr( 95, true,  ipv6_addr,   ipv6_addr,     "128");
-    ok_addr( 96, true,  ipv6_addr,   ipv6_addr,     "60");
-    ok_addr( 97, true,  "::127",     "0:0::127",    "128");
-    ok_addr( 98, true,  "::127",     "0:0::128",    "120");
-    ok_addr( 99, false, "::127",     "0:0::128",    "128");
-    ok_addr(100, false, "::7fff",    "0:0::8000",   "113");
-    ok_addr(101, true,  "::7fff",    "0:0::8000",   "112");
-    ok_addr(102, false, "::3:ffff",  "::2:ffff",    "120");
-    ok_addr(103, false, "::3:ffff",  "::2:ffff",    "119");
-    ok_addr(104, false, "ffff::1",   "7fff::1",     "1");
-    ok_addr(105, true,  "ffff::1",   "7fff::1",     "0");
-    ok_addr(106, false, "fffg::1",   "fffg::1",     NULL);
-    ok_addr(107, false, "ffff::1",   "7fff::1",     "-1");
-    ok_addr(108, false, "ffff::1",   "ffff::1",     "-1");
-    ok_addr(109, false, "ffff::1",   "ffff::1",     "129");
+    ok_addr(1, ipv6_addr,   ipv6_addr,     NULL);
+    ok_addr(1, ipv6_addr,   ipv6_addr,     "128");
+    ok_addr(1, ipv6_addr,   ipv6_addr,     "60");
+    ok_addr(1, "::127",     "0:0::127",    "128");
+    ok_addr(1, "::127",     "0:0::128",    "120");
+    ok_addr(0, "::127",     "0:0::128",    "128");
+    ok_addr(0, "::7fff",    "0:0::8000",   "113");
+    ok_addr(1, "::7fff",    "0:0::8000",   "112");
+    ok_addr(0, "::3:ffff",  "::2:ffff",    "120");
+    ok_addr(0, "::3:ffff",  "::2:ffff",    "119");
+    ok_addr(0, "ffff::1",   "7fff::1",     "1");
+    ok_addr(1, "ffff::1",   "7fff::1",     "0");
+    ok_addr(0, "fffg::1",   "fffg::1",     NULL);
+    ok_addr(0, "ffff::1",   "7fff::1",     "-1");
+    ok_addr(0, "ffff::1",   "ffff::1",     "-1");
+    ok_addr(0, "ffff::1",   "ffff::1",     "129");
 #else
-    skip_block(94, 16, "IPv6 not supported");
+    skip_block(16, "IPv6 not supported");
 #endif
 
     /* Test some invalid addresses. */
-    ok_addr(110, false, "fred",      "fred",        NULL);
-    ok_addr(111, false, "",          "",            NULL);
-    ok_addr(112, false, "",          "",            "0");
-    ok_addr(113, false, "127.0.0.1", "127.0.0.1",   "pete");
-    ok_addr(114, false, "127.0.0.1", "127.0.0.1",   "1p");
-    ok_addr(115, false, "127.0.0.1", "127.0.0.1",   "1p");
-    ok_addr(116, false, "127.0.0.1", "127.0.0.1",   "-1");
-    ok_addr(117, false, "127.0.0.1", "127.0.0.1",   "33");
+    ok_addr(0, "fred",      "fred",        NULL);
+    ok_addr(0, "",          "",            NULL);
+    ok_addr(0, "",          "",            "0");
+    ok_addr(0, "127.0.0.1", "127.0.0.1",   "pete");
+    ok_addr(0, "127.0.0.1", "127.0.0.1",   "1p");
+    ok_addr(0, "127.0.0.1", "127.0.0.1",   "1p");
+    ok_addr(0, "127.0.0.1", "127.0.0.1",   "-1");
+    ok_addr(0, "127.0.0.1", "127.0.0.1",   "33");
 
     return 0;
 }




More information about the inn-committers mailing list