xref: /freebsd/sbin/ipf/libipf/printpacket6.c (revision 1323ec57)
1 /*	$FreeBSD$	*/
2 
3 /*
4  * Copyright (C) 2012 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  *
8  * $Id$
9  */
10 
11 #include "ipf.h"
12 
13 /*
14  * This is meant to work without the IPv6 header files being present or
15  * the inet_ntop() library.
16  */
17 void
18 printpacket6(int dir, mb_t *m)
19 {
20 	u_char *buf, p;
21 	u_short plen, *addrs;
22 	tcphdr_t *tcp;
23 	u_32_t flow;
24 
25 	buf = (u_char *)m->mb_data;
26 	tcp = (tcphdr_t *)(buf + 40);
27 	p = buf[6];
28 	flow = ntohl(*(u_32_t *)buf);
29 	flow &= 0xfffff;
30 	plen = ntohs(*((u_short *)buf +2));
31 	addrs = (u_short *)buf + 4;
32 
33 	if (dir)
34 		PRINTF("> ");
35 	else
36 		PRINTF("< ");
37 
38 	PRINTF("%s ", IFNAME(m->mb_ifp));
39 
40 	PRINTF("ip6/%d %d %#x %d", buf[0] & 0xf, plen, flow, p);
41 	PRINTF(" %x:%x:%x:%x:%x:%x:%x:%x",
42 		ntohs(addrs[0]), ntohs(addrs[1]), ntohs(addrs[2]),
43 		ntohs(addrs[3]), ntohs(addrs[4]), ntohs(addrs[5]),
44 		ntohs(addrs[6]), ntohs(addrs[7]));
45 	if (plen >= 4)
46 		if (p == IPPROTO_TCP || p == IPPROTO_UDP)
47 			(void)PRINTF(",%d", ntohs(tcp->th_sport));
48 	PRINTF(" >");
49 	addrs += 8;
50 	PRINTF(" %x:%x:%x:%x:%x:%x:%x:%x",
51 		ntohs(addrs[0]), ntohs(addrs[1]), ntohs(addrs[2]),
52 		ntohs(addrs[3]), ntohs(addrs[4]), ntohs(addrs[5]),
53 		ntohs(addrs[6]), ntohs(addrs[7]));
54 	if (plen >= 4)
55 		if (p == IPPROTO_TCP || p == IPPROTO_UDP)
56 			PRINTF(",%d", ntohs(tcp->th_dport));
57 	putchar('\n');
58 }
59