Do not use on any
shared computer
August 7, 2008 04:13pm pdt
 
[x]
Attachment Details

How does a ping work?

Tags: Ping, Network, C
I am trying to write a C program to ping an IP address.  I have two functions available to me that should accomplish this task, but I don't really understand them.  

void ICMPPut(NODE_INFO *remote, ICMP_CODE code, BYTE *data, BYTE len, WORD id, WORD seq)
where:
remote is node information such as a MAC Address or IP addresses
code is ICMP code to be used for this ICMP packet (possible values are ICMP_ECHO_REPLY meaning this is an ICM echo reply packet, or ICMP_ECHO_REQUEST meaning this is an ICMP echo request packet)
data is ICMP data
len is ICMP data length
id is ICMP packet identifier
seq is ICMP packet sequence number

void ICMPGet(NODE_INFO *remote, ICMP_CODE *code, BYTE *data, BYTE *len, WORD *id, WORD *seq)
where everything is the same as the put except possible code values are ICMP_ECHO_REPLY (meaning an ICMP echo reply packet is received) and ICMP_ECHO_REQUEST (meaning an ICMP echo request packet is received)

Is a ping as simple as doing an ICMPPut with an echo request packet and then do an ICMPGet to see if the packet is received?  I guess I don't really understand what goes on during a ping, other than data is transmitted to verify a connection.  I would be greately appricitative if someone could help me formulate a ping to my computer (192.168.1.102) in C.  I don't really know anything about this TCP/IP stuff.

By the way, I have some sample code I'll attach that came with the ICMP functions.  Might not mean much but I thought I'd throw it in.  

Thanks!!!!


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
Put example:
// Check to see if transmit buffer is available
if ( ICMPIsTxReady() )
    {
    // Transmit ICMP packet.
    ICMPPut(&RemoteNode, ICMP_ECHO_REPLY, data, datalen, id, seq);
    // Done. ICMP is put into transmit queue.
 
//--------------------------------------------------------------
 
Get example:
// Check to see if any packet is ready
if ( IPGetHeader(&Remote, &IPProtocol, &IPLen) )
    {
    // Check what kind of protocol it is
    if ( IPProtocol == IP_PROT_ICMP )
        {
        // This is ICMPP packet. Fetch it.
        ICMPGet(&ICMPCode, data, &dataLen, &id, &seq);
        // Process this ICMP packet.
        ../
        // When done processing this packet, discard it
        MACDiscardRx();
        }
    else
        {
// This is not an ICMP packet. Handle it
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: CDirenzi
Question Asked On: 03.26.2008
Participating Experts: 3
Points: 500
Views: 0
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by Infinity08

Rank: Sage

Expert Comment by Infinity08:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by evilrix

Rank: Guru

Expert Comment by evilrix:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by The--Captain

Rank: Guru

Expert Comment by The--Captain:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by CDirenzi
Author Comment by CDirenzi:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by evilrix

Rank: Guru

Expert Comment by evilrix:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by The--Captain

Rank: Guru

Expert Comment by The--Captain:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Infinity08

Rank: Sage

Expert Comment by Infinity08:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628