printpacket6.c revision 145510
1/*	$NetBSD$	*/
2
3#include "ipf.h"
4
5/*
6 * This is meant to work without the IPv6 header files being present or
7 * the inet_ntop() library.
8 */
9void printpacket6(ip)
10struct ip *ip;
11{
12	u_char *buf, p;
13	u_short plen, *addrs;
14	tcphdr_t *tcp;
15	u_32_t flow;
16
17	buf = (u_char *)ip;
18	tcp = (tcphdr_t *)(buf + 40);
19	p = buf[6];
20	flow = ntohl(*(u_32_t *)buf);
21	flow &= 0xfffff;
22	plen = ntohs(*((u_short *)buf +2));
23	addrs = (u_short *)buf + 4;
24
25	printf("ip6/%d %d %#x %d", buf[0] & 0xf, plen, flow, p);
26	printf(" %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
27		ntohs(addrs[0]), ntohs(addrs[1]), ntohs(addrs[2]),
28		ntohs(addrs[3]), ntohs(addrs[4]), ntohs(addrs[5]),
29		ntohs(addrs[6]), ntohs(addrs[7]));
30	if (plen >= 4)
31		if (p == IPPROTO_TCP || p == IPPROTO_UDP)
32			(void)printf(",%d", ntohs(tcp->th_sport));
33	printf(" >");
34	addrs += 8;
35	printf(" %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
36		ntohs(addrs[0]), ntohs(addrs[1]), ntohs(addrs[2]),
37		ntohs(addrs[3]), ntohs(addrs[4]), ntohs(addrs[5]),
38		ntohs(addrs[6]), ntohs(addrs[7]));
39	if (plen >= 4)
40		if (p == IPPROTO_TCP || p == IPPROTO_UDP)
41			(void)printf(",%d", ntohs(tcp->th_dport));
42	putchar('\n');
43}
44