File: ip_47.c

package info (click to toggle)
libtrace3 3.0.14-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 11,492 kB
  • sloc: ansic: 21,584; sh: 10,236; cpp: 1,765; makefile: 454; yacc: 96; lex: 50
file content (36 lines) | stat: -rw-r--r-- 840 bytes parent folder | download | duplicates (5)
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
#include <sys/types.h>
#include <netinet/in.h>
#include <stdio.h>
#include "libpacketdump.h"

typedef struct gre_t {
	uint16_t flags;
	uint16_t ethertype;
	uint16_t checksum;
	uint16_t reserved1;
} gre_t;

DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
	// GRE
	if (len<2) {
		printf(" GRE: [Truncated]\n");
		return;
	}
	printf(" GRE: %s\n",
		ntohs(((gre_t*)packet)->flags) & 0x8000 
			? "Checksum present"
			: "Checksum absent");
	printf(" GRE: Version: %d\n", ntohs(((gre_t*)packet)->flags) & 0x0007);
	printf(" GRE: Protocol: %04x\n", ntohs(((gre_t*)packet)->ethertype));

	if (ntohs(((gre_t*)packet)->flags) & 0x8000) {
		decode_next(packet+4,len-4,"link",
				ntohs(((gre_t*)packet)->ethertype));
	}
	else {
		decode_next(packet+8,len-8,"link",
				ntohs(((gre_t*)packet)->ethertype));
	}
	return;
}