This is a low-level network debugging utility that utilizes raw packet i/o to construct and deconstruct tcp, udp, ipv4, arp, and icmp packets over ethernet.

Dependencies:   mbed

Committer:
etherealflaim
Date:
Tue Oct 12 05:32:59 2010 +0000
Revision:
0:d494b853ce97
Child:
2:e8e09adc41fc
Initial Publish - Slightly unfinished, but usable

Who changed what in which revision?

UserRevisionLine numberNew contents of line
etherealflaim 0:d494b853ce97 1 #ifndef ICMP_H
etherealflaim 0:d494b853ce97 2 #define ICMP_H
etherealflaim 0:d494b853ce97 3
etherealflaim 0:d494b853ce97 4 #include "net.h"
etherealflaim 0:d494b853ce97 5
etherealflaim 0:d494b853ce97 6 #define ICMP_ECHO_REPLY 0x00
etherealflaim 0:d494b853ce97 7 #define ICMP_ECHO_REQUEST 0x08
etherealflaim 0:d494b853ce97 8 #define IPPROTO_ICMP 0x01
etherealflaim 0:d494b853ce97 9 typedef struct {
etherealflaim 0:d494b853ce97 10 u8 type; // type of ICMP message
etherealflaim 0:d494b853ce97 11 u8 code; // code number associated with certain message types
etherealflaim 0:d494b853ce97 12 u16 checksum;
etherealflaim 0:d494b853ce97 13 u16 id; // ID value, returned in ECHO REPLY
etherealflaim 0:d494b853ce97 14 u16 sequence; // Sequence value to be returned with ECHO REPLY
etherealflaim 0:d494b853ce97 15 u8 data[];
etherealflaim 0:d494b853ce97 16 } ICMP_Packet;
etherealflaim 0:d494b853ce97 17
etherealflaim 0:d494b853ce97 18 inline void fix_endian_icmp(ICMP_Packet *segment)
etherealflaim 0:d494b853ce97 19 {
etherealflaim 0:d494b853ce97 20 fix_endian_u16(&segment->checksum);
etherealflaim 0:d494b853ce97 21 fix_endian_u16(&segment->id);
etherealflaim 0:d494b853ce97 22 fix_endian_u16(&segment->sequence);
etherealflaim 0:d494b853ce97 23 }
etherealflaim 0:d494b853ce97 24
etherealflaim 0:d494b853ce97 25 inline void print_icmp(ICMP_Packet *segment)
etherealflaim 0:d494b853ce97 26 {
etherealflaim 0:d494b853ce97 27 main_log.printf("ICMP Packet:");
etherealflaim 0:d494b853ce97 28 main_log.printf(" Type: 0x%02X", segment->type);
etherealflaim 0:d494b853ce97 29 main_log.printf(" Code: 0x%02X", segment->code);
etherealflaim 0:d494b853ce97 30 main_log.printf(" Checksum: 0x%04X", segment->checksum);
etherealflaim 0:d494b853ce97 31 main_log.printf(" ID: 0x%04X", segment->id);
etherealflaim 0:d494b853ce97 32 main_log.printf(" Sequence: 0x%04X", segment->sequence);
etherealflaim 0:d494b853ce97 33 }
etherealflaim 0:d494b853ce97 34
etherealflaim 0:d494b853ce97 35 #endif