source: libpacketdump/ip_1.c @ 39c3ce7

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivelibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 39c3ce7 was 39c3ce7, checked in by Shane Alcock <salcock@…>, 6 years ago

Dump ICMP checksum with rest of ICMP header

Previously, we were decoding and printing the embedded IP header in TTL
Exceeded and Destination Unreachable messages before printing the Checksum
for the preceding ICMP header.

  • Property mode set to 100644
File size: 2.0 KB
Line 
1#include <stdio.h>
2#include <inttypes.h>
3#include <dlfcn.h>
4#include "libpacketdump.h"
5
6static char *unreach_types[]={
7        "Destination Network Unreachable",
8        "Destination Host Unreachable",
9        "Destination Protocol Unreachable",
10        "Destination Port Unreachable",
11        "Fragmentation Required And Dont Fragment Set",
12        "Source Route Failed",
13        "Destination Network Unknown",
14        "Destination Host Unknown",
15        "Source Host Isolated",
16        "Destination Network Administratively Prohibited",
17        "Destination Host Administratively Prohibited",
18        "Destination Network Unreachable For Type Of Service",
19        "Destination Host Unreachable For Type Of Service",
20        "Communication Administratively Prohibited",
21        "Host Precedence Violation",
22        "Precedence Cutoff In Effect",
23};
24
25DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
26{
27        libtrace_icmp_t *icmp = (libtrace_icmp_t*)packet;
28        int ippresent = 0;
29        if (len<1)
30                return;
31        printf(" ICMP:");
32        switch(icmp->type) {
33                case 0:
34                        printf(" Type: 0 (ICMP Echo Reply) Sequence: ");
35                        if (len < 4)
36                                printf("(Truncated)\n");
37                        else
38                                printf("%u\n", ntohs(icmp->un.echo.sequence));
39                        break;
40                case 3:
41                        printf(" Type: 3 (ICMP Destination Unreachable)\n");
42                        if (len<2)
43                                return;
44                        if (icmp->code<sizeof(unreach_types)) {
45                                printf(" ICMP: Code: %i (%s)\n",icmp->code,
46                                                unreach_types[icmp->code]);
47                        }
48                        else {
49                                printf(" ICMP: Code: %i (Unknown)\n",icmp->code);
50                        }
51                        ippresent = 1;
52                        break;
53                case 8:
54                        printf(" Type: 8 (ICMP Echo Request) Sequence: ");
55                        if (len < 4)
56                                printf("(Truncated)\n");
57                        else
58                                printf("%u\n", ntohs(icmp->un.echo.sequence));
59                        break;
60                case 11:
61                        printf(" Type: 11 (ICMP TTL Exceeded)\n");
62                        ippresent = 1;
63                        break;
64                default:
65                        printf(" Type: %i (Unknown)\n",icmp->type);
66                        break;
67
68        }
69        printf(" ICMP: Checksum: ");
70        if (len < 8)
71                printf("(Truncated)\n");
72        else
73                printf("%u\n", ntohs(icmp->checksum));
74
75        if (ippresent) {
76                decode_next(packet+8,len-8,
77                                "eth",0x0800);
78        }
79
80
81        return;
82}
Note: See TracBrowser for help on using the repository browser.