source: libpacketdump/ip_1.c @ 176646e

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 176646e was c7062df, checked in by Shane Alcock <salcock@…>, 12 years ago
  • Ensure that the decode functions are exported as global symbols for the various libpacketdump shared libraries
  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[950d54a]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
[c7062df]41DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
[950d54a]42{
[4e65f42]43        libtrace_icmp_t *icmp = (libtrace_icmp_t*)packet;
[950d54a]44        if (len<1)
45                return;
46        printf(" ICMP:");
47        switch(icmp->type) {
48                case 0:
[48589ca]49                        printf(" Type: 0 (ICMP Echo Reply) Sequence: ");
50                        if (len < 4)
51                                printf("(Truncated)\n");
52                        else
53                                printf("%u\n", ntohs(icmp->un.echo.sequence));
[950d54a]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:
[48589ca]72                        printf(" Type: 8 (ICMP Echo Request) Sequence: ");
73                        if (len < 4)
74                                printf("(Truncated)\n");
75                        else
76                                printf("%u\n", ntohs(icmp->un.echo.sequence));
[950d54a]77                        break;
78                case 11:
79                        printf(" Type: 11 (ICMP TTL Exceeded)\n");
80                        decode_next(packet+8,len-8,
81                                        "eth",0x0800);
82                        break;
83                default:
84                        printf(" Type: %i (Unknown)\n",icmp->type);
85                        break;
86
87        }
88        return;
89}
Note: See TracBrowser for help on using the repository browser.