Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
ICMP.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
7#include "Stroika/Foundation/IO/Network/HTTP/Headers.h"
8
9#include "ICMP.h"
10
11using namespace Stroika::Foundation;
14using namespace Stroika::Foundation::IO::Network::InternetProtocol;
15
16namespace {
17 String mkMessage_ (unsigned short code)
18 {
19 // from @see https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol - Destination unreachable message
20 switch (code) {
21 case 0:
22 return "ICMP Destination Unreachable: Network unreachable error."sv;
23 case 1:
24 return "ICMP Destination Unreachable: Host unreachable error."sv;
25 case 2:
26 return "ICMP Destination Unreachable: Protocol unreachable error (the designated transport protocol is not supported)."sv;
27 case 3:
28 return "ICMP Destination Unreachable: Destination port unreachable."sv;
29 case 4:
30 return "ICMP Destination Unreachable: Fragmentation required, and DF flag set."sv;
31 case 5:
32 return "ICMP Destination Unreachable: Source route failed."sv;
33 case 6:
34 return "ICMP Destination Unreachable: Destination network unknown."sv;
35 case 7:
36 return "ICMP Destination Unreachable: Destination host unknown."sv;
37 case 8:
38 return "ICMP Destination Unreachable: Source host isolated."sv;
39 case 9:
40 return "ICMP Destination Unreachable: Network administratively prohibited."sv;
41 case 10:
42 return "ICMP Destination Unreachable: Host administratively prohibited."sv;
43 case 11:
44 return "ICMP Destination Unreachable: Network unreachable for ToS."sv;
45 case 12:
46 return "ICMP Destination Unreachable: Host unreachable for ToS."sv;
47 case 13:
48 return "ICMP Destination Unreachable: Communication administratively prohibited."sv;
49 case 14:
50 return "ICMP Destination Unreachable: Host Precedence Violation."sv;
51 case 15:
52 return "ICMP Destination Unreachable: Precedence cutoff in effect."sv;
53 default:
54 return "ICMP Destination Unreachable: code {}."_f(code);
55 }
56 }
57}
58
59/*
60 ********************************************************************************
61 ***** InternetProtocol::ICMP::V4::DestinationUnreachableException **************
62 ********************************************************************************
63 */
64InternetProtocol::ICMP::V4::DestinationUnreachableException::DestinationUnreachableException (uint8_t code, const InternetAddress& unreachedIP)
65 : inherited{mkMessage_ (code)}
66 , fCode_{code}
67 , fUnreachedIP_{unreachedIP}
68{
69}
70
71/*
72 ********************************************************************************
73 **************** InternetProtocol::ICMP::V4::UnknownICMPPacket *****************
74 ********************************************************************************
75 */
76InternetProtocol::ICMP::V4::UnknownICMPPacket::UnknownICMPPacket (ICMP_PacketTypes type)
77 : inherited{"ICMP Unknown packet type: {}."_f(type)}
78 , fType_{type}
79{
80}
81
82/*
83 ********************************************************************************
84 ************* InternetProtocol::ICMP::V4::TTLExpiredException ******************
85 ********************************************************************************
86 */
87InternetProtocol::ICMP::V4::TTLExpiredException::TTLExpiredException (const InternetAddress& unreachedIP)
88 : inherited{"ICMP TTL Expired."sv}
89 , fUnreachedIP_{unreachedIP}
90{
91}
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201