source: examples/tracedump/ip_1.cc @ d907ff5

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since d907ff5 was d907ff5, checked in by Perry Lorier <perry@…>, 16 years ago

Import tracedump to libtrace

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