source: libpacketdump/eth_2048.cc @ 4a605a9

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

use netdb to lookup ports/protocols

  • Property mode set to 100644
File size: 1.4 KB
Line 
1#include <netinet/ether.h>
2#include <netinet/in.h>
3#include <stdio.h>
4#include <inttypes.h>
5#include <dlfcn.h>
6#include <map>
7#include "libpacketdump.h"
8#include <sys/socket.h>
9#include <netinet/in.h>
10#include <netinet/ip.h>
11#include <arpa/inet.h>
12#include <netdb.h>
13
14#define DISPLAY_EXP(x,fmt,exp) \
15        if ((unsigned int)len>=((char*)&ip->x-(char*)ip+sizeof(ip->x))) \
16                printf(fmt,exp); \
17        else \
18                return;
19
20#define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,ip->x)
21
22#define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(ip->x))
23#define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&ip->x))
24
25extern "C"
26void decode(int link_type,char *packet,int len)
27{
28        struct iphdr *ip = (struct iphdr*)packet;
29        if (len>=1) {
30                printf(" IP: Header Len %i",ip->ihl*4);
31                printf(" Ver %i",ip->version);
32        }
33        DISPLAY(tos," TOS %02x")
34        DISPLAYS(tot_len," Total Length %i")
35        printf("\n IP:");
36        DISPLAY(id," Id %i");
37        DISPLAY(frag_off," Fragoff %i");
38        //printf("\n IP:");
39        DISPLAY(ttl," TTL %i");
40        if ((unsigned int)len>=((char*)&ip->protocol-(char*)ip+sizeof(ip->protocol))) {
41                struct protoent *ent=getprotobynumber(ip->protocol);
42                if (ent) {
43                        printf(" Proto %i (%s)",ip->protocol,ent->p_name);
44                }
45                else {
46                        printf(" Proto %i",ip->protocol);
47                }
48        } else {
49                printf("\n");
50                return;
51        }
52        DISPLAYS(check," Checksum %i\n");
53        DISPLAYIP(saddr," IP: Source %s ");
54        DISPLAYIP(daddr,"Destination %s\n");
55        decode_next(packet+sizeof(*ip),len-sizeof(*ip),"ip",ip->protocol);
56        return;
57}
Note: See TracBrowser for help on using the repository browser.