Icmp.cc
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#include "squid.h"
12#include "debug/Stream.h"
13#include "Icmp.h"
14#include "time/gadgets.h"
15
17{
18#if USE_ICMP
19 icmp_sock = -1;
20 icmp_ident = 0;
21#endif
22}
23
24void
26{
27#if USE_ICMP
28 if (icmp_sock > 0)
29 close(icmp_sock);
30 icmp_sock = -1;
31 icmp_ident = 0;
32#endif
33}
34
35#if USE_ICMP
36
37int
38Icmp::CheckSum(unsigned short *ptr, int size)
39{
40 long sum;
41 unsigned short oddbyte;
42 unsigned short answer;
43
44 if (!ptr) return (int)htons(0xffff); // bad input.
45
46 sum = 0;
47
48 while (size > 1) {
49 sum += *ptr;
50 ++ptr;
51 size -= 2;
52 }
53
54 if (size == 1) {
55 oddbyte = 0;
56 *((unsigned char *) &oddbyte) = *(unsigned char *) ptr;
57 sum += oddbyte;
58 }
59
60 sum = (sum >> 16) + (sum & 0xffff);
61 sum += (sum >> 16);
62 answer = (unsigned short) ~sum;
63 return (answer);
64}
65
66int
68{
69 if (ttl < 33)
70 return 33 - ttl;
71
72 if (ttl < 63)
73 return 63 - ttl; /* 62 = (64+60)/2 */
74
75 if (ttl < 65)
76 return 65 - ttl; /* 62 = (64+60)/2 */
77
78 if (ttl < 129)
79 return 129 - ttl;
80
81 if (ttl < 193)
82 return 193 - ttl;
83
84 return 256 - ttl;
85}
86
87void
88Icmp::Log(const Ip::Address &addr, const uint8_t type, const char* pkt_str, const int rtt, const int hops)
89{
90 debugs(42, 2, "pingerLog: " << current_time << " " << std::left <<
91 std::setw(45) << addr << " " << type <<
92 " " << std::setw(15) << pkt_str << " " << rtt <<
93 "ms " << hops << " hops");
94}
95
96#endif /* USE_ICMP */
97
int size
Definition: ModDevPoll.cc:75
virtual void Close()
Shutdown pinger helper and control channel.
Definition: Icmp.cc:25
int CheckSum(unsigned short *ptr, int size)
Calculate a packet checksum.
Definition: Icmp.cc:38
int icmp_ident
Definition: Icmp.h:122
void Log(const Ip::Address &addr, const uint8_t type, const char *pkt_str, const int rtt, const int hops)
Log the packet.
Definition: Icmp.cc:88
int icmp_sock
Definition: Icmp.h:121
Icmp()
Definition: Icmp.cc:16
int ipHops(int ttl)
Definition: Icmp.cc:67
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:196
int type
Definition: errorpage.cc:152
struct timeval current_time
the current UNIX time in timeval {seconds, microseconds} format
Definition: gadgets.cc:17

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors