Bharat Banate's Work Profile

View Bharat Banate's profile on LinkedIn

Tuesday, September 18, 2007

Networking: How does Ping actually works?

Ping is a basic Internet program that most of us use daily, but did you ever stop to wonder how it really worked?

• As the ping program initializes, it opens a raw ICMP socket so that it can employ IP directly, circumventing TCP and UDP.
• Ping formats an ICMP type 8 message, an Echo Request, and sends it (using the “sendto” function) to the designated target address. The system provides the IP header and the data link layer envelope.
• As ICMP messages are received, ping has the opportunity to examine each packet to pick out those items that are of interest.
• The usual behavior is to siphon off ICMP type 0 messages, Echo Replies, which have an identification field value that matches the program PID.
• Ping uses the timestamp in the data area of the Echo Reply to calculate a round-trip time. It also reports the TTL from the IP header of the reply.
• When things do not work normally, ping may report some of the other ICMP message types that show up in the inbox. This includes things like Destination Unreachable and Time Exceeded messages.

2 comments:

Anonymous said...

Can we ping any machine on Internet?

code-squeryl said...

yes we can.. but for that you need IP address along with port number.. & there too comes concept of global & local IP address.. & I will put more focus on this concept soon with example.