version 1.1.1.2, 2021/03/17 00:07:30
|
version 1.1.1.3, 2023/09/27 11:18:58
|
Line 38
|
Line 38
|
#include <sys/limits.h> |
#include <sys/limits.h> |
#endif |
#endif |
|
|
#include <netdb.h> |
|
#include <netinet/in.h> |
#include <netinet/in.h> |
#include <sys/socket.h> |
#include <sys/socket.h> |
#include <ctype.h> |
#include <ctype.h> |
Line 63
|
Line 62
|
#include "portability/getopt.h" |
#include "portability/getopt.h" |
#endif |
#endif |
|
|
#ifdef ENABLE_IPV6 |
|
#define DEFAULT_AF AF_UNSPEC |
|
#else |
|
#define DEFAULT_AF AF_INET |
|
#endif |
|
|
|
|
|
char *myname; |
char *myname; |
|
|
const struct fields data_fields[MAXFLD] = { |
const struct fields data_fields[MAXFLD] = { |
Line 150 static void __attribute__ ((__noreturn__)) usage(FILE
|
Line 142 static void __attribute__ ((__noreturn__)) usage(FILE
|
fputs(" -w, --report-wide output wide report\n", out); |
fputs(" -w, --report-wide output wide report\n", out); |
fputs(" -c, --report-cycles COUNT set the number of pings sent\n", |
fputs(" -c, --report-cycles COUNT set the number of pings sent\n", |
out); |
out); |
|
#ifdef HAVE_JANSSON |
fputs(" -j, --json output json\n", out); |
fputs(" -j, --json output json\n", out); |
|
#endif |
fputs(" -x, --xml output xml\n", out); |
fputs(" -x, --xml output xml\n", out); |
fputs(" -C, --csv output comma separated values\n", |
fputs(" -C, --csv output comma separated values\n", |
out); |
out); |
Line 696 static void init_rand(
|
Line 690 static void init_rand(
|
srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec); |
srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec); |
} |
} |
|
|
|
|
/* |
/* |
For historical reasons, we need a hostent structure to represent |
For historical reasons, we need a hostent structure to represent |
our remote target for probing. The obsolete way of doing this |
our remote target for probing. The obsolete way of doing this |
would be to use gethostbyname(). We'll use getaddrinfo() instead |
would be to use gethostbyname(). We'll use getaddrinfo() instead |
to generate the hostent. |
to generate the hostent. |
*/ |
*/ |
static int get_hostent_from_name( | int get_addrinfo_from_name( |
struct mtr_ctl *ctl, |
struct mtr_ctl *ctl, |
struct hostent *host, | struct addrinfo **res, |
const char *name, | const char *name) |
char **alptr) | |
{ |
{ |
int gai_error; |
int gai_error; |
struct addrinfo hints, *res; | struct addrinfo hints; |
struct sockaddr_in *sa4; | |
#ifdef ENABLE_IPV6 | |
struct sockaddr_in6 *sa6; | |
#endif | |
|
|
/* gethostbyname2() is deprecated so we'll use getaddrinfo() instead. */ |
/* gethostbyname2() is deprecated so we'll use getaddrinfo() instead. */ |
memset(&hints, 0, sizeof hints); |
memset(&hints, 0, sizeof hints); |
hints.ai_family = ctl->af; |
hints.ai_family = ctl->af; |
hints.ai_socktype = SOCK_DGRAM; |
hints.ai_socktype = SOCK_DGRAM; |
gai_error = getaddrinfo(name, NULL, &hints, &res); | gai_error = getaddrinfo(name, NULL, &hints, res); |
if (gai_error) { |
if (gai_error) { |
if (gai_error == EAI_SYSTEM) |
if (gai_error == EAI_SYSTEM) |
error(0, 0, "Failed to resolve host: %s", name); |
error(0, 0, "Failed to resolve host: %s", name); |
Line 731 static int get_hostent_from_name(
|
Line 719 static int get_hostent_from_name(
|
return -1; |
return -1; |
} |
} |
|
|
/* Convert the first addrinfo into a hostent. */ | ctl->af = (*res)->ai_family; |
memset(host, 0, sizeof(struct hostent)); | |
host->h_name = res->ai_canonname; | |
host->h_aliases = NULL; | |
host->h_addrtype = res->ai_family; | |
ctl->af = res->ai_family; | |
host->h_length = res->ai_addrlen; | |
host->h_addr_list = alptr; | |
switch (ctl->af) { | |
case AF_INET: | |
sa4 = (struct sockaddr_in *) res->ai_addr; | |
alptr[0] = (void *) &(sa4->sin_addr); | |
break; | |
#ifdef ENABLE_IPV6 | |
case AF_INET6: | |
sa6 = (struct sockaddr_in6 *) res->ai_addr; | |
alptr[0] = (void *) &(sa6->sin6_addr); | |
break; | |
#endif | |
default: | |
error(0, 0, "unknown address type"); | |
| |
errno = EINVAL; | |
return -1; | |
} | |
alptr[1] = NULL; | |
| |
return 0; |
return 0; |
} |
} |
|
|
Line 766 int main(
|
Line 728 int main(
|
int argc, |
int argc, |
char **argv) |
char **argv) |
{ |
{ |
struct hostent *host = NULL; |
|
struct hostent trhost; |
|
char *alptr[2]; |
|
names_t *names_head = NULL; |
names_t *names_head = NULL; |
names_t *names_walk; |
names_t *names_walk; |
|
|
Line 837 int main(
|
Line 796 int main(
|
sizeof(ctl.LocalHostname)); |
sizeof(ctl.LocalHostname)); |
} |
} |
|
|
host = &trhost; | struct addrinfo *res = NULL; |
if (get_hostent_from_name(&ctl, host, ctl.Hostname, alptr) != 0) { | if (get_addrinfo_from_name(&ctl, &res, ctl.Hostname) != 0) { |
if (ctl.Interactive) |
if (ctl.Interactive) |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
else { |
else { |
Line 847 int main(
|
Line 806 int main(
|
} |
} |
} |
} |
|
|
if (net_open(&ctl, host) != 0) { | if (net_open(&ctl, res) != 0) { |
error(0, 0, "Unable to start net module"); |
error(0, 0, "Unable to start net module"); |
if (ctl.Interactive) |
if (ctl.Interactive) |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
Line 857 int main(
|
Line 816 int main(
|
} |
} |
} |
} |
|
|
|
freeaddrinfo(res); |
|
|
lock(stdout); |
lock(stdout); |
dns_open(&ctl); | dns_open(); |
display_open(&ctl); |
display_open(&ctl); |
|
|
display_loop(&ctl); |
display_loop(&ctl); |