Icmp4.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9/* DEBUG: section 37 ICMP Routines */
10
11#ifndef _INCLUDE_ICMPV4_H
12#define _INCLUDE_ICMPV4_H
13
14#include "Icmp.h"
15
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
26#if !_SQUID_LINUX_ && !_SQUID_WINDOWS_
27#define icmphdr icmp
28#define iphdr ip
29#endif
30
31/* Linux uses its own field names. */
32#if _SQUID_LINUX_
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
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
62#if _SQUID_WINDOWS_
63#include "fde.h"
64
65#if _SQUID_WINDOWS_
66
67#if HAVE_WINSOCK2_H
68#include <winsock2.h>
69#elif HAVE_WINSOCK_H
70#include <winsock.h>
71#endif
72#include <process.h>
73
74#endif
75
76/* IP Header */
77typedef struct iphdr {
78
79uint8_t ip_vhl:
80 4; /* Length of the header in dwords */
81
82uint8_t version:
83 4; /* Version of IP */
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;
93} iphdr;
94
95/* ICMP header */
96typedef struct icmphdr {
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 */
103} icmphdr;
104
105#endif /* _SQUID_WINDOWS_ */
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
133class Icmp4 : public Icmp
134{
135public:
136 Icmp4();
137 virtual ~Icmp4();
138
139 virtual int Open();
140
141#if USE_ICMP
142 virtual void SendEcho(Ip::Address &, int, const char*, int);
143 virtual void Recv(void);
144#endif
145};
146
147#if USE_ICMP
148
150extern Icmp4 icmp4;
151
152#endif /* USE_ICMP && SQUID_HELPER */
153
154#endif
155
#define iphdr
Definition: Icmp4.h:28
#define icmphdr
Definition: Icmp4.h:27
Icmp4 icmp4
pinger helper contains one of these as a global object.
Definition: pinger.cc:91
static int version
Definition: Icmp4.h:134
virtual void Recv(void)
Handle ICMP responses.
Definition: Icmp4.cc:156
virtual int Open()
Start pinger helper and initiate control channel.
Definition: Icmp4.cc:66
virtual void SendEcho(Ip::Address &, int, const char *, int)
Definition: Icmp4.cc:83
Icmp4()
Definition: Icmp4.cc:55
virtual ~Icmp4()
Definition: Icmp4.cc:60
Definition: Icmp.h:68

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors