--- embedaddon/mtr/dns.c 2013/07/21 23:43:41 1.1.1.1 +++ embedaddon/mtr/dns.c 2016/11/01 09:33:48 1.1.1.2 @@ -22,7 +22,8 @@ Released under GPL, as above. */ -#include +#include "config.h" + #include #include #include @@ -56,10 +57,8 @@ #ifdef ENABLE_IPV6 #ifdef __GLIBC__ -#define NSCOUNT6 myres._u._ext.nscount6 #define NSSOCKADDR6(i) (myres._u._ext.nsaddrs[i]) #else -#define NSCOUNT6 myres.nscount #define NSSOCKADDR6(i) (&(myres._u._ext.ext->nsaddrs[i].sin6)) #endif #endif @@ -529,10 +528,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 +544,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 ); @@ -932,19 +935,19 @@ 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)); - } -#endif for (i = 0;i < myres.nscount;i++) if (myres.nsaddr_list[i].sin_family == AF_INET) (void)sendto(resfd,buf,r,0,(struct sockaddr *)&myres.nsaddr_list[i], sizeof(struct sockaddr)); +#ifdef ENABLE_IPV6 + else if (resfd6 > 0) { + 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 } void resendrequest(struct resolve *rp,int type) @@ -1327,13 +1330,16 @@ 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) { /* Check to see if this server is actually one we sent to */ if ( addrcmp( (void *) &(from6->sin6_addr), (void *) &localhost6, (int) AF_INET6 ) == 0 ) { - for (i = 0;i < NSCOUNT6;i++) { + for (i = 0;i < myres.nscount;i++) { if (!NSSOCKADDR6(i)) continue; @@ -1344,14 +1350,14 @@ void dns_ack6(void) break; } } else - for (i = 0;i < NSCOUNT6;i++) { + for (i = 0;i < myres.nscount;i++) { if (!NSSOCKADDR6(i)) continue; if ( addrcmp( (void *) &(NSSOCKADDR6(i)->sin6_addr), (void *) &(from6->sin6_addr), AF_INET6 ) == 0 ) break; } - if (i == NSCOUNT6) { + if (i == myres.nscount) { snprintf(tempstring, sizeof(tempstring), "Resolver error: Received reply from unknown source: %s", inet_ntop( AF_INET6, &(from6->sin6_addr), addrstr,