From: Roger Wolff Date: Sun, 17 Aug 2014 14:30:57 +0000 (+0200) Subject: moved towards IPV6 compatibilty... X-Git-Tag: v0.88~43^2~7^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34fda04e2008118de05c87a4ea3b589bc5e45b31;p=thirdparty%2Fmtr.git moved towards IPV6 compatibilty... --- diff --git a/dns.c b/dns.c index f126b24..3159d3b 100644 --- a/dns.c +++ b/dns.c @@ -116,6 +116,23 @@ struct dns_results *findip (ip_t *ip) return NULL; } +void set_sockaddr_ip (struct sockaddr *sa, ip_t *ip) +{ + struct sockaddr_in *sa_in; + struct sockaddr_in6 *sa_in6; + + sa->sa_family = af; + switch (af) { + case AF_INET: + sa_in = (struct sockaddr_in *) sa; + addrcpy ((void *) &sa_in->sin_addr, (void*) ip, af); + break; + case AF_INET6: + sa_in6 = (struct sockaddr_in6 *) sa; + addrcpy ((void *) &sa_in6->sin6_addr, (void*)ip, af); + break; + } +} static int todns[2], fromdns[2]; @@ -150,45 +167,54 @@ void dns_open(void) if (pid == 0) { char buf[1024]; int i; - FILE *infp, *outfp; - - // The child: We're going to handle the DNS requests here. - close (todns[1]); // close the pipe ends we don't need. - close (fromdns[0]); + FILE *infp; //, *outfp; + // Automatically reap children. if (signal(SIGCHLD, SIG_IGN) == SIG_ERR) { perror("signal"); exit(1); } +#if 0 + // No longer necessary: we close all of them below. + // The child: We're going to handle the DNS requests here. + close (todns[1]); // close the pipe ends we don't need. + close (fromdns[0]); +#endif // Close all unneccessary FDs. + // for debugging and error reporting, keep std-in/out/err. for (i=3;i %s\n", strlongip (&host), hostname); + + sprintf (result, "%s %s\n", strlongip (&host), hostname); + + printf ("resolved: %s -> %s (%d)\n", strlongip (&host), hostname, rv); + write (fromdns[1], result, strlen (result)); exit (0); }