[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] pinging
From: |
Jonathan Larmour |
Subject: |
Re: [lwip-users] pinging |
Date: |
Wed, 10 Jan 2007 00:28:47 +0000 |
User-agent: |
Thunderbird 1.5.0.9 (X11/20070102) |
Marcin Prusinski wrote:
Hey !
I was looking for example that will help me send some icmp echo
requests. I only found post of Larry Piggins who wrote exactly something
i need, but i couldn't find the code.
You need to make a raw socket, i.e. NETCONN_RAW, ensuring LWIP_RAW is on in
your configuration.
I'm using standalone version of LWIP.
I'm just a begginer and I can't figure out how to compute ICMP ECHO
checksum.
Here's some code obtained from elsewhere:
static int inet_cksum(u_short *addr, int len)
{
register int nleft = len;
register u_short *w = addr;
register u_short answer;
register u_int sum = 0;
u_short odd_byte = 0;
/*
* Our algorithm is simple, using a 32 bit accumulator (sum),
* we add sequential 16 bit words to it, and at the end, fold
* back all the carry bits from the top 16 bits into the lower
* 16 bits.
*/
while( nleft > 1 ) {
sum += *w++;
nleft -= 2;
}
/* mop up an odd byte, if necessary */
if( nleft == 1 ) {
*(u_char *)(&odd_byte) = *(u_char *)w;
sum += odd_byte;
}
/*
* add back carry outs from top 16 bits to low 16 bits
*/
sum = (sum >> 16) + (sum & 0x0000ffff); /* add hi 16 to low 16 */
sum += (sum >> 16); /* add carry */
answer = ~sum; /* truncate to 16 bits */
return (answer);
}
Hope this helps,
Jifl
--
eCosCentric http://www.eCosCentric.com/ The eCos and RedBoot experts
Company legal info, address and number: http://www.ecoscentric.com/legal
------["The best things in life aren't things."]------ Opinions==mine