]> git.ipfire.org Git - thirdparty/squid.git/blame - src/icmp/Icmp4.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / icmp / Icmp4.h
CommitLineData
cc192b50 1/*
bde978a6 2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
cc192b50 3 *
bbc27441
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
cc192b50 7 */
bbc27441
AJ
8
9/* DEBUG: section 37 ICMP Routines */
10
cc192b50 11#ifndef _INCLUDE_ICMPV4_H
12#define _INCLUDE_ICMPV4_H
13
b826ffb5 14#include "Icmp.h"
cc192b50 15
cc192b50 16#if HAVE_NETINET_IN_H
17#include <netinet/in.h>
18#endif
19#if HAVE_NETINET_IP_H
20#include <netinet/ip.h>
21#endif
22#if HAVE_NETINET_IP_ICMP_H
23#include <netinet/ip_icmp.h>
24#endif
25
be266cb2 26#if !_SQUID_LINUX_ && !_SQUID_WINDOWS_
17232ccf
AJ
27#define icmphdr icmp
28#define iphdr ip
29#endif
17232ccf 30
cc192b50 31/* Linux uses its own field names. */
1191b93b 32#if _SQUID_LINUX_
cc192b50 33#ifdef icmp_id
34#undef icmp_id
35#endif
36#ifdef icmp_seq
37#undef icmp_seq
38#endif
39#define icmp_type type
40#define icmp_code code
41#define icmp_cksum checksum
42#define icmp_id un.echo.id
43#define icmp_seq un.echo.sequence
44#define ip_hl ihl
45#define ip_v version
46#define ip_tos tos
47#define ip_len tot_len
48#define ip_id id
49#define ip_off frag_off
50#define ip_ttl ttl
51#define ip_p protocol
52#define ip_sum check
53#define ip_src saddr
54#define ip_dst daddr
55#endif
56
cc192b50 57/* Native Windows port doesn't have netinet support, so we emulate it.
58 At this time, Cygwin lacks icmp support in its include files, so we need
59 to use the native Windows port definitions.
60 */
61
be266cb2 62#if _SQUID_WINDOWS_
cc192b50 63#include "fde.h"
64
7aa9bb3e 65#if _SQUID_WINDOWS_
cc192b50 66
bfe8dedf 67#if HAVE_WINSOCK2_H
cc192b50 68#include <winsock2.h>
fcabe077
FC
69#elif HAVE_WINSOCK_H
70#include <winsock.h>
bfe8dedf 71#endif
cc192b50 72#include <process.h>
73
74#endif
75
76/* IP Header */
26ac0430 77typedef struct iphdr {
cc192b50 78
09aabd84 79uint8_t ip_vhl:
cc192b50 80 4; /* Length of the header in dwords */
81
09aabd84 82uint8_t version:
cc192b50 83 4; /* Version of IP */
09aabd84
FC
84 uint8_t tos; /* Type of service */
85 uint16_t total_len; /* Length of the packet in dwords */
86 uint16_t ident; /* unique identifier */
87 uint16_t flags; /* Flags */
88 uint8_t ip_ttl; /* Time to live */
89 uint8_t proto; /* Protocol number (TCP, UDP etc) */
90 uint16_t checksum; /* IP checksum */
91 uint32_t source_ip;
92 uint32_t dest_ip;
2fadd50d 93} iphdr;
cc192b50 94
95/* ICMP header */
26ac0430 96typedef struct icmphdr {
09aabd84
FC
97 uint8_t icmp_type; /* ICMP packet type */
98 uint8_t icmp_code; /* Type sub code */
99 uint16_t icmp_cksum;
100 uint16_t icmp_id;
101 uint16_t icmp_seq;
102 uint32_t timestamp; /* not part of ICMP, but we need it */
2fadd50d 103} icmphdr;
cc192b50 104
7aa9bb3e 105#endif /* _SQUID_WINDOWS_ */
cc192b50 106
107#ifndef ICMP_ECHO
108#define ICMP_ECHO 8
109#endif
110
111#ifndef ICMP_ECHOREPLY
112#define ICMP_ECHOREPLY 0
113#endif
114
115#ifndef IPPROTO_ICMP
116#define IPPROTO_ICMP 1
117#endif
118
119/* some OS apparently define icmp instead of icmphdr */
120#if !defined(icmphdr) && defined(icmp)
121#define icmphdr icmp
122#endif
123
124/* some OS apparently define ip instead of iphdr */
125#if !defined(iphdr) && defined(ip)
126#define iphdr ip
127#endif
128
129/**
130 * Class partially implementing RFC 792 - ICMP for IP version 4.
131 * Provides ECHO-REQUEST, ECHO-REPLY (secion 4.1)
132 */
b826ffb5 133class Icmp4 : public Icmp
cc192b50 134{
135public:
b826ffb5
AJ
136 Icmp4();
137 virtual ~Icmp4();
cc192b50 138
139 virtual int Open();
140
141#if USE_ICMP
b7ac5457 142 virtual void SendEcho(Ip::Address &, int, const char*, int);
cc192b50 143 virtual void Recv(void);
144#endif
145};
146
147#if USE_ICMP
148
149/// pinger helper contains one of these as a global object.
d9c252f2 150extern Icmp4 icmp4;
cc192b50 151
152#endif /* USE_ICMP && SQUID_HELPER */
153
154#endif
f53969cc 155