1//
2// ICMPSocket.cpp
3//
4// Library: Net
5// Package: ICMP
6// Module: ICMPSocket
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/ICMPSocket.h"
16#include "Poco/Net/ICMPSocketImpl.h"
17#include "Poco/Exception.h"
18
19
20using Poco::InvalidArgumentException;
21
22
23namespace Poco {
24namespace Net {
25
26
27ICMPSocket::ICMPSocket(IPAddress::Family family, int dataSize, int ttl, int timeout):
28 Socket(new ICMPSocketImpl(family, dataSize, ttl, timeout))
29{
30}
31
32
33ICMPSocket::ICMPSocket(const Socket& socket):
34 Socket(socket)
35{
36 if (!dynamic_cast<ICMPSocketImpl*>(impl()))
37 throw InvalidArgumentException("Cannot assign incompatible socket");
38}
39
40
41ICMPSocket::ICMPSocket(SocketImpl* pImpl):
42 Socket(pImpl)
43{
44 if (!dynamic_cast<ICMPSocketImpl*>(impl()))
45 throw InvalidArgumentException("Cannot assign incompatible socket");
46}
47
48
49ICMPSocket::~ICMPSocket()
50{
51}
52
53
54ICMPSocket& ICMPSocket::operator = (const Socket& socket)
55{
56 if (dynamic_cast<ICMPSocketImpl*>(socket.impl()))
57 Socket::operator = (socket);
58 else
59 throw InvalidArgumentException("Cannot assign incompatible socket");
60 return *this;
61}
62
63
64int ICMPSocket::sendTo(const SocketAddress& address, int flags)
65{
66 return impl()->sendTo(0, 0, address, flags);
67}
68
69
70int ICMPSocket::receiveFrom(SocketAddress& address, int flags)
71{
72 return impl()->receiveFrom(0, 0, address, flags);
73}
74
75
76int ICMPSocket::dataSize() const
77{
78 return static_cast<ICMPSocketImpl*>(impl())->dataSize();
79}
80
81
82int ICMPSocket::packetSize() const
83{
84 return static_cast<ICMPSocketImpl*>(impl())->packetSize();
85}
86
87
88int ICMPSocket::ttl() const
89{
90 return static_cast<ICMPSocketImpl*>(impl())->ttl();
91}
92
93
94int ICMPSocket::timeout() const
95{
96 return static_cast<ICMPSocketImpl*>(impl())->timeout();
97}
98
99
100} } // namespace Poco::Net
101