Subject: bin/3876: ping fails to convert net byte order to host byte order when displaying some values
To: None <gnats-bugs@gnats.netbsd.org>
From: Dave Huang <khym@bga.com>
List: netbsd-bugs
Date: 07/17/1997 00:26:28
>Number:         3876
>Category:       bin
>Synopsis:       ping fails to convert net byte order to host byte order when displaying some values
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 16 22:35:00 1997
>Last-Modified:
>Originator:     Dave Huang
>Organization:
Name: Dave Huang     |   Mammal, mammal / their names are called /
INet: khym@bga.com   |   they raise a paw / the bat, the cat /
FurryMUCK: Dahan     |   dolphin and dog / koala bear and hog -- TMBG
Dahan: Hani G Y+C 21 Y++ L+++ W- C++ T++ A+ E+ S++ V++ F- Q+++ P+ B+ PA+ PL++
>Release:        NetBSD-current as of July 16, 1997
>Environment:
	
System: NetBSD dahan.metonymy.com 1.2G NetBSD 1.2G (SPIFF) #63: Tue Jul 15 19:30:39 CDT 1997 khym@dahan.metonymy.com:/usr/src.local/sys/arch/i386/compile/SPIFF i386


>Description:
When ping receives a packet other than ICMP Echo Reply in response to
its Echo Request, it prints the error along with the echo request's
sequence number. However, it fails to convert it from network byte
order to host byte order before printing it out, so on a little-endian
machine (i386, in this case), you get something like:

PING 10.1.1.1 (10.1.1.1): 56 data bytes
36 bytes from sl-fw-13-S1/0-T1.sprintlink.net (144.228.12.1): Destination Host Unreachable for icmp_seq=0
36 bytes from sl-fw-13-S1/0-T1.sprintlink.net (144.228.12.1): Destination Host Unreachable for icmp_seq=256
36 bytes from sl-fw-13-S1/0-T1.sprintlink.net (144.228.12.1): Destination Host Unreachable for icmp_seq=512

----10.1.1.1 PING Statistics----
3 packets transmitted, 0 packets received, 100% packet loss

>How-To-Repeat:
On a little-endian machine, ping someplace that'll return a host
unreachable. Network 10 seems to do it for me...

>Fix:
This patch also does ntohs on icmp_id... it's just an arbitrary
number, so I guess it doesn't really matter, but I think it's more
"correct" this way :) On the other hand, ping sets icmp_id to it's
process id, without first doing htons, so with the unpatched ping, ID
would always be displayed as the pid of the ping process. I still
think it's nicer this way though :)

--- ping.c~	Thu Jun 26 23:42:22 1997
+++ ping.c	Wed Jul 16 23:46:30 1997
@@ -1511,11 +1511,11 @@
 		if (icp2.icmp_type == ICMP_ECHO) {
 			if (pingflags & F_VERBOSE)
 				(void)printf("\n  ID=%u icmp_seq=%u",
-					     icp2.icmp_id,
-					     icp2.icmp_seq);
+					     ntohs(icp2.icmp_id),
+					     ntohs(icp2.icmp_seq));
 			else
 				(void)printf(" for icmp_seq=%u",
-					     icp2.icmp_seq);
+					     ntohs(icp2.icmp_seq));
 		}
 	}
 }

>Audit-Trail:
>Unformatted: