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