|
Packit Service |
b38f0b |
/*
|
|
Packit Service |
b38f0b |
* HEADER Testing netsnmp_gethostbyaddr()
|
|
Packit Service |
b38f0b |
*/
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
SOCK_STARTUP;
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
{
|
|
Packit Service |
b38f0b |
int ran_test = 0;
|
|
Packit Service |
b38f0b |
#ifdef HAVE_GETHOSTBYADDR
|
|
Packit Service |
b38f0b |
struct hostent *h, *h2 = NULL;
|
|
Packit Service |
b38f0b |
struct in_addr v4loop;
|
|
Packit Service |
b38f0b |
struct sockaddr_in sin_addr;
|
|
Packit Service |
b38f0b |
int s;
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
v4loop.s_addr = htonl(INADDR_LOOPBACK);
|
|
Packit Service |
b38f0b |
memset(&sin_addr, 0, sizeof(sin_addr));
|
|
Packit Service |
b38f0b |
sin_addr.sin_family = AF_INET;
|
|
Packit Service |
b38f0b |
sin_addr.sin_addr = v4loop;
|
|
Packit Service |
b38f0b |
s = socket(AF_INET, SOCK_DGRAM, 0);
|
|
Packit Service |
b38f0b |
if (s >= 0) {
|
|
Packit Service |
b38f0b |
if (bind(s, (struct sockaddr *) &sin_addr, sizeof(sin_addr)) >= 0) {
|
|
Packit Service |
b38f0b |
h = netsnmp_gethostbyaddr(&v4loop, sizeof(v4loop), AF_INET);
|
|
Packit Service |
b38f0b |
if (h)
|
|
Packit Service |
b38f0b |
h2 = gethostbyname(h->h_name);
|
|
Packit Service |
b38f0b |
OKF(h && (strcmp(h->h_name, "localhost") == 0 ||
|
|
Packit Service |
b38f0b |
(h2 && memcmp(h2->h_addr, &v4loop.s_addr,
|
|
Packit Service |
b38f0b |
sizeof(v4loop.s_addr)) == 0)),
|
|
Packit Service |
b38f0b |
("127.0.0.1 lookup (%s -> %s)", h ? h->h_name : "(failed)",
|
|
Packit Service |
b38f0b |
h2 ? inet_ntoa(*(struct in_addr *) h2->
|
|
Packit Service |
b38f0b |
h_addr) : "(failed)"));
|
|
Packit Service |
b38f0b |
ran_test = 1;
|
|
Packit Service |
b38f0b |
}
|
|
Packit Service |
b38f0b |
close(s);
|
|
Packit Service |
b38f0b |
}
|
|
Packit Service |
b38f0b |
#endif
|
|
Packit Service |
b38f0b |
if (!ran_test)
|
|
Packit Service |
b38f0b |
OKF(1, ("Skipped IPv4 test"));
|
|
Packit Service |
b38f0b |
}
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
{
|
|
Packit Service |
b38f0b |
struct hostent *h;
|
|
Packit Service |
b38f0b |
#ifdef cygwin
|
|
Packit Service |
b38f0b |
static const struct in6_addr v6loop = { { IN6ADDR_LOOPBACK_INIT } };
|
|
Packit Service |
b38f0b |
#else
|
|
Packit Service |
b38f0b |
static const struct in6_addr v6loop = IN6ADDR_LOOPBACK_INIT;
|
|
Packit Service |
b38f0b |
#endif
|
|
Packit Service |
b38f0b |
struct sockaddr_in6 sin6_addr;
|
|
Packit Service |
b38f0b |
struct addrinfo hints, *addr = NULL, *ap;
|
|
Packit Service |
b38f0b |
char buf[64];
|
|
Packit Service |
b38f0b |
int s, res, ran_test = 0;
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
memset(&sin6_addr, 0, sizeof(sin6_addr));
|
|
Packit Service |
b38f0b |
sin6_addr.sin6_family = AF_INET6;
|
|
Packit Service |
b38f0b |
sin6_addr.sin6_addr = v6loop;
|
|
Packit Service |
b38f0b |
s = socket(AF_INET6, SOCK_DGRAM, 0);
|
|
Packit Service |
b38f0b |
if (s >= 0) {
|
|
Packit Service |
b38f0b |
if (bind(s, (struct sockaddr *) &sin6_addr, sizeof(sin6_addr)) >=
|
|
Packit Service |
b38f0b |
0) {
|
|
Packit Service |
b38f0b |
addr = NULL;
|
|
Packit Service |
b38f0b |
strcpy(buf, "(failed)");
|
|
Packit Service |
b38f0b |
h = netsnmp_gethostbyaddr(&v6loop, sizeof(v6loop), AF_INET6);
|
|
Packit Service |
b38f0b |
if (h) {
|
|
Packit Service |
b38f0b |
memset(&hints, 0, sizeof(hints));
|
|
Packit Service |
b38f0b |
hints.ai_family = AF_INET6;
|
|
Packit Service |
b38f0b |
res = getaddrinfo(h->h_name, NULL, &hints, &addr);
|
|
Packit Service |
b38f0b |
if (res == 0) {
|
|
Packit Service |
b38f0b |
for (ap = addr; ap; ap = ap->ai_next) {
|
|
Packit Service |
b38f0b |
if (ap->ai_family == AF_INET6) {
|
|
Packit Service |
b38f0b |
inet_ntop(ap->ai_family,
|
|
Packit Service |
b38f0b |
&((struct sockaddr_in6 *) ap->
|
|
Packit Service |
b38f0b |
ai_addr)->sin6_addr, buf,
|
|
Packit Service |
b38f0b |
sizeof(buf));
|
|
Packit Service |
b38f0b |
break;
|
|
Packit Service |
b38f0b |
}
|
|
Packit Service |
b38f0b |
}
|
|
Packit Service |
b38f0b |
if (!ap)
|
|
Packit Service |
b38f0b |
strcpy(buf, "no AF_INET6 address found");
|
|
Packit Service |
b38f0b |
} else {
|
|
Packit Service |
b38f0b |
snprintf(buf, sizeof(buf), "getaddrinfo() failed: %s",
|
|
Packit Service |
b38f0b |
strerror(errno));
|
|
Packit Service |
b38f0b |
}
|
|
Packit Service |
b38f0b |
}
|
|
Packit Service |
b38f0b |
OKF(h && (strcmp(h->h_name, "localhost") == 0 ||
|
|
Packit Service |
b38f0b |
(res == 0 && addr && memcmp(addr->ai_addr, &sin6_addr,
|
|
Packit Service |
b38f0b |
sizeof(sin6_addr)) == 0)),
|
|
Packit Service |
b38f0b |
("::1 lookup (%s -> %s)", h ? h->h_name : "(failed)",
|
|
Packit Service |
b38f0b |
buf));
|
|
Packit Service |
b38f0b |
if (addr)
|
|
Packit Service |
b38f0b |
freeaddrinfo(addr);
|
|
Packit Service |
b38f0b |
ran_test = 1;
|
|
Packit Service |
b38f0b |
}
|
|
Packit Service |
b38f0b |
close(s);
|
|
Packit Service |
b38f0b |
}
|
|
Packit Service |
b38f0b |
if (!ran_test)
|
|
Packit Service |
b38f0b |
OKF(1, ("Skipped IPv6 test"));
|
|
Packit Service |
b38f0b |
}
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
SOCK_CLEANUP;
|