source: libpacketdump/eth_2048.c @ 0a22046

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

New automake infrastructure
Moved a lot of C++ libpacketdump parsers to C (they weren't using any C++ features and it makes automake happier)

  • 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
26void decode(int link_type,char *packet,int len)
27{
28        libtrace_ip_t *ip = (libtrace_ip_t*)packet;
29        if (len>=1) {
30                printf(" IP: Header Len %i",ip->ip_hl*4);
31                printf(" Ver %i",ip->ip_v);
32        }
33        DISPLAY(ip_tos," TOS %02x")
34        DISPLAYS(ip_len," Total Length %i")
35        printf("\n IP:");
36        DISPLAY(ip_id," Id %u");
37       
38        if ((unsigned int)len >= ((char *)&ip->ip_ttl - (char *)ip - 2)) {
39                printf(" \n Fragoff %i", ip->ip_off);
40                if (ip->ip_mf) printf(" MORE_FRAG");
41                if (ip->ip_df) printf(" DONT_FRAG");
42                if (ip->ip_rf) printf(" RESV_FRAG");
43        }
44        //printf("\n IP:");
45        DISPLAY(ip_ttl,"\n TTL %i");
46        if ((unsigned int)len>=((char*)&ip->ip_p-(char*)ip+sizeof(ip->ip_p))) {
47                struct protoent *ent=getprotobynumber(ip->ip_p);
48                if (ent) {
49                        printf(" Proto %i (%s)",ip->ip_p,ent->p_name);
50                }
51                else {
52                        printf(" Proto %i",ip->ip_p);
53                }
54        } else {
55                printf("\n");
56                return;
57        }
58        DISPLAYS(ip_sum," Checksum %i\n");
59        DISPLAYIP(ip_src," IP: Source %s ");
60        DISPLAYIP(ip_dst,"Destination %s\n");
61        decode_next(packet+sizeof(*ip),len-sizeof(*ip),"ip",ip->ip_p);
62        return;
63}
Note: See TracBrowser for help on using the repository browser.