lwip-users
[Top][All Lists]
Advanced

[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: Sat, 13 Jan 2007 03:17:07 +0000
User-agent: Mozilla Thunderbird 1.0.8-1.1.fc3.4.legacy (X11/20060515)

Marcin Prusinski wrote:

Thanks for the reply,
I have one more question about this checksum. In ICMP ECHO header -
there are those fields:
type - 8 bits
code - 8 bits
checksum - 16 bits
id 16 bits
and seq number 16 bits
in exactly this order. Which fields are being computed in checksum ?

The whole IP header. You set the checksum field itself to 0 when working it out.

Should I use /inet_chksum/ like that:
/inet_chksum(iecho,1)/ ?  - where iecho is pointer to icmp_echo_hdr .
Then what's the point of 16 bit chksum field for 16 bit of data ?

http://www.tcpipguide.com/free/t_IPDatagramGeneralFormat.htm

Try something like:

#include "lwip/icmp.h"

{
  struct icmp_echo_hdr ping_pkt;
  static u16_t icmp_seq;
  u16t chksum;

  ping_pkt._type_code = ICMP_ECHO;
  ping_pkt.chksum = 0;
  ping_pkt.id = 0x8765;
  ping_pkt.seqno = icmp_seq++;
  chksum = inet_chksum( &ping_pkt, sizeof(ping_pkt);
  ping_pkt.chksum = chksum;


And then you can send ping_pkt down the raw socket you should have created with netconn_new_with_proto_and_callback(NETCONN_RAW, IP_PROTO_ICMP, NULL); or whatever is appropriate to the API you are using.

At least that's what I think... I haven't tried the above, so it may not be quite right.

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]