]>
Commit | Line | Data |
---|---|---|
cc192b50 | 1 | /* |
262a0e14 | 2 | * $Id$ |
cc192b50 | 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" | |
b826ffb5 | 38 | #include "Icmp.h" |
cc192b50 | 39 | |
cc192b50 | 40 | #if HAVE_NETINET_IN_H |
41 | #include <netinet/in.h> | |
42 | #endif | |
43 | #if HAVE_NETINET_IP_H | |
44 | #include <netinet/ip.h> | |
45 | #endif | |
46 | #if HAVE_NETINET_IP_ICMP_H | |
47 | #include <netinet/ip_icmp.h> | |
48 | #endif | |
49 | ||
17232ccf AJ |
50 | #ifndef _SQUID_LINUX_ |
51 | #ifndef _SQUID_CYGWIN_ | |
52 | #ifndef _SQUID_MSWIN_ | |
53 | #define icmphdr icmp | |
54 | #define iphdr ip | |
55 | #endif | |
56 | #endif | |
57 | #endif | |
58 | ||
cc192b50 | 59 | /* Linux uses its own field names. */ |
60 | #if defined (_SQUID_LINUX_) | |
61 | #ifdef icmp_id | |
62 | #undef icmp_id | |
63 | #endif | |
64 | #ifdef icmp_seq | |
65 | #undef icmp_seq | |
66 | #endif | |
67 | #define icmp_type type | |
68 | #define icmp_code code | |
69 | #define icmp_cksum checksum | |
70 | #define icmp_id un.echo.id | |
71 | #define icmp_seq un.echo.sequence | |
72 | #define ip_hl ihl | |
73 | #define ip_v version | |
74 | #define ip_tos tos | |
75 | #define ip_len tot_len | |
76 | #define ip_id id | |
77 | #define ip_off frag_off | |
78 | #define ip_ttl ttl | |
79 | #define ip_p protocol | |
80 | #define ip_sum check | |
81 | #define ip_src saddr | |
82 | #define ip_dst daddr | |
83 | #endif | |
84 | ||
85 | ||
86 | /* Native Windows port doesn't have netinet support, so we emulate it. | |
87 | At this time, Cygwin lacks icmp support in its include files, so we need | |
88 | to use the native Windows port definitions. | |
89 | */ | |
90 | ||
91 | #ifdef _SQUID_WIN32_ | |
92 | ||
93 | #include "fde.h" | |
94 | ||
95 | #ifdef _SQUID_MSWIN_ | |
96 | ||
bfe8dedf | 97 | #if HAVE_WINSOCK2_H |
cc192b50 | 98 | #include <winsock2.h> |
bfe8dedf | 99 | #endif |
cc192b50 | 100 | #include <process.h> |
101 | ||
102 | #endif | |
103 | ||
104 | /* IP Header */ | |
26ac0430 | 105 | typedef struct iphdr { |
cc192b50 | 106 | |
107 | u_int8_t ip_vhl: | |
108 | 4; /* Length of the header in dwords */ | |
109 | ||
110 | u_int8_t version: | |
111 | 4; /* Version of IP */ | |
112 | u_int8_t tos; /* Type of service */ | |
113 | u_int16_t total_len; /* Length of the packet in dwords */ | |
114 | u_int16_t ident; /* unique identifier */ | |
115 | u_int16_t flags; /* Flags */ | |
116 | u_int8_t ip_ttl; /* Time to live */ | |
117 | u_int8_t proto; /* Protocol number (TCP, UDP etc) */ | |
118 | u_int16_t checksum; /* IP checksum */ | |
119 | u_int32_t source_ip; | |
120 | u_int32_t dest_ip; | |
2fadd50d | 121 | } iphdr; |
cc192b50 | 122 | |
123 | /* ICMP header */ | |
26ac0430 | 124 | typedef struct icmphdr { |
cc192b50 | 125 | u_int8_t icmp_type; /* ICMP packet type */ |
126 | u_int8_t icmp_code; /* Type sub code */ | |
127 | u_int16_t icmp_cksum; | |
128 | u_int16_t icmp_id; | |
129 | u_int16_t icmp_seq; | |
130 | u_int32_t timestamp; /* not part of ICMP, but we need it */ | |
2fadd50d | 131 | } icmphdr; |
cc192b50 | 132 | |
133 | #endif /* _SQUID_MSWIN_ */ | |
134 | ||
135 | #ifndef ICMP_ECHO | |
136 | #define ICMP_ECHO 8 | |
137 | #endif | |
138 | ||
139 | #ifndef ICMP_ECHOREPLY | |
140 | #define ICMP_ECHOREPLY 0 | |
141 | #endif | |
142 | ||
143 | #ifndef IPPROTO_ICMP | |
144 | #define IPPROTO_ICMP 1 | |
145 | #endif | |
146 | ||
147 | /* some OS apparently define icmp instead of icmphdr */ | |
148 | #if !defined(icmphdr) && defined(icmp) | |
149 | #define icmphdr icmp | |
150 | #endif | |
151 | ||
152 | /* some OS apparently define ip instead of iphdr */ | |
153 | #if !defined(iphdr) && defined(ip) | |
154 | #define iphdr ip | |
155 | #endif | |
156 | ||
157 | /** | |
158 | * Class partially implementing RFC 792 - ICMP for IP version 4. | |
159 | * Provides ECHO-REQUEST, ECHO-REPLY (secion 4.1) | |
160 | */ | |
b826ffb5 | 161 | class Icmp4 : public Icmp |
cc192b50 | 162 | { |
163 | public: | |
b826ffb5 AJ |
164 | Icmp4(); |
165 | virtual ~Icmp4(); | |
cc192b50 | 166 | |
167 | virtual int Open(); | |
168 | ||
169 | #if USE_ICMP | |
b7ac5457 | 170 | virtual void SendEcho(Ip::Address &, int, const char*, int); |
cc192b50 | 171 | virtual void Recv(void); |
172 | #endif | |
173 | }; | |
174 | ||
175 | #if USE_ICMP | |
176 | ||
177 | /// pinger helper contains one of these as a global object. | |
b826ffb5 | 178 | SQUIDCEXTERN Icmp4 icmp4; |
cc192b50 | 179 | |
180 | #endif /* USE_ICMP && SQUID_HELPER */ | |
181 | ||
182 | #endif |