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