Sync usage with man page.
[netbsd-mini2440.git] / dist / ipf / lib / printpacket.c
bloba1db1654c79939eaa3969eec28968f45c86ad6b7
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2000-2005 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * Id: printpacket.c,v 1.12.4.5 2007/09/09 22:15:30 darrenr Exp
9 */
11 #include "ipf.h"
13 #ifndef IP_OFFMASK
14 # define IP_OFFMASK 0x3fff
15 #endif
18 void printpacket(ip)
19 struct ip *ip;
21 struct tcphdr *tcp;
22 u_short len;
23 u_short off;
25 if (IP_V(ip) == 6) {
26 off = 0;
27 len = ntohs(((u_short *)ip)[2]) + 40;
28 } else {
29 off = ntohs(ip->ip_off);
30 len = ntohs(ip->ip_len);
33 if ((opts & OPT_HEX) == OPT_HEX) {
34 u_char *s;
35 int i;
37 for (s = (u_char *)ip, i = 0; i < len; i++) {
38 printf("%02x", *s++ & 0xff);
39 if (len - i > 1) {
40 i++;
41 printf("%02x", *s++ & 0xff);
43 putchar(' ');
45 putchar('\n');
46 putchar('\n');
47 return;
50 if (IP_V(ip) == 6) {
51 printpacket6(ip);
52 return;
55 tcp = (struct tcphdr *)((char *)ip + (IP_HL(ip) << 2));
56 printf("ip #%d %d(%d) %d", ntohs(ip->ip_id), ntohs(ip->ip_len),
57 IP_HL(ip) << 2, ip->ip_p);
58 if (off & IP_OFFMASK)
59 printf(" @%d", (off & IP_OFFMASK) << 3);
60 printf(" %s", inet_ntoa(ip->ip_src));
61 if (!(off & IP_OFFMASK))
62 if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP)
63 printf(",%d", ntohs(tcp->th_sport));
64 printf(" > ");
65 printf("%s", inet_ntoa(ip->ip_dst));
66 if (!(off & IP_OFFMASK)) {
67 if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP)
68 printf(",%d", ntohs(tcp->th_dport));
69 if ((ip->ip_p == IPPROTO_TCP) && (tcp->th_flags != 0)) {
70 putchar(' ');
71 if (tcp->th_flags & TH_FIN)
72 putchar('F');
73 if (tcp->th_flags & TH_SYN)
74 putchar('S');
75 if (tcp->th_flags & TH_RST)
76 putchar('R');
77 if (tcp->th_flags & TH_PUSH)
78 putchar('P');
79 if (tcp->th_flags & TH_ACK)
80 putchar('A');
81 if (tcp->th_flags & TH_URG)
82 putchar('U');
83 if (tcp->th_flags & TH_ECN)
84 putchar('E');
85 if (tcp->th_flags & TH_CWR)
86 putchar('C');
90 putchar('\n');