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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers icmp.h Source File

icmp.h

Go to the documentation of this file.
00001 #ifndef ICMP_H
00002 #define ICMP_H
00003 
00004 #include "net.h"
00005 
00006 /**
00007   \file icmp.h
00008   \brief ICMP frame header
00009   
00010   This file contains the memory map and associated functions for ICMP packet
00011   creation and deconstruction. 
00012 */
00013 
00014 #define ICMP_ECHO_REPLY   0x00
00015 #define ICMP_ECHO_REQUEST 0x08
00016 #define IPPROTO_ICMP      0x01
00017 
00018 /// ICMP packet memory map
00019 typedef struct {
00020     u8 type;        ///< type of ICMP message
00021     u8 code;        ///< code number associated with certain message types
00022     u16 checksum; 
00023     u16 id;         ///< ID value, returned in ECHO REPLY
00024     u16 sequence;   ///< Sequence value to be returned with ECHO REPLY
00025     u8 data[];      ///< Data memory map
00026 } ICMP_Packet;
00027 
00028 /// Convert from wire to host or host to wire endianness
00029 inline void fix_endian_icmp(ICMP_Packet *segment)
00030 {
00031   fix_endian_u16(&segment->checksum);
00032   fix_endian_u16(&segment->id);
00033   fix_endian_u16(&segment->sequence);
00034 }
00035 
00036 /// Print the ICMP packet
00037 inline void print_icmp(ICMP_Packet *segment)
00038 {
00039   main_log.printf("ICMP Packet:");
00040   main_log.printf("  Type:      0x%02X", segment->type);
00041   main_log.printf("  Code:      0x%02X", segment->code);
00042   main_log.printf("  Checksum:  0x%04X", segment->checksum);
00043   main_log.printf("  ID:        0x%04X", segment->id);
00044   main_log.printf("  Sequence:  0x%04X", segment->sequence);
00045 }
00046 
00047 #endif