* Added contrib/fping.spec (Stephen Schaefer, #24)
* Convert man-page source to POD for easier maintenance
* Fix error message on DNS error for IPv6 hosts (#27)
+ * Fix -n flag in fping6 (#28)
* Man-page fix: TOS option typo (Thomas Liske, #23)
* Man-page fix: inconsistency in regards to numeric arguments (Robert Henney)
* Man-page fix: better description of option -q (#15)
}/* WHILE */
}/* ELSE */
#else
- FPING_SOCKADDR dst;
- struct addrinfo *res, hints;
- int ret_ga;
- char *hostname;
- size_t len;
+ FPING_SOCKADDR dst;
+ struct addrinfo *res, hints;
+ int ret_ga;
+ size_t len;
+ char *printname;
+ char namebuf[256];
+ char addrbuf[256];
/* getaddrinfo */
bzero(&hints, sizeof(struct addrinfo));
- hints.ai_flags = name_flag ? AI_CANONNAME : 0;
+ hints.ai_flags = 0;
hints.ai_family = AF_INET6;
hints.ai_socktype = SOCK_RAW;
hints.ai_protocol = IPPROTO_ICMPV6;
-
ret_ga = getaddrinfo(name, NULL, &hints, &res);
if (ret_ga) {
if(!quiet_flag)
num_noaddress++;
return;
}
- if (res->ai_canonname) hostname = res->ai_canonname;
- else hostname = name;
- if (!res->ai_addr) {
- if(!quiet_flag)
- print_warning("%s: getaddrinfo failed\n", name);
- num_noaddress++;
- return;
- }
len = res->ai_addrlen;
if (len > sizeof(FPING_SOCKADDR)) len = sizeof(FPING_SOCKADDR);
(void)memcpy(&dst, res->ai_addr, len);
- /* numerical addresses requested */
+ /* name_flag: addr -> name lookup requested) */
+ if(!name_flag) {
+ printname = name;
+ }
+ else {
+ int ret;
+ ret = getnameinfo(res->ai_addr, res->ai_addrlen, namebuf,
+ sizeof(namebuf)/sizeof(char), NULL, 0, 0);
+ if (ret) {
+ if(!quiet_flag) {
+ print_warning("%s: %s\n", name, gai_strerror(ret_ga));
+ }
+ num_noaddress++;
+ return;
+ }
+ printname = namebuf;
+ }
+
+ /* addr_flag: name -> addr lookup requested */
if(addr_flag) {
- char addrbuf[64];
int ret;
ret = getnameinfo(res->ai_addr, res->ai_addrlen, addrbuf,
- 64, NULL, 0, NI_NUMERICHOST);
+ sizeof(addrbuf)/sizeof(char), NULL, 0, NI_NUMERICHOST);
if (ret) {
if(!quiet_flag) {
print_warning("%s: %s\n", name, gai_strerror(ret_ga));
num_noaddress++;
return;
}
+
if(name_flag) {
- char nameaddrbuf[256];
- snprintf(nameaddrbuf, 256, "%s (%s)", name, addrbuf);
+ char nameaddrbuf[512];
+ snprintf(nameaddrbuf, sizeof(nameaddrbuf)/sizeof(char), "%s (%s)", printname, addrbuf);
add_addr(name, nameaddrbuf, &dst);
}
else {
}
}
else {
- add_addr(name, name, &dst);
+ add_addr(name, printname, &dst);
}
#endif
} /* add_name() */