source: libpacketdump/ip_17.cc @ e3b0188

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since e3b0188 was e3b0188, checked in by Daniel Lawson <dlawson@…>, 16 years ago

a lot of changes for cross-compilation support

  • header ordering
  • os-specific headers
  • an lt_inttypes.h which defines PRIu64 etc for platforms that don't have them
  • removed daglegacy.h, merged with dagformat.h
  • Property mode set to 100644
File size: 1.6 KB
Line 
1#include <stdio.h>
2#include <inttypes.h>
3#include <dlfcn.h>
4#include <map>
5#include "libpacketdump.h"
6#include "libtrace.h"
7#include <netinet/udp.h>
8#include <netinet/in.h>
9#include <netdb.h>
10
11#define STRUCT udp
12
13#define SAFE(x) \
14        ((unsigned int)len>=((char*)&STRUCT->x-(char*)STRUCT+sizeof(STRUCT->x)))
15#define DISPLAY_EXP(x,fmt,exp) \
16        if (SAFE(x)) \
17                printf(fmt,exp); \
18        else \
19                return;
20
21#define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,STRUCT->x)
22
23#define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(STRUCT->x))
24#define DISPLAYL(x,fmt) DISPLAY_EXP(x,fmt,htonl(STRUCT->x))
25#define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&STRUCT->x))
26
27
28extern "C"
29void decode(int link_type,char *packet,int len)
30{
31        struct libtrace_udp *udp = (struct libtrace_udp*)packet;
32        printf(" UDP:");
33        if (SAFE(source)) {
34                struct servent *ent=getservbyport(udp->source,"udp");
35                if(ent) {
36                        printf(" Source %i (%s)",htons(udp->source),ent->s_name);
37                } else {
38                        printf(" Source %i",htons(udp->source));
39                }
40        }
41        else {
42                printf("\n");
43                return;
44        }
45        if (SAFE(dest)) {
46                struct servent *ent=getservbyport(udp->dest,"udp");
47                if(ent) {
48                        printf(" Dest %i (%s)",htons(udp->dest),ent->s_name);
49                } else {
50                        printf(" Dest %i",htons(udp->dest));
51                }
52        }
53        else {
54                printf("\n");
55                return;
56        }
57        printf("\n UDP:");
58        DISPLAYS(len," Len %u");
59        DISPLAYS(check," Checksum %u");
60        printf("\n");
61        if (htons(udp->source) < htons(udp->dest)) 
62                decode_next(packet+sizeof(*udp),len-sizeof(*udp),"udp",htons(udp->source));
63        else
64                decode_next(packet+sizeof(*udp),len-sizeof(*udp),"udp",htons(udp->dest));
65        return;
66}
Note: See TracBrowser for help on using the repository browser.