source: libpacketdump/ip_33.c @ 387d299

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivelibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 387d299 was 387d299, checked in by Shane Alcock <salcock@…>, 7 years ago

Remove duplicate macros in libpacketdump

Ensure OSPF libpacketdump module won't segfault or print garbage
if a truncated OSPF header is passed into it.

Renamed 'len' field in OSPF header to 'ospf_len' to avoid
potential conflict with variables named len in libpacketdump
code.

  • Property mode set to 100644
File size: 1.5 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
9struct dccphdr {
10        uint16_t source;
11        uint16_t dest;
12        uint8_t type:4;
13        uint8_t ccval:4;
14        uint32_t seq:24;
15        uint8_t doff;
16        uint8_t ndp:4;
17        uint8_t cslen:4;
18        uint16_t check;
19};
20
21static char *dccp_types[]={
22        "DCCP-Request packet",
23        "DCCP-Response packet",
24        "DCCP-Data packet",
25        "DCCP-Ack packet",
26        "DCCP-DataAck packet",
27        "DCCP-CloseReq packet",
28        "DCCP-Close packet",
29        "DCCP-Reset packet",
30        "DCCP-Move packet",
31        };
32
33DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
34{
35        struct dccphdr *dccp = (struct dccphdr*)packet;
36        DISPLAYS(dccp, source," DCCP: Source %i");
37        DISPLAYS(dccp, dest," Dest %i");
38        if (len>4) {
39                printf("\n DCCP: Type %i",dccp->type);
40                if (dccp->type<sizeof(dccp_types)) {
41                        printf(" (%s)\n",dccp_types[dccp->type]);
42                } else {
43                        printf(" (Unknown)\n");
44                }
45                printf(" DCCP: CcVal %i\n",dccp->ccval);
46        }
47        else  {
48                printf("\n"); 
49                return;
50        }
51        if (len>7)
52                printf(" DCCP: Seq %u\n",dccp->seq); // htonwhat?
53        else
54                return;
55        DISPLAY(dccp, doff," DCCP: Dataoff: %i\n");
56        if (len>9)
57                printf(" DCCP: NDP %i CsLen: %i\n",dccp->ndp,dccp->cslen);
58        else {
59                return;
60        }
61        /* Should this be byteswapped??? */
62        DISPLAY(dccp, check," DCCP: Checksum: %i\n");
63        if (htons(dccp->source) < htons(dccp->dest)) 
64                decode_next(packet+dccp->doff*4,len-dccp->doff*4,"dccp",htons(dccp->source));
65        else
66                decode_next(packet+dccp->doff*4,len-dccp->doff*4,"dccp",htons(dccp->dest));
67        return;
68}
Note: See TracBrowser for help on using the repository browser.