Advertisement

03.26.2008 at 06:27PM PDT, ID: 23272704 | Points: 500
[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: Networking
Question Asked By: CDirenzi
Question Asked On: 03.26.2008
Participating Experts: 3
Points: 500
Views: 0
Translate:
Loading Advertisement...
03.27.2008 at 12:32AM PDT, ID: 21219234

Rank: Sage

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.

 
03.27.2008 at 05:46AM PDT, ID: 21220673

Rank: Guru

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.

 
03.27.2008 at 02:04PM PDT, ID: 21225738

Rank: Guru

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.

 
03.28.2008 at 09:27AM PDT, ID: 21231837

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.

 
03.28.2008 at 10:08AM PDT, ID: 21232234

Rank: Guru

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.

 
03.28.2008 at 05:07PM PDT, ID: 21234885

Rank: Guru

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.

 
03.31.2008 at 01:28AM PDT, ID: 21243882

Rank: Sage

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...
20080236-EE-VQP-29 / EE_QW_2_20070628