Ping Command

of 6
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Similar Documents
  Submitted by: Jay K ShrotriyaAim: To implement the PING CommandTheory: Ping   is a  computer network   administration  utility  used to test the reachability of a  host  on an  InternetProtocol  (IP) network and to measure the  round-trip time  for messages sent from the srcinating host toa destination computer.Ping operates by sending  Internet Control Message Protocol  (ICMP)   echo request   packets  to thetarget host and waiting for an ICMP response. In the process it measures the time from transmission toreception (round-trip time)   and records any   packet loss . he results of the test are printed in the form of astatistical summary of the response packets recei!ed including the minimum ma#imum andthe  mean  round-trip times and sometimes the  standard de!iation  of the mean.$epending on actual implementation the ping utility may be e#ecuted with !arious command-lineswitches to enable special operational modes. %or e.g. options include specifying the packet si&e of the probe automatic repeated operation for sending a specified count of probes and time stamping.%ig' PI command in command prompt.  MESSAGE FOMAT ICMP packet IP Datagram Bits 0–7Bits 8–15Bits 16–23Bits 24–31IP Header (20 !tes Version/IHLType of serviceLengthIdentification  flags  and offset  Time To Live (TTL)ProtocolChecksumource IP address!estination IP address ICMP Header (8 !tes Type of messageCodeChecksumHeader !ata ICMP Pa!#$ad( optional  Payload !ata eneric composition of an ICMP *+-byte packet ã IP ,eader (in blue)' ã Protocol set to  (ICMP) and ype of er!ice set to /. ã ICMP ,eader (in red)' ã ype of ICMP message (0 bits) ã Code (0 bits) ã Checksum (1 bits) calculated with the ICMP part of the packet (the IP header is not used). It is the 1-bit one2s complement of the one2s complement sum of the ICMP message starting with the ype field  ã ,eader $ata (*+ bits) field which in this case (ICMP echo request and replies) will be composed of identifier (1 bits) and sequence number (1 bits). ã ICMP Payload ã Payload for the different kind of answers3 can be an arbitrary length left to implementation detail. ,owe!er the packet including IP and ICMP headers must be less than the ma#imum transmission unit of the network or risk being fragmented. ã $ata ransportation Program and Output: 4include 5fcntl.h64include 5errno.h64include 5sys7socket.h64include 5resol!.h64include 5netdb.h64include 5netinet7in.h64include 5netinet7ip8icmp.h64define P9C:;I<;1=struct packet>struct icmphdr hdr3char msg?P9C:;I<;-si&eof(struct icmphdr)@3A3int pidB-3struct protoent protoBDEE37--- checksum - standard s complement checksum ---7unsigned short checksum(!oid b int len)>unsigned short buf B b3unsigned int sumB/3unsigned short result3for ( sum B /3 len 6 3 len -B + )sum FB bufFF3if ( len BB  )sum FB (unsigned char)buf3sum B (sum 66 1) F (sum G /#%%%%)3sum FB (sum 66 1)3result B Hsum3  return result3A7--- display - present echo info ---7!oid display(!oid buf int bytes)>int i3struct iphdr ip B buf3struct icmphdr icmp B bufFip-6ihl=3 printf(----------------Jn)3 printf(Jn)3 printf(IP!Kd' hdr-si&eBKd pkt-si&eBKd protocolBKd EBKd srcBKs  ip-6!ersion ip-6ihl= ntohs(ip-6tot8len) ip-6protocol ip-6ttl inet8ntoa(ip-6saddr))3 printf(dstBKsJn inet8ntoa(ip-6daddr))3if ( BB pid )> printf(ICMP' type?Kd7Kd@ checksum?Kd@ id?Kd@ seq?Kd@Jn icmp-6type icmp-6code ntohs(icmp-6checksum) icmp-6un.echo.sequence)3AA7--- listener - separate process to listen for and collect messages--7!oid listener(!oid)>int sd3struct sockaddr8in addr3unsigned char buf?/+=@3sd B socket(P%8I; LC:89N proto-6p8proto)3if ( sd 5 / )> perror(socket)3e#it(/)3Afor (33)>int bytes lenBsi&eof(addr)3 b&ero(buf si&eof(buf))3 bytes B rec!from(sd buf si&eof(buf) / (struct sockaddr)Gaddr Glen)3if ( bytes 6 / )display(buf bytes)3else perror(rec!from)3A
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...

Sign Now!

We are very appreciated for your Prompt Action!