2 * Copyright (C) 1993-2002 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 #if defined(__sgi) && (IRIX > 602)
7 # include <sys/ptimers.h>
10 # define _SYS_VARARGS_H
21 #include <sys/types.h>
22 #if !defined(__SVR4) && !defined(__svr4__)
25 #include <sys/byteorder.h>
27 #include <sys/param.h>
32 #include <sys/socket.h>
33 #include <sys/ioctl.h>
34 #include <netinet/in.h>
35 #include <arpa/inet.h>
36 #include <netinet/in_systm.h>
38 #include <netinet/ip_var.h>
40 #include <netinet/ip.h>
41 #include <netinet/udp.h>
42 #include <netinet/tcp.h>
43 #include <netinet/ip_icmp.h>
46 #include <arpa/nameser.h>
48 #include "ip_compat.h"
49 #include <netinet/tcpip.h>
55 static const char sccsid[] = "@(#)misc.c 1.3 2/4/96 (C) 1995 Darren Reed";
56 static const char rcsid[] = "@(#)$Id: misc.c,v 2.2.2.9 2002/12/06 11:40:27 darrenr Exp $";
69 len = ntohs(ip->ip_len);
70 else if (ip->ip_v == 6)
71 len = ntohs(((u_short *)ip)[2]) + 40;
75 if ((opts & OPT_HEX) == OPT_HEX) {
79 for (s = (u_char *)ip, i = 0; i < len; i++) {
80 printf("%02x", *s++ & 0xff);
83 printf("%02x", *s++ & 0xff);
97 tcp = (struct tcphdr *)((char *)ip + (ip->ip_hl << 2));
98 printf("ip %d(%d) %d", ntohs(ip->ip_len), ip->ip_hl << 2, ip->ip_p);
99 if (ip->ip_off & IP_OFFMASK)
100 printf(" @%d", ip->ip_off << 3);
101 (void)printf(" %s", inet_ntoa(ip->ip_src));
102 if (!(ip->ip_off & IP_OFFMASK))
103 if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP)
104 (void)printf(",%d", ntohs(tcp->th_sport));
106 (void)printf("%s", inet_ntoa(ip->ip_dst));
107 if (!(ip->ip_off & IP_OFFMASK)) {
108 if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP)
109 (void)printf(",%d", ntohs(tcp->th_dport));
110 if ((ip->ip_p == IPPROTO_TCP) && (tcp->th_flags)) {
112 if (tcp->th_flags & TH_FIN)
114 if (tcp->th_flags & TH_SYN)
116 if (tcp->th_flags & TH_RST)
118 if (tcp->th_flags & TH_PUSH)
120 if (tcp->th_flags & TH_ACK)
122 if (tcp->th_flags & TH_URG)
124 if (tcp->th_flags & TH_ECN)
126 if (tcp->th_flags & TH_CWR)
135 * This is meant to work without the IPv6 header files being present or
136 * the inet_ntop() library.
138 void printpacket6(ip)
141 u_char *buf, p, hops;
142 u_short plen, *addrs;
147 tcp = (tcphdr_t *)(buf + 40);
150 flow = ntohl(*(u_32_t *)buf);
152 plen = ntohs(*((u_short *)buf +2));
153 addrs = (u_short *)buf + 4;
155 printf("ip6/%d %d %#x %d", buf[0] & 0xf, plen, flow, p);
156 printf(" %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
157 ntohs(addrs[0]), ntohs(addrs[1]), ntohs(addrs[2]),
158 ntohs(addrs[3]), ntohs(addrs[4]), ntohs(addrs[5]),
159 ntohs(addrs[6]), ntohs(addrs[7]));
161 if (p == IPPROTO_TCP || p == IPPROTO_UDP)
162 (void)printf(",%d", ntohs(tcp->th_sport));
165 printf(" %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
166 ntohs(addrs[0]), ntohs(addrs[1]), ntohs(addrs[2]),
167 ntohs(addrs[3]), ntohs(addrs[4]), ntohs(addrs[5]),
168 ntohs(addrs[6]), ntohs(addrs[7]));
170 if (p == IPPROTO_TCP || p == IPPROTO_UDP)
171 (void)printf(",%d", ntohs(tcp->th_dport));
176 #if defined(__STDC__)
177 void verbose(char *fmt, ...)
179 void verbose(fmt, va_alist)
187 if (opts & OPT_VERBOSE)
194 void debug(char *fmt, ...)
196 void debug(fmt, va_alist)
204 if (opts & OPT_DEBUG)