CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How do I send an ICMP packet?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
TimC



Joined: 12 Nov 2005
Posts: 5

View user's profile Send private message

How do I send an ICMP packet?
PostPosted: Mon Sep 25, 2006 10:51 am     Reply with quote

Hi all,
I am using the CCS Embedded Ethernet Dev kit and there are 2 examples in chapter 10 on receiving a response from a ICMP ping packet but I have no idea on how to send a ping request.

My project is to increment the TTL value for several Ping requests going to the same destination. I should be able to trace my Ping route as the number of hops exceeds the TTL value.

Thank You
Tim C
erhan



Joined: 17 Aug 2005
Posts: 7

View user's profile Send private message

PostPosted: Fri Dec 15, 2006 2:29 am     Reply with quote

How can we send ping?My ip address=10.0.0.10

Code:
   NODE_INFO PingDest;
   int PingData[]={'e','r','h','a','n',0};
   int16 SeqNo=0;
   PingDest.MACAddr.v[0]= MY_MAC_BYTE1;
   PingDest.MACAddr.v[1]= MY_MAC_BYTE2;
   PingDest.MACAddr.v[2]= MY_MAC_BYTE3;
   PingDest.MACAddr.v[3]= MY_MAC_BYTE4;
   PingDest.MACAddr.v[4]= MY_MAC_BYTE5;
   PingDest.MACAddr.v[5]= MY_MAC_BYTE6;

   PingDest.IPAddr.v[0]=10;
   PingDest.IPAddr.v[1]=0;
   PingDest.IPAddr.v[2]=0;
   PingDest.IPAddr.v[3]=25;

   //ping   
         ICMPPut(&PingDest,ICMP_ECHO_REQUEST,&PingData[0],5,12,++SeqNo);


This code did'nt work.I am watching bus with ethereal.it says 10.0.0.10 ping request but it doesn't say 10.0.0.25 echo reply.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Dec 15, 2006 2:56 am     Reply with quote

There are a number of possible problems.

Ensure that the source MAC address of the outbound packet is a unicast MAC address

If the source MAC address unique?

Have you set the sunbet mask correctly?

Does the target have a personal firewall - if so is ICMP enabled (not blocked)?

Do you see an ARP request from the Target looking for the PIC? If so does the PIC respond?
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!


Last edited by asmallri on Fri Dec 15, 2006 5:15 am; edited 1 time in total
erhan



Joined: 17 Aug 2005
Posts: 7

View user's profile Send private message

PostPosted: Fri Dec 15, 2006 3:18 am     Reply with quote

I know destination mac address so I don't have to do arp request.
I corrected my code like this

Code:
   NODE_INFO PingDest;
   int PingData[]={'e','r','h','a','n',0};
   int16 SeqNo=0;
   PingDest.MACAddr.v[0]= 0;
   PingDest.MACAddr.v[1]= 0x17;
   PingDest.MACAddr.v[2]= 0x31;
   PingDest.MACAddr.v[3]= 0x2E;
   PingDest.MACAddr.v[4]= 0x26;
   PingDest.MACAddr.v[5]= 0xD5;

   PingDest.IPAddr.v[0]=10;
   PingDest.IPAddr.v[1]=0;
   PingDest.IPAddr.v[2]=0;
   PingDest.IPAddr.v[3]=25;

   ICMPPut(&PingDest,ICMP_ECHO_REQUEST,&PingData[0],5,0,++SeqNo);


Anyway now I can send ping.But I want to do arp request to learn destination mac address automatically.How can I do this
erhan



Joined: 17 Aug 2005
Posts: 7

View user's profile Send private message

PostPosted: Fri Dec 15, 2006 7:10 am     Reply with quote

this is the working ping code with arp request
Code:

void ping(IP_ADDR *IPAddr)
{
       
    NODE_INFO remoteNode;   
    int PingData[]="abcdefghijklmnnopqrstuwxvyz12345";
    int i;
    static int SeqNo=0;
   
    remoteNode.IPAddr = *IPAddr;
    ArpResolve(&remoteNode.IPAddr.v[0]);
   
    for(i=0;i<6;i++)
      remoteNode.MACAddr.v[i]=Cache.MACAddr.v[i];       
    ICMPPut(&remoteNode,ICMP_ECHO_REQUEST,&PingData[0],32,0,SeqNo);

}


in main

Code:
   NODE_INFO PingDest;

   PingDest.IPAddr.v[0]=10;
   PingDest.IPAddr.v[1]=0;
   PingDest.IPAddr.v[2]=0;
   PingDest.IPAddr.v[3]=25; 

   ping(&PingDest.IPAddr.v[0]);
dpechman



Joined: 04 Dec 2007
Posts: 43

View user's profile Send private message Visit poster's website

PostPosted: Thu Mar 22, 2012 7:24 pm     Reply with quote

My ping stop working after I change another parts of the code and I cannot find the bug.

In icmp.c the MyTxBuffer is equal to INVALID_BUFFER.

If I bypass the avoid check the ping is sent and looks ok to the address that I have pointed to.

How is the right way to set the MyTxBuffer?

Code:

void ICMPPut(NODE_INFO *remote,
             ICMP_CODE code,
             BYTE *data,
             BYTE len,
             WORD id,
             WORD seq)
{
    ICMP_PACKET   packet;
    WORD ICMPLen;
   BUFFER MyTxBuffer;
   MyTxBuffer = MACGetTxBuffer(TRUE);

   // Abort if there is no where in the Ethernet controller to
   // store this packet.
   //if(MyTxBuffer == INVALID_BUFFER) <<==here is true
     // return;
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group