]> git.ipfire.org Git - thirdparty/squid.git/blob - src/icmp/Icmp4.h
Merge from trunk
[thirdparty/squid.git] / src / icmp / Icmp4.h
1 /*
2 * $Id: ICMPv4.h,v 1.1 2007/12/14 23:11:45 amosjeffries Exp $
3 *
4 * DEBUG: section 37 ICMP Routines
5 * AUTHOR: Duane Wessels, Amos Jeffries
6 *
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 *
33 */
34 #ifndef _INCLUDE_ICMPV4_H
35 #define _INCLUDE_ICMPV4_H
36
37 #include "config.h"
38 #include "Icmp.h"
39 #include "IPAddress.h"
40
41 #if HAVE_NETINET_IN_SYSTM_H
42 #include <netinet/in_systm.h>
43 #endif
44 #if HAVE_NETINET_IN_H
45 #include <netinet/in.h>
46 #endif
47 #if HAVE_NETINET_IP_H
48 #include <netinet/ip.h>
49 #endif
50 #if HAVE_NETINET_IP_ICMP_H
51 #include <netinet/ip_icmp.h>
52 #endif
53
54 #ifndef _SQUID_LINUX_
55 #ifndef _SQUID_CYGWIN_
56 #ifndef _SQUID_MSWIN_
57 #define icmphdr icmp
58 #define iphdr ip
59 #endif
60 #endif
61 #endif
62
63 /* Linux uses its own field names. */
64 #if defined (_SQUID_LINUX_)
65 #ifdef icmp_id
66 #undef icmp_id
67 #endif
68 #ifdef icmp_seq
69 #undef icmp_seq
70 #endif
71 #define icmp_type type
72 #define icmp_code code
73 #define icmp_cksum checksum
74 #define icmp_id un.echo.id
75 #define icmp_seq un.echo.sequence
76 #define ip_hl ihl
77 #define ip_v version
78 #define ip_tos tos
79 #define ip_len tot_len
80 #define ip_id id
81 #define ip_off frag_off
82 #define ip_ttl ttl
83 #define ip_p protocol
84 #define ip_sum check
85 #define ip_src saddr
86 #define ip_dst daddr
87 #endif
88
89
90 /* Native Windows port doesn't have netinet support, so we emulate it.
91 At this time, Cygwin lacks icmp support in its include files, so we need
92 to use the native Windows port definitions.
93 */
94
95 #ifdef _SQUID_WIN32_
96
97 #include "fde.h"
98
99 #ifdef _SQUID_MSWIN_
100
101 #if HAVE_WINSOCK2_H
102 #include <winsock2.h>
103 #endif
104 #include <process.h>
105
106 #endif
107
108 /* IP Header */
109 typedef struct iphdr {
110
111 u_int8_t ip_vhl:
112 4; /* Length of the header in dwords */
113
114 u_int8_t version:
115 4; /* Version of IP */
116 u_int8_t tos; /* Type of service */
117 u_int16_t total_len; /* Length of the packet in dwords */
118 u_int16_t ident; /* unique identifier */
119 u_int16_t flags; /* Flags */
120 u_int8_t ip_ttl; /* Time to live */
121 u_int8_t proto; /* Protocol number (TCP, UDP etc) */
122 u_int16_t checksum; /* IP checksum */
123 u_int32_t source_ip;
124 u_int32_t dest_ip;
125 } iphdr;
126
127 /* ICMP header */
128 typedef struct icmphdr {
129 u_int8_t icmp_type; /* ICMP packet type */
130 u_int8_t icmp_code; /* Type sub code */
131 u_int16_t icmp_cksum;
132 u_int16_t icmp_id;
133 u_int16_t icmp_seq;
134 u_int32_t timestamp; /* not part of ICMP, but we need it */
135 } icmphdr;
136
137 #endif /* _SQUID_MSWIN_ */
138
139 #ifndef ICMP_ECHO
140 #define ICMP_ECHO 8
141 #endif
142
143 #ifndef ICMP_ECHOREPLY
144 #define ICMP_ECHOREPLY 0
145 #endif
146
147 #ifndef IPPROTO_ICMP
148 #define IPPROTO_ICMP 1
149 #endif
150
151 /* some OS apparently define icmp instead of icmphdr */
152 #if !defined(icmphdr) && defined(icmp)
153 #define icmphdr icmp
154 #endif
155
156 /* some OS apparently define ip instead of iphdr */
157 #if !defined(iphdr) && defined(ip)
158 #define iphdr ip
159 #endif
160
161 /**
162 * Class partially implementing RFC 792 - ICMP for IP version 4.
163 * Provides ECHO-REQUEST, ECHO-REPLY (secion 4.1)
164 */
165 class Icmp4 : public Icmp
166 {
167 public:
168 Icmp4();
169 virtual ~Icmp4();
170
171 virtual int Open();
172
173 #if USE_ICMP
174 virtual void SendEcho(IPAddress &, int, const char*, int);
175 virtual void Recv(void);
176 #endif
177 };
178
179 #if USE_ICMP
180
181 /// pinger helper contains one of these as a global object.
182 SQUIDCEXTERN Icmp4 icmp4;
183
184 #endif /* USE_ICMP && SQUID_HELPER */
185
186 #endif