version 1.1.1.2, 2021/03/17 00:07:30
|
version 1.1.1.3, 2023/09/27 11:18:58
|
Line 3
|
Line 3
|
Copyright (C) 1997,1998 Matt Kimball |
Copyright (C) 1997,1998 Matt Kimball |
|
|
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
it under the terms of the GNU General Public License version 2 as | it under the terms of the GNU General Public License version 2 as |
published by the Free Software Foundation. |
published by the Free Software Foundation. |
|
|
This program is distributed in the hope that it will be useful, |
This program is distributed in the hope that it will be useful, |
Line 52 struct dns_results {
|
Line 52 struct dns_results {
|
static struct dns_results *results; |
static struct dns_results *results; |
|
|
char *strlongip( |
char *strlongip( |
struct mtr_ctl *ctl, | sa_family_t family, |
ip_t * ip) |
ip_t * ip) |
{ |
{ |
#ifdef ENABLE_IPV6 |
#ifdef ENABLE_IPV6 |
static char addrstr[INET6_ADDRSTRLEN]; |
static char addrstr[INET6_ADDRSTRLEN]; |
|
|
return (char *) inet_ntop(ctl->af, ip, addrstr, sizeof addrstr); | return (char *) inet_ntop(family, ip, addrstr, sizeof addrstr); |
#else |
#else |
return inet_ntoa(*ip); |
return inet_ntoa(*ip); |
#endif |
#endif |
Line 87 static int longipstr(
|
Line 87 static int longipstr(
|
} |
} |
|
|
|
|
struct hostent *dns_forward( |
|
const char *name) |
|
{ |
|
struct hostent *host; |
|
|
|
if ((host = gethostbyname(name))) |
|
return host; |
|
else |
|
return NULL; |
|
} |
|
|
|
|
|
static struct dns_results *findip( |
static struct dns_results *findip( |
struct mtr_ctl *ctl, |
struct mtr_ctl *ctl, |
ip_t * ip) |
ip_t * ip) |
Line 114 static struct dns_results *findip(
|
Line 102 static struct dns_results *findip(
|
} |
} |
|
|
static void set_sockaddr_ip( |
static void set_sockaddr_ip( |
struct mtr_ctl *ctl, | sa_family_t family, |
struct sockaddr_storage *sa, |
struct sockaddr_storage *sa, |
ip_t * ip) |
ip_t * ip) |
{ |
{ |
memset(sa, 0, sizeof(struct sockaddr_storage)); |
memset(sa, 0, sizeof(struct sockaddr_storage)); |
sa->ss_family = ctl->af; | sa->ss_family = family; |
memcpy(sockaddr_addr_offset(sa), ip, sockaddr_addr_size(sa)); |
memcpy(sockaddr_addr_offset(sa), ip, sockaddr_addr_size(sa)); |
} |
} |
|
|
void dns_open( |
void dns_open( |
struct mtr_ctl *ctl) | void) |
{ |
{ |
int pid; |
int pid; |
|
|
Line 173 void dns_open(
|
Line 161 void dns_open(
|
|
|
buf[strlen(buf) - 1] = 0; /* chomp newline. */ |
buf[strlen(buf) - 1] = 0; /* chomp newline. */ |
|
|
longipstr(buf, &host, ctl->af); | sa_family_t family = (buf[0] == '4') ? AF_INET : AF_INET6; |
set_sockaddr_ip(ctl, &sa, &host); | longipstr(buf +1, &host, family); |
salen = (ctl->af == AF_INET) ? sizeof(struct sockaddr_in) : | set_sockaddr_ip(family, &sa, &host); |
| salen = (family == AF_INET) ? sizeof(struct sockaddr_in) : |
sizeof(struct sockaddr_in6); |
sizeof(struct sockaddr_in6); |
|
|
rv = getnameinfo((struct sockaddr *) &sa, salen, |
rv = getnameinfo((struct sockaddr *) &sa, salen, |
hostname, sizeof(hostname), NULL, 0, 0); |
hostname, sizeof(hostname), NULL, 0, 0); |
if (rv == 0) { |
if (rv == 0) { |
snprintf(result, sizeof(result), |
snprintf(result, sizeof(result), |
"%s %s\n", strlongip(ctl, &host), hostname); | "%s %s\n", strlongip(family, &host), hostname); |
|
|
rv = write(fromdns[1], result, strlen(result)); |
rv = write(fromdns[1], result, strlen(result)); |
if (rv < 0) |
if (rv < 0) |
Line 256 char *dns_lookup2(
|
Line 245 char *dns_lookup2(
|
ip_t * ip) |
ip_t * ip) |
{ |
{ |
struct dns_results *r; |
struct dns_results *r; |
char buf[INET6_ADDRSTRLEN + 1]; | char buf[INET6_ADDRSTRLEN + 2]; // af_byte + addr + null |
int rv; |
int rv; |
|
|
r = findip(ctl, ip); |
r = findip(ctl, ip); |
Line 270 char *dns_lookup2(
|
Line 259 char *dns_lookup2(
|
r->name = NULL; |
r->name = NULL; |
r->next = results; |
r->next = results; |
results = r; |
results = r; |
snprintf(buf, sizeof(buf), "%s\n", strlongip(ctl, ip)); | char ip4or6 = (ctl->af == AF_INET) ? '4' : '6'; |
| snprintf(buf, sizeof(buf), "%c%s\n", ip4or6, strlongip(ctl->af, ip)); |
rv = write(todns[1], buf, strlen(buf)); |
rv = write(todns[1], buf, strlen(buf)); |
if (rv < 0) |
if (rv < 0) |
error(0, errno, "couldn't write to resolver process"); |
error(0, errno, "couldn't write to resolver process"); |
Line 288 char *dns_lookup(
|
Line 278 char *dns_lookup(
|
if (!ctl->dns || !ctl->use_dns) |
if (!ctl->dns || !ctl->use_dns) |
return NULL; |
return NULL; |
t = dns_lookup2(ctl, ip); |
t = dns_lookup2(ctl, ip); |
return t ? t : strlongip(ctl, ip); | return t ? t : strlongip(ctl->af, ip); |
} |
} |
|
|
/* XXX check if necessary/exported. */ |
/* XXX check if necessary/exported. */ |