ICMPPacket.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #include "Poco/Net/ICMPPacket.h"
  14. #include "Poco/Net/ICMPv4PacketImpl.h"
  15. #include "Poco/Net/NetException.h"
  16. #include "Poco/Timestamp.h"
  17. #include "Poco/Timespan.h"
  18. #include "Poco/NumberFormatter.h"
  19. #include <sstream>
  20. using Poco::InvalidArgumentException;
  21. using Poco::NotImplementedException;
  22. using Poco::Timestamp;
  23. using Poco::Timespan;
  24. using Poco::NumberFormatter;
  25. using Poco::UInt8;
  26. using Poco::UInt16;
  27. using Poco::Int32;
  28. namespace Poco {
  29. namespace Net {
  30. ICMPPacket::ICMPPacket(IPAddress::Family family, int dataSize):_pImpl(0)
  31. {
  32. if (family == IPAddress::IPv4)
  33. _pImpl = new ICMPv4PacketImpl(dataSize);
  34. #if defined(POCO_HAVE_IPv6)
  35. else if (family == IPAddress::IPv6)
  36. throw NotImplementedException("ICMPv6 packets not implemented.");
  37. #endif
  38. else throw InvalidArgumentException("Invalid or unsupported address family passed to ICMPPacket");
  39. }
  40. ICMPPacket::~ICMPPacket()
  41. {
  42. delete _pImpl;
  43. }
  44. void ICMPPacket::setDataSize(int dataSize)
  45. {
  46. _pImpl->setDataSize(dataSize);
  47. }
  48. int ICMPPacket::getDataSize() const
  49. {
  50. return _pImpl->getDataSize();
  51. }
  52. int ICMPPacket::packetSize() const
  53. {
  54. return _pImpl->packetSize();
  55. }
  56. int ICMPPacket::maxPacketSize() const
  57. {
  58. return _pImpl->maxPacketSize();
  59. }
  60. const Poco::UInt8* ICMPPacket::packet()
  61. {
  62. return _pImpl->packet();
  63. }
  64. struct timeval ICMPPacket::time(Poco::UInt8* buffer, int length) const
  65. {
  66. return _pImpl->time(buffer, length);
  67. }
  68. bool ICMPPacket::validReplyID(Poco::UInt8* buffer, int length) const
  69. {
  70. return _pImpl->validReplyID(buffer, length);
  71. }
  72. std::string ICMPPacket::errorDescription(Poco::UInt8* buffer, int length)
  73. {
  74. return _pImpl->errorDescription(buffer, length);
  75. }
  76. std::string ICMPPacket::typeDescription(int typeId)
  77. {
  78. return _pImpl->typeDescription(typeId);
  79. }
  80. } } // namespace Poco::Net