source: libpacketdump/ip_33.c @ 2ec8434

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 2ec8434 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: 1.9 KB
Line 
1/* DCCP */
2#include <stdio.h>
3#include <inttypes.h>
4#include <dlfcn.h>
5#include "libpacketdump.h"
6#include <netinet/tcp.h>
7#include <netinet/in.h>
8
9#define STRUCT dccp
10
11#define SAFE(x) \
12        ((unsigned int)len>=((char*)&STRUCT->x-(char*)STRUCT+sizeof(STRUCT->x)))
13#define DISPLAY_EXP(x,fmt,exp) \
14        if (SAFE(x)) \
15                printf(fmt,exp); \
16        else \
17                return;
18
19#define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,STRUCT->x)
20
21#define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(STRUCT->x))
22#define DISPLAYL(x,fmt) DISPLAY_EXP(x,fmt,htonl(STRUCT->x))
23#define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&STRUCT->x))
24
25struct dccphdr {
26        uint16_t source;
27        uint16_t dest;
28        uint8_t type:4;
29        uint8_t ccval:4;
30        uint32_t seq:24;
31        uint8_t doff;
32        uint8_t ndp:4;
33        uint8_t cslen:4;
34        uint16_t check;
35};
36
37static char *dccp_types[]={
38        "DCCP-Request packet",
39        "DCCP-Response packet",
40        "DCCP-Data packet",
41        "DCCP-Ack packet",
42        "DCCP-DataAck packet",
43        "DCCP-CloseReq packet",
44        "DCCP-Close packet",
45        "DCCP-Reset packet",
46        "DCCP-Move packet",
47        };
48
49DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
50{
51        struct dccphdr *dccp = (struct dccphdr*)packet;
52        DISPLAYS(source," DCCP: Source %i");
53        DISPLAYS(dest," Dest %i");
54        if (len>4) {
55                printf("\n DCCP: Type %i",dccp->type);
56                if (dccp->type<sizeof(dccp_types)) {
57                        printf(" (%s)\n",dccp_types[dccp->type]);
58                } else {
59                        printf(" (Unknown)\n");
60                }
61                printf(" DCCP: CcVal %i\n",dccp->ccval);
62        }
63        else  {
64                printf("\n"); 
65                return;
66        }
67        if (len>7)
68                printf(" DCCP: Seq %u\n",dccp->seq); // htonwhat?
69        else
70                return;
71        DISPLAY(doff," DCCP: Dataoff: %i\n");
72        if (len>9)
73                printf(" DCCP: NDP %i CsLen: %i\n",dccp->ndp,dccp->cslen);
74        else {
75                return;
76        }
77        DISPLAY(check," DCCP: Checksum: %i\n");
78        if (htons(dccp->source) < htons(dccp->dest)) 
79                decode_next(packet+dccp->doff*4,len-dccp->doff*4,"dccp",htons(dccp->source));
80        else
81                decode_next(packet+dccp->doff*4,len-dccp->doff*4,"dccp",htons(dccp->dest));
82        return;
83}
Note: See TracBrowser for help on using the repository browser.