File: eth_0.c

package info (click to toggle)
libtrace3 3.0.7-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,676 kB
  • ctags: 3,140
  • sloc: ansic: 20,551; sh: 10,125; cpp: 1,384; makefile: 415; yacc: 96; lex: 50
file content (46 lines) | stat: -rw-r--r-- 997 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
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <ctype.h>
#include "libpacketdump.h"

#define WIDTH 16

/* This is an example of a decoder for a protocol that we know exists, but is undocumented.
 * We dump the protocol as hex, and then skip onto the next header which we do know exists.
 */

DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
	unsigned int i=0;
	printf(" Ubiquity:");
	for(i=0;i<132; /* Nothing */ ) {
		unsigned int j;
		printf("\n ");
		for(j=0;j<WIDTH;j++) {
			if (i+j<len)
				printf(" %02x",(unsigned char)packet[i+j]);
			else
				printf("   ");
		}
		printf("    ");
		for(j=0;j<WIDTH;j++) {
			if (i+j<len)
				if (isprint((unsigned char)packet[i+j]))
					printf("%c",(unsigned char)packet[i+j]);
				else
					printf(".");
			else
				printf("   ");
		}
		if (i+WIDTH>len)
			break;
		else
			i+=WIDTH;
	}
	printf("\n");
	if (len>132)
		decode_next(packet+132,len-132,"link",4);
	return;
}