source: libpacketdump/ip_1.c @ 387d299

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

Remove duplicate macros in libpacketdump

Ensure OSPF libpacketdump module won't segfault or print garbage
if a truncated OSPF header is passed into it.

Renamed 'len' field in OSPF header to 'ospf_len' to avoid
potential conflict with variables named len in libpacketdump
code.

  • 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        if (len<1)
29                return;
30        printf(" ICMP:");
31        switch(icmp->type) {
32                case 0:
33                        printf(" Type: 0 (ICMP Echo Reply) Sequence: ");
34                        if (len < 4)
35                                printf("(Truncated)\n");
36                        else
37                                printf("%u\n", ntohs(icmp->un.echo.sequence));
38                        break;
39                case 3:
40                        printf(" Type: 3 (ICMP Destination Unreachable)\n");
41                        if (len<2)
42                                return;
43                        if (icmp->code<sizeof(unreach_types)) {
44                                printf(" ICMP: Code: %i (%s)\n",icmp->code,
45                                                unreach_types[icmp->code]);
46                        }
47                        else {
48                                printf(" ICMP: Code: %i (Unknown)\n",icmp->code);
49                        }
50                        // Pretend that this was just passed up from ethernet
51                        decode_next(packet+8,len-8,
52                                        "eth",0x0800);
53
54                        break;
55                case 8:
56                        printf(" Type: 8 (ICMP Echo Request) Sequence: ");
57                        if (len < 4)
58                                printf("(Truncated)\n");
59                        else
60                                printf("%u\n", ntohs(icmp->un.echo.sequence));
61                        break;
62                case 11:
63                        printf(" Type: 11 (ICMP TTL Exceeded)\n");
64                        decode_next(packet+8,len-8,
65                                        "eth",0x0800);
66                        break;
67                default:
68                        printf(" Type: %i (Unknown)\n",icmp->type);
69                        break;
70
71        }
72        printf(" ICMP: Checksum: ");
73        if (len < 8)
74                printf("(Truncated)\n");
75        else
76                printf("%u\n", ntohs(icmp->checksum));
77
78
79        return;
80}
Note: See TracBrowser for help on using the repository browser.