iputils/iputils-ss021109-ping6_getaddrinfo.patch

77 lines
2.1 KiB
Diff

--- ping6.c 2006-11-15 17:05:29.000000000 +0900
+++ ping6.c 2006-11-22 18:50:58.000000000 +0900
@@ -196,6 +196,7 @@ int main(int argc, char *argv[])
int socket_errno;
struct icmp6_filter filter;
int err, csum_offset, sz_opt;
+ struct addrinfo hints, *res0;
icmp_sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
socket_errno = errno;
@@ -211,6 +212,11 @@ int main(int argc, char *argv[])
memset(&firsthop, 0, sizeof(firsthop));
firsthop.sin6_family = AF_INET6;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET6;
+ hints.ai_socktype = SOCK_RAW;
+ hints.ai_protocol = IPPROTO_ICMPV6;
+
preload = 1;
while ((ch = getopt(argc, argv, COMMON_OPTSTR "F:")) != EOF) {
switch(ch) {
@@ -291,16 +297,20 @@ int main(int argc, char *argv[])
}
if (inet_pton(AF_INET6, target, &addr) <= 0) {
- struct hostent *hp;
-
- hp = gethostbyname2(target, AF_INET6);
-
- if (hp == NULL) {
+ err = getaddrinfo(target, NULL, &hints, &res0);
+ if (err) {
fprintf(stderr, "unknown host %s\n", target);
exit(2);
}
+ if (res0->ai_addrlen > sizeof(struct sockaddr_in6)) {
+ fprintf(stderr, "address length is too long\n");
+ exit(2);
+ }
- memcpy(&addr, hp->h_addr_list[0], 16);
+ addr=((struct sockaddr_in6 *)res0->ai_addr)->sin6_addr;
+ if (ipv6_addr_any(&firsthop.sin6_addr))
+ memcpy(&firsthop, res0->ai_addr, res0->ai_addrlen);
+ freeaddrinfo(res0);
}
inet6_srcrt_add(srcrt, &addr);
@@ -328,16 +338,20 @@ int main(int argc, char *argv[])
}
if (inet_pton(AF_INET6, target, &whereto.sin6_addr) <= 0) {
- struct hostent *hp;
-
- hp = gethostbyname2(target, AF_INET6);
-
- if (hp == NULL) {
+ err = getaddrinfo(target, NULL, &hints, &res0);
+ if (err) {
fprintf(stderr, "unknown host\n");
exit(2);
}
+ if (res0->ai_addrlen > sizeof(struct sockaddr_in6)) {
+ fprintf(stderr, "address length is too long\n");
+ exit(2);
+ }
- memcpy(&whereto.sin6_addr, hp->h_addr_list[0], 16);
+ memcpy(&whereto, res0->ai_addr, res0->ai_addrlen);
+ if (ipv6_addr_any(&firsthop.sin6_addr))
+ memcpy(&firsthop, res0->ai_addr, res0->ai_addrlen);
+ freeaddrinfo(res0);
} else {
options |= F_NUMERIC;
}