Netdev List
 help / color / mirror / Atom feed
* [iputils] - patch for ping to set un.echo.id to network byte order
@ 2009-09-01  5:05 Jamie Le Tual
  0 siblings, 0 replies; only message in thread
From: Jamie Le Tual @ 2009-09-01  5:05 UTC (permalink / raw)
  To: nedev

I noticed in the ping source code that the identity flag on the icmp
echo packet is set to the pid of the ping command being run. I
immediatly fired up a packet sniffer to see it, but got endian
wierdness. Looking back at the code, and comparing with ping6 and
traceroute6, I noticed that when the identity is set, its fed the
value of getpid() without running it through htons(), as is done in
traceroute6.

So this patch for the ipv4 version of ping:

diff -pu iputils-s20071127/ping_common.c iputils-jamie/ping_common.c
--- iputils-s20071127/ping_common.c	2007-11-26 19:57:27.000000000 -0500
+++ iputils-jamie/ping_common.c	2009-09-01 00:10:58.000000000 -0400
@@ -473,7 +473,7 @@ void setup(int icmp_sock)
 			*p++ = i;
 	}

-	ident = getpid() & 0xFFFF;
+	ident = htons(getpid() & 0xFFFF);

 	set_signal(SIGINT, sigexit);
 	set_signal(SIGALRM, sigexit);



seems obvious enough. I figured that htons was safe enough, since
pid_t is just an int.

Is there some reason to not send the identifier properly so it doesn't
end up bass-ackwards on the receiving end?

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-09-01  5:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-01  5:05 [iputils] - patch for ping to set un.echo.id to network byte order Jamie Le Tual

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox