Sync usage with man page.
[netbsd-mini2440.git] / dist / ipf / lib / printpacket6.c
blob47e85537332afaa78ef669461d22934e3b41b387
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2002 by Darren Reed.
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 *
8 * Id: printpacket6.c,v 1.3.4.1 2006/06/16 17:21:13 darrenr Exp
9 */
11 #include "ipf.h"
14 * This is meant to work without the IPv6 header files being present or
15 * the inet_ntop() library.
17 void printpacket6(ip)
18 struct ip *ip;
20 u_char *buf, p;
21 u_short plen, *addrs;
22 tcphdr_t *tcp;
23 u_32_t flow;
25 buf = (u_char *)ip;
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;
33 printf("ip6/%d %d %#x %d", buf[0] & 0xf, plen, flow, p);
34 printf(" %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
35 ntohs(addrs[0]), ntohs(addrs[1]), ntohs(addrs[2]),
36 ntohs(addrs[3]), ntohs(addrs[4]), ntohs(addrs[5]),
37 ntohs(addrs[6]), ntohs(addrs[7]));
38 if (plen >= 4)
39 if (p == IPPROTO_TCP || p == IPPROTO_UDP)
40 (void)printf(",%d", ntohs(tcp->th_sport));
41 printf(" >");
42 addrs += 8;
43 printf(" %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
44 ntohs(addrs[0]), ntohs(addrs[1]), ntohs(addrs[2]),
45 ntohs(addrs[3]), ntohs(addrs[4]), ntohs(addrs[5]),
46 ntohs(addrs[6]), ntohs(addrs[7]));
47 if (plen >= 4)
48 if (p == IPPROTO_TCP || p == IPPROTO_UDP)
49 (void)printf(",%d", ntohs(tcp->th_dport));
50 putchar('\n');