Title: icmp_hdr_t


An icmp header has the following structure:

typedef struct icmp_hdr

{
       u8_t ih_type, ih_code;
       u16_t ih_chksum;
       union
       {
              u32_t ihh_unused;
              icmp_id_seq_t ihh_idseq;
              ipaddr_t ihh_gateway;
              icmp_ram_t ihh_ram;
              icmp_pp_t ihh_pp;
       } ih_hun;
       union
       {
              icmp_ip_id_t ihd_ipid;
              u8_t uhd_data[1];
       } ih_dun;
} icmp_hdr_t;


Note that the "union" keyword specifies that only one field within the block will be used. For example, for router advertisements, only the ihh_ram field from the first union and the uhd_data[1] field from the second union are used.

ih_type, ih_code: ih_type, as the name suggests, is the type of icmp message. ih_code is a code that is specific to the messages type. Below are the possible types and their associates codes (note that the codes are indented):

#define ICMP_TYPE_ECHO_REPL       0

#define ICMP_TYPE_DST_UNRCH 3
# define ICMP_NET_UNRCH 0
# define ICMP_HOST_UNRCH 1
# define ICMP_PROTOCOL_UNRCH 2
# define ICMP_PORT_UNRCH 3
# define ICMP_FRAGM_AND_DF 4
# define ICMP_SOURCE_ROUTE_FAILED 5
#define ICMP_TYPE_SRC_QUENCH 4
#define ICMP_TYPE_REDIRECT 5
# define ICMP_REDIRECT_NET 0
# define ICMP_REDIRECT_HOST 1
# define ICMP_REDIRECT_TOS_AND_NET 2
# define ICMP_REDIRECT_TOS_AND_HOST 3
#define ICMP_TYPE_ECHO_REQ 8
#define ICMP_TYPE_ROUTER_ADVER 9
#define ICMP_TYPE_ROUTE_SOL 10
#define ICMP_TYPE_TIME_EXCEEDED 11
# define ICMP_TTL_EXC 0
# define ICMP_FRAG_REASSEM 1
Most of these are self-explanatory. It is unclear what function the ICMP_TYPE_ROUTE_SOL icmp message performs.


u16_t ih_chksum: The checksum of the icmp message.


icmp_id_seq_t ihh_idseq:

typedef struct icmp_id_seq

{
       u16_t       iis_id, iis_seq;
} icmp_id_seq_t;
u16_t       iis_id, iis_seq:

The iis_id and the iis_seq fields are used to match echo replies to echo requests.


ipaddr_t ihh_gateway: The redirect gateway.


icmp_ram_t ihh_ram:

typedef struct icmp_ram              /* RFC 1256 */

{
       u8_t       iram_na;
       u8_t       iram_aes;
       u16_t       iram_lt;
} icmp_ram_t;
Note that "ram" stands for "Router Advertisement Message". Only router advertisement icmp messages use this struct.

u8_t       iram_na: (Number of Addresses) The number of router addresses advertised in the message.

u8_t       iram_aes: (Address Entry Size) The number of 32-bit words of information per router address (2 in the diagram below; the first 32-bits is for the router address and the second 32-bits is the preference of the router).

u16_t       iram_lt: (LifeTime) Lifetime of the router address in seconds.


icmp_pp_t ihh_pp: Not used by the network service.
icmp_ip_id_t ihd_ipid: Not used by the network service.


u8_t uhd_data[1]: Although this field shows that it has a length of a single byte, as much data as necessary may be placed here. This field is the location of the router advertisements (see figure below) as well as the ip header of returned ip packets and may be as long as necessary .

ICMP Router Advertisement Message


0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Code | Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Num Addrs |Addr Entry Size| Lifetime |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Router Address[1] |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Preference Level[1] |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Router Address[2] |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Preference Level[2] |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| . |
| . |
| . |