]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/ipfilter/lib/printpacket6.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / ipfilter / lib / printpacket6.c
1 /*      $FreeBSD$       */
2
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  */     
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 printpacket6(ip)
18 struct ip *ip;
19 {
20         u_char *buf, p;
21         u_short plen, *addrs;
22         tcphdr_t *tcp;
23         u_32_t flow;
24
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;
32
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');
51 }