source: libpacketdump/eth_2048.cc @ 4e65f42

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 4e65f42 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: 1.6 KB
Line 
1#include <netinet/in.h>
2#include <stdio.h>
3#include <inttypes.h>
4#include <dlfcn.h>
5#include "libpacketdump.h"
6#include <sys/socket.h>
7#ifndef WIN32
8        #include <netinet/in_systm.h>
9#endif
10#include <netinet/in.h>
11#include <netinet/ip.h>
12#include <arpa/inet.h>
13#include <netdb.h>
14
15#define DISPLAY_EXP(x,fmt,exp) \
16        if ((unsigned int)len>=((char*)&ip->x-(char*)ip+sizeof(ip->x))) \
17                printf(fmt,exp); \
18        else \
19                return;
20
21#define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,ip->x)
22
23#define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(ip->x))
24#define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&ip->x))
25
26extern "C"
27void decode(int link_type,char *packet,int len)
28{
29        libtrace_ip_t *ip = (libtrace_ip_t*)packet;
30        if (len>=1) {
31                printf(" IP: Header Len %i",ip->ip_hl*4);
32                printf(" Ver %i",ip->ip_v);
33        }
34        DISPLAY(ip_tos," TOS %02x")
35        DISPLAYS(ip_len," Total Length %i")
36        printf("\n IP:");
37        DISPLAY(ip_id," Id %i");
38       
39        if ((unsigned int)len >= ((char *)&ip->ip_ttl - (char *)ip - 2)) {
40                printf(" \n Fragoff %i", ip->ip_off);
41                if (ip->ip_mf) printf(" MORE_FRAG");
42                if (ip->ip_df) printf(" DONT_FRAG");
43                if (ip->ip_rf) printf(" RESV_FRAG");
44        }
45        //printf("\n IP:");
46        DISPLAY(ip_ttl,"\n TTL %i");
47        if ((unsigned int)len>=((char*)&ip->ip_p-(char*)ip+sizeof(ip->ip_p))) {
48                struct protoent *ent=getprotobynumber(ip->ip_p);
49                if (ent) {
50                        printf(" Proto %i (%s)",ip->ip_p,ent->p_name);
51                }
52                else {
53                        printf(" Proto %i",ip->ip_p);
54                }
55        } else {
56                printf("\n");
57                return;
58        }
59        DISPLAYS(ip_sum," Checksum %i\n");
60        DISPLAYIP(ip_src," IP: Source %s ");
61        DISPLAYIP(ip_dst,"Destination %s\n");
62        decode_next(packet+sizeof(*ip),len-sizeof(*ip),"ip",ip->ip_p);
63        return;
64}
Note: See TracBrowser for help on using the repository browser.