4 * Copyright (C) 2012 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
14 # define IP_OFFMASK 0x3fff
19 printpacket(int dir, mb_t *m)
29 len = ntohs(((ip6_t *)ip)->ip6_plen);
31 len = ntohs(((u_short *)ip)[2]);
35 len = ntohs(ip->ip_len);
37 ASSERT(len == msgdsize(m));
39 if ((opts & OPT_HEX) == OPT_HEX) {
43 for (; m != NULL; m = m->mb_next) {
45 for (s = (u_char *)m->mb_data, i = 0; i < len; i++) {
46 PRINTF("%02x", *s++ & 0xff);
49 PRINTF("%02x", *s++ & 0xff);
69 PRINTF("%s ", IFNAME(m->mb_ifp));
71 off = ntohs(ip->ip_off);
72 tcp = (struct tcphdr *)((char *)ip + (IP_HL(ip) << 2));
73 PRINTF("ip #%d %d(%d) %d", ntohs(ip->ip_id), ntohs(ip->ip_len),
74 IP_HL(ip) << 2, ip->ip_p);
76 PRINTF(" @%d", off << 3);
77 PRINTF(" %s", inet_ntoa(ip->ip_src));
78 if (!(off & IP_OFFMASK))
79 if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP)
80 PRINTF(",%d", ntohs(tcp->th_sport));
82 PRINTF("%s", inet_ntoa(ip->ip_dst));
83 if (!(off & IP_OFFMASK)) {
84 if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP)
85 PRINTF(",%d", ntohs(tcp->th_dport));
86 if ((ip->ip_p == IPPROTO_TCP) && (tcp->th_flags != 0)) {
88 if (tcp->th_flags & TH_FIN)
90 if (tcp->th_flags & TH_SYN)
92 if (tcp->th_flags & TH_RST)
94 if (tcp->th_flags & TH_PUSH)
96 if (tcp->th_flags & TH_ACK)
98 if (tcp->th_flags & TH_URG)
100 if (tcp->th_flags & TH_ECN)
102 if (tcp->th_flags & TH_CWR)