how to get the same display as a ping command ? #4

Open
benoitc opened this Issue May 19, 2012 · 2 comments

Comments

Projects
None yet
2 participants

benoitc commented May 19, 2012

Hi, Any idea how I could return something like :

$ ping friendpaste.com
PING friendpaste.com (94.23.221.113): 56 data bytes
64 bytes from 94.23.221.113: icmp_seq=0 ttl=54 time=36.183 ms
64 bytes from 94.23.221.113: icmp_seq=1 ttl=54 time=321.526 ms

ie, how can I get the ttl ? and packet size (for the last one I guess the payload lenght is OK) .

Owner

msantos commented May 19, 2012

On Sat, May 19, 2012 at 02:11:41AM -0700, Benoit Chesneau wrote:

Hi, Any idea how I could return something like :

$ ping friendpaste.com
PING friendpaste.com (94.23.221.113): 56 data bytes
64 bytes from 94.23.221.113: icmp_seq=0 ttl=54 time=36.183 ms
64 bytes from 94.23.221.113: icmp_seq=1 ttl=54 time=321.526 ms

ie, how can I get the ttl ? and packet size (for the last one I guess the payload lenght is OK) .

I checked the source for BSD ping. For the packet size, it is printing
out the size of the packet with the ICMP header removed (by default,
64-8). If you calculate the length from the packet contents that are
returned to you, it won't be exactly as in your example:

1> gen_icmp:ping("google.com").
[{ok,"google.com",
 {74,125,226,0},
 {{3275,0,382786},
  <<" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJK">>}}]
2> byte_size(<<"!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJK">>).
44

The packet is 64 bytes = 8 bytes (ICMP header) + 12 bytes timestamp (3 *
sizeof(u_int32_t), the result from erlang:now()) + 44 bytes payload.

As for ttl, gen_icmp only sees the ICMP header and payload. The TTL
is in the IP header so, at the moment, there is no way to retrieve it.
You could get a value for the TTL by using tracert.

Owner

msantos commented May 31, 2012

I was wrong about the TTL. The inet driver returns the whole IPv4 packet so gen_icmp can get the value. But for IPv6, only the ICMPv6 + payload is returned. Haven't decided what to do here yet (gen_icmp could do the socket handling itself, like tracert), so leaving this issue open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment