File: link_1.c

package info (click to toggle)
libtrace3 3.0.21-1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, stretch
  • size: 4,356 kB
  • ctags: 3,791
  • sloc: ansic: 24,422; sh: 11,372; cpp: 1,811; makefile: 464; yacc: 96; lex: 50
file content (49 lines) | stat: -rw-r--r-- 993 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
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Decoder for CHDLC frames */

#include <sys/types.h>
#include <netinet/in.h>
#include <stdio.h>
#include <inttypes.h>
#include <dlfcn.h>
#include "libtrace.h"
#include "libpacketdump.h"

typedef struct libtrace_chdlc_t {
        uint8_t address;        /** 0xF0 for unicast, 0xF8 for multicast */
        uint8_t control;        /** Always 0x00 */
        uint16_t ethertype;
} libtrace_chdlc_t;


DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
	libtrace_chdlc_t *frame = (libtrace_chdlc_t *)packet;

	printf(" CHDLC:");
	if (len >= 1)
		printf(" Address: 0x%02x", frame->address);
	else {
		printf("[|Truncated]\n");
		return;
	}
	
	if (len >= 2)
		printf(" Control: 0x%02x", frame->control);
	else {
		printf("[|Truncated]\n");
		return;
	}
	
	if (len >= 4) {
		printf(" Ethertype: 0x%04x\n", ntohs(frame->ethertype));
		decode_next(packet + 4, len - 4, "eth", 
				ntohs(frame->ethertype));
	}
	else {
		printf("[|Truncated]\n");
		return;
	}
	

	return;
}