ICMPSocketImpl.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // ICMPSocketImpl.h
  3. //
  4. // Library: Net
  5. // Package: ICMP
  6. // Module: ICMPSocketImpl
  7. //
  8. // Definition of the ICMPSocketImpl class.
  9. //
  10. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Net_ICMPSocketImpl_INCLUDED
  16. #define Net_ICMPSocketImpl_INCLUDED
  17. #include "Poco/Net/Net.h"
  18. #include "Poco/Net/RawSocketImpl.h"
  19. #include "Poco/Net/ICMPPacket.h"
  20. #include "Poco/Timestamp.h"
  21. namespace Poco {
  22. namespace Net {
  23. class Net_API ICMPSocketImpl: public RawSocketImpl
  24. /// This class implements an ICMP socket.
  25. {
  26. public:
  27. ICMPSocketImpl(SocketAddress::Family family, int dataSize, int ttl, int timeout);
  28. /// Creates an unconnected ICMP socket.
  29. ///
  30. /// The socket will be created for the given address family.
  31. int sendTo(const void*, int, const SocketAddress& address, int flags = 0);
  32. /// Sends an ICMP request through the socket to the given address.
  33. ///
  34. /// Returns the number of bytes sent.
  35. int receiveFrom(void*, int, SocketAddress& address, int flags = 0);
  36. /// Receives data from the socket.
  37. /// Stores the address of the sender in address.
  38. ///
  39. /// Returns the time elapsed since the originating request was sent.
  40. int dataSize() const;
  41. /// Returns the data size in bytes.
  42. int ttl() const;
  43. /// Returns the Time-To-Live value.
  44. int timeout() const;
  45. /// Returns the socket timeout value.
  46. protected:
  47. ~ICMPSocketImpl();
  48. private:
  49. ICMPPacket _icmpPacket;
  50. int _ttl;
  51. int _timeout;
  52. };
  53. //
  54. // inlines
  55. //
  56. inline int ICMPSocketImpl::dataSize() const
  57. {
  58. return _icmpPacket.getDataSize();
  59. }
  60. inline int ICMPSocketImpl::ttl() const
  61. {
  62. return _ttl;
  63. }
  64. inline int ICMPSocketImpl::timeout() const
  65. {
  66. return _timeout;
  67. }
  68. } } // namespace Poco::Net
  69. #endif // Net_ICMPSocketImpl_INCLUDED