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