]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
Fix bombout with ipv6 enabled binary on ipv4 only system.
authorRoger Wolff <R.E.Wolff@BitWizard.nl>
Tue, 16 Jul 2013 11:59:52 +0000 (13:59 +0200)
committerRoger Wolff <R.E.Wolff@BitWizard.nl>
Tue, 16 Jul 2013 11:59:52 +0000 (13:59 +0200)
dns.c
gtk.c
select.c

diff --git a/dns.c b/dns.c
index 371934ffbec220a8510fbc0f161f43a113711755..221665d278bab7895eb61790db689178f1bd0df9 100644 (file)
--- a/dns.c
+++ b/dns.c
@@ -529,10 +529,12 @@ void dns_open(void)
 #ifdef ENABLE_IPV6
   resfd6 = socket(AF_INET6, SOCK_DGRAM, 0);
   if (resfd6 == -1) {
+    // consider making removing this warning. For now leave it in to see 
+    // new code activated. -- REW
     fprintf(stderr,
             "Unable to allocate IPv6 socket for nameserver communication: %s\n",
            strerror(errno));
-    exit(-1);
+    //    exit(-1);
   }
 #endif
   option = 1;
@@ -543,11 +545,13 @@ void dns_open(void)
     exit(-1);
   }
 #ifdef ENABLE_IPV6
-  if (setsockopt(resfd6,SOL_SOCKET,SO_BROADCAST,(char *)&option,sizeof(option))) {
-    fprintf(stderr,
-            "Unable to setsockopt() on IPv6 nameserver communication socket: %s\n",
-           strerror(errno));
-    exit(-1);
+  if (resfd6 > 0) {
+    if (setsockopt(resfd6,SOL_SOCKET,SO_BROADCAST,(char *)&option,sizeof(option))) {
+      fprintf(stderr,
+             "Unable to setsockopt() on IPv6 nameserver communication socket: %s\n",
+             strerror(errno));
+      exit(-1);
+    }
   }
 #endif
   longipstr( "127.0.0.1", &localhost, AF_INET );
@@ -933,12 +937,14 @@ void dorequest(char *s,int type,word id)
   hp = (packetheader *)buf;
   hp->id = id; /* htons() deliberately left out (redundant) */
 #ifdef ENABLE_IPV6
-  for (i = 0;i < NSCOUNT6;i++) {
-    if (!NSSOCKADDR6(i))
-      continue;
-    if (NSSOCKADDR6(i)->sin6_family == AF_INET6)
-      (void)sendto(resfd6,buf,r,0,(struct sockaddr *) NSSOCKADDR6(i),
-                  sizeof(struct sockaddr_in6));
+  if (resfd6 > 0) {
+    for (i = 0;i < NSCOUNT6;i++) {
+      if (!NSSOCKADDR6(i))
+       continue;
+      if (NSSOCKADDR6(i)->sin6_family == AF_INET6)
+       (void)sendto(resfd6,buf,r,0,(struct sockaddr *) NSSOCKADDR6(i),
+                    sizeof(struct sockaddr_in6));
+    }
   }
 #endif
   for (i = 0;i < myres.nscount;i++)
@@ -1327,6 +1333,9 @@ void dns_ack6(void)
   int r,i;
   static char addrstr[INET6_ADDRSTRLEN];
 
+  // Probably not necessary. -- REW
+  if (resfd6 < 0) return; 
+
   r = recvfrom(resfd6,(byte *)resrecvbuf,MaxPacketsize,0,
                from, &fromlen);
   if (r > 0) {
diff --git a/gtk.c b/gtk.c
index d00f769d0b70505834e2044dcaedf9273532cf6d..38ed507ceeaf742f0faf2f80a6e45cfe03a62bb3 100644 (file)
--- a/gtk.c
+++ b/gtk.c
@@ -615,8 +615,10 @@ void gtk_loop(void)
   net_iochannel = g_io_channel_unix_new(net_waitfd());
   g_io_add_watch(net_iochannel, G_IO_IN, gtk_net_data, NULL);
 #ifdef ENABLE_IPV6
-  dns_iochannel = g_io_channel_unix_new(dns_waitfd6());
-  g_io_add_watch(dns_iochannel, G_IO_IN, gtk_dns_data6, NULL);
+  if (dns_waitfd6() > 0) {
+    dns_iochannel = g_io_channel_unix_new(dns_waitfd6());
+    g_io_add_watch(dns_iochannel, G_IO_IN, gtk_dns_data6, NULL);
+  }
 #endif
   dns_iochannel = g_io_channel_unix_new(dns_waitfd());
   g_io_add_watch(dns_iochannel, G_IO_IN, gtk_dns_data, NULL);
index 0545d9f736d012c11e6018708a6fc6eb8e8f66b9..e7c397e95255c714fd95f981174fa6a78aea04b9 100644 (file)
--- a/select.c
+++ b/select.c
@@ -80,8 +80,12 @@ void select_loop(void) {
 #ifdef ENABLE_IPV6
     if (dns) {
       dnsfd6 = dns_waitfd6();
-      FD_SET(dnsfd6, &readfd);
-      if(dnsfd6 >= maxfd) maxfd = dnsfd6 + 1;
+      if (dnsfd6 >= 0) {
+        FD_SET(dnsfd6, &readfd);
+        if(dnsfd6 >= maxfd) maxfd = dnsfd6 + 1;
+      } else {
+        dnsfd6 = 0;
+      }
     } else
       dnsfd6 = 0;
 #endif