INN commit: branches/2.4/nnrpd (nnrpd.c)

INN Commit Russ_Allbery at isc.org
Sat Oct 25 17:06:15 UTC 2008


    Date: Saturday, October 25, 2008 @ 10:06:15
  Author: iulius
Revision: 8144

Fix two bugs when "nnrpd -D" is used:
 * ListenAddress was not initialized (to ::0 or 0.0.0.0) when
   the -b flag was not used;
 * an incorrect size was given to bind() when IPv6 was enabled
   and the binding done using IPv4.

Thanks to Johan van Selst for having identified the problem and
Kai Gallasch for having provided a FreeBSD server to test my patch.

Modified:
  branches/2.4/nnrpd/nnrpd.c

---------+
 nnrpd.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Modified: nnrpd.c
===================================================================
--- nnrpd.c	2008-10-07 17:09:47 UTC (rev 8143)
+++ nnrpd.c	2008-10-25 17:06:15 UTC (rev 8144)
@@ -804,9 +804,9 @@
     struct		timeval tv;
     unsigned short	ListenPort = NNTP_PORT;
 #ifdef HAVE_INET6
-    char		ListenAddr[INET6_ADDRSTRLEN];
+    char		ListenAddr[INET6_ADDRSTRLEN] = "::0";
 #else
-    char		ListenAddr[16];
+    char		ListenAddr[16] = "0.0.0.0";
 #endif
     int			lfd, fd;
     socklen_t		clen;
@@ -948,11 +948,14 @@
     SPOOLlen = strlen(innconf->patharticles);
 
     if (DaemonMode) {
+        bool ipv4binding = true;
+
 #ifdef HAVE_INET6
 	memset(&ssa, '\0', sizeof(struct sockaddr_in6));
 	ssa6->sin6_family = AF_INET6;
 	ssa6->sin6_port   = htons(ListenPort);
 	if (inet_pton(AF_INET6, ListenAddr, ssa6->sin6_addr.s6_addr) > 0) {
+            ipv4binding = false;
 	    if ( (lfd = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
 		syslog(L_FATAL, "can't open socket (%m)");
 		exit(1);
@@ -979,7 +982,9 @@
 	    exit(1);
 	}
 
-	if (bind(lfd, (struct sockaddr *) &ssa, sizeof(ssa)) < 0) {
+        if (bind(lfd, (struct sockaddr *) &ssa,
+                 ipv4binding ? sizeof(struct sockaddr_in)
+                             : sizeof(struct sockaddr_storage)) < 0) {
 	    fprintf(stderr, "%s: can't bind (%s)\n", argv[0], strerror(errno));
 	    syslog(L_FATAL, "can't bind local address (%m)");
 	    exit(1);



More information about the inn-committers mailing list