]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ipfilter/lib/printpacket6.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / ipfilter / lib / printpacket6.c
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(dir, m)
19         int dir;
20         mb_t *m;
21 {
22         u_char *buf, p;
23         u_short plen, *addrs;
24         tcphdr_t *tcp;
25         u_32_t flow;
26
27         buf = (u_char *)m->mb_data;
28         tcp = (tcphdr_t *)(buf + 40);
29         p = buf[6];
30         flow = ntohl(*(u_32_t *)buf);
31         flow &= 0xfffff;
32         plen = ntohs(*((u_short *)buf +2));
33         addrs = (u_short *)buf + 4;
34
35         if (dir)
36                 PRINTF("> ");
37         else
38                 PRINTF("< ");
39
40         PRINTF("%s ", IFNAME(m->mb_ifp));
41
42         PRINTF("ip6/%d %d %#x %d", buf[0] & 0xf, plen, flow, p);
43         PRINTF(" %x:%x:%x:%x:%x:%x:%x:%x",
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_sport));
50         PRINTF(" >");
51         addrs += 8;
52         PRINTF(" %x:%x:%x:%x:%x:%x:%x:%x",
53                 ntohs(addrs[0]), ntohs(addrs[1]), ntohs(addrs[2]),
54                 ntohs(addrs[3]), ntohs(addrs[4]), ntohs(addrs[5]),
55                 ntohs(addrs[6]), ntohs(addrs[7]));
56         if (plen >= 4)
57                 if (p == IPPROTO_TCP || p == IPPROTO_UDP)
58                         PRINTF(",%d", ntohs(tcp->th_dport));
59         putchar('\n');
60 }