source: libpacketdump/ip_1.cc @ 9461526

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 9461526 was 4e65f42, checked in by Shane Alcock <salcock@…>, 15 years ago

Fixed segmentation faults when trace_destroy is called on a trace that wasn't successfully created
libdl is now checked for and only linked against if available (BSD's don't have a libdl)
Fixed the libpacketdump .so's to use libtrace's generic protocol headers as well as trace_ether_ntoa
Added missing check for strlcpy
Added a couple of #defines to various tools that needed them under FreeBSD
Removed some needless #includes from the libpacketdump .so's

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