Page MenuHomeFreeBSD

ping6: make lookup of symbolic names in the reply default
AbandonedPublic

Authored by jansucan on Aug 20 2019, 12:26 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Oct 28, 3:56 PM
Unknown Object (File)
Mon, Oct 28, 3:56 PM
Unknown Object (File)
Mon, Oct 28, 3:55 PM
Unknown Object (File)
Mon, Oct 28, 3:38 PM
Unknown Object (File)
Oct 8 2024, 3:46 PM
Unknown Object (File)
Oct 8 2024, 2:44 PM
Unknown Object (File)
Sep 30 2024, 3:23 PM
Unknown Object (File)
Sep 30 2024, 8:46 AM
Subscribers
None

Details

Reviewers
asomers
Summary

Make lookup of symbolic names in the reply default

The -H option has been removed. It was setting F_HOSTNAME flag and the-n option was clearing it. The default value of the flag was 0 so the -n option was effective only when it was used with -H option.

Making lookup of symbolic names in the reply to be default, -n option can be used to set the flag for numeric output only. Thus, -H option is no longer necessary.

This unifies the behavior with ping and will simplify unification of option parsing.

Submitted by: Ján Sučan <sucanjan@gmail.com>
Sponsored by: Google LLC (Google Summer of Code 2019)

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 25980
Build 24535: arc lint + arc unit

Event Timeline

Remove 'H' from the getopt() option string.

ping doesn't do reverse lookup. So doesn't this change actually increase the differences between the utilities? I think a better change would be to implement -H for ping.

I'm not sure if I understand you correctly.

This is ping's use of F_NUMERIC flag in pr_addr():

	if (options & F_NUMERIC)
		return inet_ntoa(ina);

	hp = cap_gethostbyaddr(capdns, (char *)&ina, 4, AF_INET);

	if (hp == NULL)
		return inet_ntoa(ina);

	(void)snprintf(buf, sizeof(buf), "%s (%s)", hp->h_name,
	    inet_ntoa(ina));
	return(buf);

and this is ping6's use of F_HOSTNAME in pr_addr():

	if ((options & F_HOSTNAME) == 0)
		flag |= NI_NUMERICHOST;

	if (cap_getnameinfo(capdns, addr, addrlen, buf, sizeof(buf), NULL, 0,
		flag) == 0)
		return (buf);
	else
		return "?";
In D21338#464272, @sucanjan_gmail.com wrote:

I'm not sure if I understand you correctly.

This is ping's use of F_NUMERIC flag in pr_addr():

	if (options & F_NUMERIC)
		return inet_ntoa(ina);

	hp = cap_gethostbyaddr(capdns, (char *)&ina, 4, AF_INET);

	if (hp == NULL)
		return inet_ntoa(ina);

	(void)snprintf(buf, sizeof(buf), "%s (%s)", hp->h_name,
	    inet_ntoa(ina));
	return(buf);

and this is ping6's use of F_HOSTNAME in pr_addr():

	if ((options & F_HOSTNAME) == 0)
		flag |= NI_NUMERICHOST;

	if (cap_getnameinfo(capdns, addr, addrlen, buf, sizeof(buf), NULL, 0,
		flag) == 0)
		return (buf);
	else
		return "?";

Yeah, but ping and ping6 use pr_addr for different things. ping hardly uses it at all. In fact, I can't come up with a single invocation that works and does the reverse lookup. ping6, however, uses reverse lookup more liberally. The main IP address of concern, the target's, isn't looked up during a normal ping. Compare these commands:

[asomers@universe13a ~/freebsd/base/head]$ ping -c1 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=55 time=1.560 ms

--- 8.8.8.8 ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 1.560/1.560/1.560/0.000 ms
[asomers@universe13a ~/freebsd/base/head]$ ping6 -c1 -H 2600::
PING6(56=40+8+8 bytes) universe13a.freebsd.org --> www.sprint.net
16 bytes from www.sprint.net, icmp_seq=0 hlim=51 time=27.506 ms

--- 2600:: ping6 statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/std-dev = 27.506/27.506/27.506/0.000 ms

Only ping6 did a reverse lookup.

I suppose I should've said "make ping use pr_addr when it prints the "bytes from" on line 1170", rather than "implement -H" for ping.

I suppose I should've said "make ping use pr_addr when it prints the "bytes from" on line 1170", rather than "implement -H" for ping.

It's done in D21351. Together with this diff, ping and ping6 should behave equally when printing out replies. Numeric output only can be requested by '-n'.

I would recommend leaving -H in. Even though it's the default, defaults change. Script authors don't like to rely on defaults; they like to specify exactly the behavior that they want.

OK. I will keep -H in ping6 and add it to ping. It will be default in both of them.

D21356 adds -H option to ping . Eventually I decided to keep the default behavior in ping and ping6.

The default behavior has been unified in D21364. This revision is no longer needed and can be abandoned.