| 1 | // |
| 2 | // ICMPPacket.h |
| 3 | // |
| 4 | // Library: Net |
| 5 | // Package: ICMP |
| 6 | // Module: ICMPPacket |
| 7 | // |
| 8 | // Definition of the ICMPPacket class. |
| 9 | // |
| 10 | // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. |
| 11 | // and Contributors. |
| 12 | // |
| 13 | // SPDX-License-Identifier: BSL-1.0 |
| 14 | // |
| 15 | |
| 16 | |
| 17 | #ifndef Net_ICMPPacket_INCLUDED |
| 18 | #define Net_ICMPPacket_INCLUDED |
| 19 | |
| 20 | |
| 21 | #include "Poco/Foundation.h" |
| 22 | #include "Poco/Net/Socket.h" |
| 23 | #include "Poco/Net/ICMPPacketImpl.h" |
| 24 | |
| 25 | |
| 26 | namespace Poco { |
| 27 | namespace Net { |
| 28 | |
| 29 | |
| 30 | class Net_API ICMPPacket |
| 31 | /// This class is the ICMP packet abstraction. |
| 32 | { |
| 33 | public: |
| 34 | ICMPPacket(SocketAddress::Family family, int dataSize = 48); |
| 35 | /// Creates an ICMPPacket of specified family. |
| 36 | |
| 37 | ~ICMPPacket(); |
| 38 | /// Destroys the ICMPPacket. |
| 39 | |
| 40 | const Poco::UInt8* packet(); |
| 41 | /// Returns raw ICMP packet. ICMP header and data are included in the returned packet. |
| 42 | |
| 43 | int packetSize() const; |
| 44 | /// Returns the total length of packet (header + data); |
| 45 | |
| 46 | Poco::UInt16 sequence() const; |
| 47 | /// Returns the most recent sequence number generated. |
| 48 | |
| 49 | void setDataSize(int dataSize); |
| 50 | /// Sets data size. |
| 51 | |
| 52 | int getDataSize() const; |
| 53 | /// Returns data size. |
| 54 | |
| 55 | int maxPacketSize() const; |
| 56 | /// Returns the total length of packet (header + data); |
| 57 | |
| 58 | struct timeval time(Poco::UInt8* buffer = 0, int length = 0) const; |
| 59 | /// Returns current epoch time if either buffer or length are equal to zero. |
| 60 | /// Otherwise, it extracts the time value from the supplied buffer and |
| 61 | /// returns the extracted value. |
| 62 | /// |
| 63 | /// Supplied buffer includes IP header, ICMP header and data. |
| 64 | |
| 65 | bool validReplyID(Poco::UInt8* buffer, int length) const; |
| 66 | /// Returns true if the extracted id is recognized |
| 67 | /// (equals the process id). |
| 68 | /// |
| 69 | /// Supplied buffer includes IP header, ICMP header and data. |
| 70 | |
| 71 | std::string errorDescription(Poco::UInt8* buffer, int length); |
| 72 | /// Returns error description string. |
| 73 | /// If supplied buffer contains an ICMP echo reply packet, an |
| 74 | /// empty string is returned indicating the absence of error. |
| 75 | /// |
| 76 | /// Supplied buffer includes IP header, ICMP header and data. |
| 77 | |
| 78 | std::string typeDescription(int typeId); |
| 79 | /// Returns the description of the packet type. |
| 80 | |
| 81 | private: |
| 82 | ICMPPacketImpl* _pImpl; |
| 83 | }; |
| 84 | |
| 85 | |
| 86 | } } // namespace Poco::Net |
| 87 | |
| 88 | |
| 89 | #endif // Net_ICMPPacket_INCLUDED |
| 90 | |