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

net/icmp.h

Committer:
etherealflaim
Date:
2010-10-12
Revision:
2:e8e09adc41fc
Parent:
0:d494b853ce97
Child:
3:c32d9660b888

File content as of revision 2:e8e09adc41fc:

#ifndef ICMP_H
#define ICMP_H

#include "net.h"

/// \file ICMP Packet

#define ICMP_ECHO_REPLY   0x00
#define ICMP_ECHO_REQUEST 0x08
#define IPPROTO_ICMP      0x01

/// Memory map of ICMP packet
typedef struct {
    u8 type;        ///< type of ICMP message
    u8 code;        ///< code number associated with certain message types
    u16 checksum; 
    u16 id;         ///< ID value, returned in ECHO REPLY
    u16 sequence;   ///< Sequence value to be returned with ECHO REPLY
    u8 data[];      ///< Data memory map
} ICMP_Packet;

/// Convert from wire to host or host to wire endianness
inline void fix_endian_icmp(ICMP_Packet *segment)
{
  fix_endian_u16(&segment->checksum);
  fix_endian_u16(&segment->id);
  fix_endian_u16(&segment->sequence);
}

/// Print the ICMP packet
inline void print_icmp(ICMP_Packet *segment)
{
  main_log.printf("ICMP Packet:");
  main_log.printf("  Type:      0x%02X", segment->type);
  main_log.printf("  Code:      0x%02X", segment->code);
  main_log.printf("  Checksum:  0x%04X", segment->checksum);
  main_log.printf("  ID:        0x%04X", segment->id);
  main_log.printf("  Sequence:  0x%04X", segment->sequence);
}

#endif