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