| 1 | // |
|---|---|
| 2 | // ICMPPacket.cpp |
| 3 | // |
| 4 | // Library: Net |
| 5 | // Package: ICMP |
| 6 | // Module: ICMPPacket |
| 7 | // |
| 8 | // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. |
| 9 | // and Contributors. |
| 10 | // |
| 11 | // SPDX-License-Identifier: BSL-1.0 |
| 12 | // |
| 13 | |
| 14 | |
| 15 | #include "Poco/Net/ICMPPacket.h" |
| 16 | #include "Poco/Net/ICMPv4PacketImpl.h" |
| 17 | #include "Poco/Net/NetException.h" |
| 18 | #include "Poco/Timestamp.h" |
| 19 | #include "Poco/Timespan.h" |
| 20 | #include "Poco/NumberFormatter.h" |
| 21 | #include <sstream> |
| 22 | |
| 23 | |
| 24 | using Poco::InvalidArgumentException; |
| 25 | using Poco::NotImplementedException; |
| 26 | using Poco::Timestamp; |
| 27 | using Poco::Timespan; |
| 28 | using Poco::NumberFormatter; |
| 29 | using Poco::UInt8; |
| 30 | using Poco::UInt16; |
| 31 | using Poco::Int32; |
| 32 | |
| 33 | |
| 34 | namespace Poco { |
| 35 | namespace Net { |
| 36 | |
| 37 | |
| 38 | ICMPPacket::ICMPPacket(IPAddress::Family family, int dataSize):_pImpl(0) |
| 39 | { |
| 40 | if (family == IPAddress::IPv4) |
| 41 | _pImpl = new ICMPv4PacketImpl(dataSize); |
| 42 | #if defined(POCO_HAVE_IPv6) |
| 43 | else if (family == IPAddress::IPv6) |
| 44 | throw NotImplementedException("ICMPv6 packets not implemented."); |
| 45 | #endif |
| 46 | else throw InvalidArgumentException("Invalid or unsupported address family passed to ICMPPacket"); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | ICMPPacket::~ICMPPacket() |
| 51 | { |
| 52 | delete _pImpl; |
| 53 | } |
| 54 | |
| 55 | |
| 56 | void ICMPPacket::setDataSize(int dataSize) |
| 57 | { |
| 58 | _pImpl->setDataSize(dataSize); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | int ICMPPacket::getDataSize() const |
| 63 | { |
| 64 | return _pImpl->getDataSize(); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | int ICMPPacket::packetSize() const |
| 69 | { |
| 70 | return _pImpl->packetSize(); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | int ICMPPacket::maxPacketSize() const |
| 75 | { |
| 76 | return _pImpl->maxPacketSize(); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | const Poco::UInt8* ICMPPacket::packet() |
| 81 | { |
| 82 | return _pImpl->packet(); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | struct timeval ICMPPacket::time(Poco::UInt8* buffer, int length) const |
| 87 | { |
| 88 | return _pImpl->time(buffer, length); |
| 89 | } |
| 90 | |
| 91 | |
| 92 | bool ICMPPacket::validReplyID(Poco::UInt8* buffer, int length) const |
| 93 | { |
| 94 | return _pImpl->validReplyID(buffer, length); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | std::string ICMPPacket::errorDescription(Poco::UInt8* buffer, int length) |
| 99 | { |
| 100 | return _pImpl->errorDescription(buffer, length); |
| 101 | } |
| 102 | |
| 103 | |
| 104 | std::string ICMPPacket::typeDescription(int typeId) |
| 105 | { |
| 106 | return _pImpl->typeDescription(typeId); |
| 107 | } |
| 108 | |
| 109 | |
| 110 | } } // namespace Poco::Net |
| 111 |