Icmp4.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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#include <process.h>
67#endif
68
69/* IP Header */
70typedef struct iphdr {
71
72uint8_t ip_vhl:
73 4; /* Length of the header in dwords */
74
75uint8_t version:
76 4; /* Version of IP */
77 uint8_t tos; /* Type of service */
78 uint16_t total_len; /* Length of the packet in dwords */
79 uint16_t ident; /* unique identifier */
80 uint16_t flags; /* Flags */
81 uint8_t ip_ttl; /* Time to live */
82 uint8_t proto; /* Protocol number (TCP, UDP etc) */
83 uint16_t checksum; /* IP checksum */
84 uint32_t source_ip;
85 uint32_t dest_ip;
86} iphdr;
87
88/* ICMP header */
89typedef struct icmphdr {
90 uint8_t icmp_type; /* ICMP packet type */
91 uint8_t icmp_code; /* Type sub code */
92 uint16_t icmp_cksum;
93 uint16_t icmp_id;
94 uint16_t icmp_seq;
95 uint32_t timestamp; /* not part of ICMP, but we need it */
96} icmphdr;
97
98#endif /* _SQUID_WINDOWS_ */
99
100#ifndef ICMP_ECHO
101#define ICMP_ECHO 8
102#endif
103
104#ifndef ICMP_ECHOREPLY
105#define ICMP_ECHOREPLY 0
106#endif
107
108#ifndef IPPROTO_ICMP
109#define IPPROTO_ICMP 1
110#endif
111
112/* some OS apparently define icmp instead of icmphdr */
113#if !defined(icmphdr) && defined(icmp)
114#define icmphdr icmp
115#endif
116
117/* some OS apparently define ip instead of iphdr */
118#if !defined(iphdr) && defined(ip)
119#define iphdr ip
120#endif
121
126class Icmp4 : public Icmp
127{
128public:
129 Icmp4();
130 ~Icmp4() override;
131
132 int Open() override;
133
134#if USE_ICMP
135 void SendEcho(Ip::Address &, int, const char*, int) override;
136 void Recv(void) override;
137#endif
138};
139
140#if USE_ICMP
141
143extern Icmp4 icmp4;
144
145#endif /* USE_ICMP && SQUID_HELPER */
146
147#endif
148
#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:127
Icmp4()
Definition: Icmp4.cc:55
void SendEcho(Ip::Address &, int, const char *, int) override
Definition: Icmp4.cc:83
void Recv(void) override
Handle ICMP responses.
Definition: Icmp4.cc:156
~Icmp4() override
Definition: Icmp4.cc:60
int Open() override
Start pinger helper and initiate control channel.
Definition: Icmp4.cc:66
Definition: Icmp.h:68

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors