1 | // |
2 | // ICMPSocket.h |
3 | // |
4 | // Library: Net |
5 | // Package: ICMP |
6 | // Module: ICMPSocket |
7 | // |
8 | // Definition of the ICMPSocket 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_ICMPSocket_INCLUDED |
18 | #define Net_ICMPSocket_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Net/Net.h" |
22 | #include "Poco/Net/Socket.h" |
23 | |
24 | |
25 | namespace Poco { |
26 | namespace Net { |
27 | |
28 | |
29 | class Net_API ICMPSocket: public Socket |
30 | /// This class provides an interface to an |
31 | /// ICMP client socket. |
32 | { |
33 | public: |
34 | ICMPSocket(SocketAddress::Family family, int dataSize = 48, int ttl = 128, int timeout = 5000000); |
35 | /// Creates an unconnected ICMP socket. |
36 | /// |
37 | /// The socket will be created for the |
38 | /// given address family. |
39 | |
40 | ICMPSocket(const Socket& socket); |
41 | /// Creates the ICMPSocket with the SocketImpl |
42 | /// from another socket. The SocketImpl must be |
43 | /// a ICMPSocketImpl, otherwise an InvalidArgumentException |
44 | /// will be thrown. |
45 | |
46 | ~ICMPSocket(); |
47 | /// Destroys the ICMPSocket. |
48 | |
49 | ICMPSocket& operator = (const Socket& socket); |
50 | /// Assignment operator. |
51 | /// |
52 | /// Releases the socket's SocketImpl and |
53 | /// attaches the SocketImpl from the other socket and |
54 | /// increments the reference count of the SocketImpl. |
55 | |
56 | int sendTo(const SocketAddress& address, int flags = 0); |
57 | /// Sends an ICMP request through |
58 | /// the socket to the given address. |
59 | /// |
60 | /// Returns the number of bytes sent. |
61 | |
62 | int receiveFrom(SocketAddress& address, int flags = 0); |
63 | /// Receives data from the socket. |
64 | /// Stores the address of the sender in address. |
65 | /// |
66 | /// Returns the time elapsed since the originating |
67 | /// request was sent. |
68 | |
69 | int dataSize() const; |
70 | /// Returns the data size in bytes. |
71 | |
72 | int packetSize() const; |
73 | /// Returns the packet size in bytes. |
74 | |
75 | int ttl() const; |
76 | /// Returns the Time-To-Live value. |
77 | |
78 | int timeout() const; |
79 | /// Returns the socket timeout value. |
80 | |
81 | protected: |
82 | ICMPSocket(SocketImpl* pImpl); |
83 | /// Creates the Socket and attaches the given SocketImpl. |
84 | /// The socket takes ownership of the SocketImpl. |
85 | /// |
86 | /// The SocketImpl must be a ICMPSocketImpl, otherwise |
87 | /// an InvalidArgumentException will be thrown. |
88 | }; |
89 | |
90 | |
91 | } } // namespace Poco::Net |
92 | |
93 | |
94 | #endif // Net_ICMPSocket_INCLUDED |
95 | |