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
14 # define IP_OFFMASK 0x3fff
27 len
= ntohs(((u_short
*)ip
)[2]) + 40;
29 off
= ntohs(ip
->ip_off
);
30 len
= ntohs(ip
->ip_len
);
33 if ((opts
& OPT_HEX
) == OPT_HEX
) {
37 for (s
= (u_char
*)ip
, i
= 0; i
< len
; i
++) {
38 printf("%02x", *s
++ & 0xff);
41 printf("%02x", *s
++ & 0xff);
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
);
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
));
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)) {
71 if (tcp
->th_flags
& TH_FIN
)
73 if (tcp
->th_flags
& TH_SYN
)
75 if (tcp
->th_flags
& TH_RST
)
77 if (tcp
->th_flags
& TH_PUSH
)
79 if (tcp
->th_flags
& TH_ACK
)
81 if (tcp
->th_flags
& TH_URG
)
83 if (tcp
->th_flags
& TH_ECN
)
85 if (tcp
->th_flags
& TH_CWR
)