File: ip_33.c

package info (click to toggle)
libtrace3 3.0.22-0.2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,452 kB
  • sloc: ansic: 24,574; sh: 11,372; cpp: 1,811; makefile: 460; yacc: 96; lex: 50
file content (68 lines) | stat: -rw-r--r-- 1,562 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* DCCP */
#include <stdio.h>
#include <inttypes.h>
#include <dlfcn.h>
#include "libpacketdump.h"
#include <netinet/tcp.h>
#include <netinet/in.h>

struct dccphdr {
	uint16_t source;
	uint16_t dest;
	uint8_t type:4;
	uint8_t ccval:4;
	uint32_t seq:24;
	uint8_t doff;
	uint8_t ndp:4;
	uint8_t cslen:4;
	uint16_t check;
};

static char *dccp_types[]={
	"DCCP-Request packet",
	"DCCP-Response packet",
	"DCCP-Data packet",
	"DCCP-Ack packet",
	"DCCP-DataAck packet",
	"DCCP-CloseReq packet",
	"DCCP-Close packet",
	"DCCP-Reset packet",
	"DCCP-Move packet",
	};

DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
	struct dccphdr *dccp = (struct dccphdr*)packet;
	DISPLAYS(dccp, source," DCCP: Source %i");
	DISPLAYS(dccp, dest," Dest %i");
	if (len>4) {
		printf("\n DCCP: Type %i",dccp->type);
		if (dccp->type<sizeof(dccp_types)) {
			printf(" (%s)\n",dccp_types[dccp->type]);
		} else {
			printf(" (Unknown)\n");
		}
		printf(" DCCP: CcVal %i\n",dccp->ccval);
	}
	else  {
		printf("\n"); 
		return;
	}
	if (len>7)
		printf(" DCCP: Seq %u\n",dccp->seq); // htonwhat?
	else
		return;
	DISPLAY(dccp, doff," DCCP: Dataoff: %i\n");
	if (len>9)
		printf(" DCCP: NDP %i CsLen: %i\n",dccp->ndp,dccp->cslen);
	else {
		return;
	}
	/* Should this be byteswapped??? */
        DISPLAY(dccp, check," DCCP: Checksum: %i\n");
	if (htons(dccp->source) < htons(dccp->dest)) 
		decode_next(packet+dccp->doff*4,len-dccp->doff*4,"dccp",htons(dccp->source));
	else
		decode_next(packet+dccp->doff*4,len-dccp->doff*4,"dccp",htons(dccp->dest));
	return;
}