File: eth_34525.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 (35 lines) | stat: -rw-r--r-- 1,061 bytes parent folder | download | duplicates (4)
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
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include "libpacketdump.h"
#ifndef WIN32
	#include <netinet/in_systm.h>
#endif
#include <arpa/inet.h>
#include <netdb.h>

DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
{
	libtrace_ip6_t *ip = (libtrace_ip6_t*)packet;
	
	uint32_t tmp = ntohl(*(uint32_t*)ip);

	printf(" IPv6: Version %u\n", (tmp >> 28) & 0x000000f);
	printf(" IPv6: Class %u\n", (tmp >> 20) & 0x000000ff);
	printf(" IPv6: Flow Label %u\n", tmp & 0x000fffff);
	printf(" IPv6: Payload Length %u\n", ntohs(ip->plen));
	printf(" IPv6: Next Header %u\n", ip->nxt);
	printf(" IPv6: Hop Limit %u\n", ip->hlim);


	char ipstr[INET6_ADDRSTRLEN];                             
	inet_ntop(AF_INET6, &(ip->ip_src), ipstr, INET6_ADDRSTRLEN);

	printf(" IPv6: Source IP %s\n", ipstr);
	inet_ntop(AF_INET6, &(ip->ip_dst), ipstr, INET6_ADDRSTRLEN);
	printf(" IPv6: Destination IP %s\n", ipstr);

	decode_next(packet+sizeof(libtrace_ip6_t),len-sizeof(libtrace_ip6_t),"ip",ip->nxt);
	return;
}