mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-poco.git
synced 2025-11-02 03:27:56 +00:00
* add PMTU discovery #2329 * add socket gather/scatter capabilities #2330 (win, udp) * enable WSAPoll * add FastMemoryPool * add receiveFrom() with native args * allow copying of StringTokenizer * add AtomicFlag and SpinlockMutex * update .gitignore * UDPServer and client #2343 (windows) * fix warnings * fix warnings * regenerate Net VS solutions * regenerate CppUnit projects/solutions * clang fixes * gcc fixes * try to fix travis * more travis fixes * more travis fixes * handle UDPClient exception * fix makefiles and init order warnings * add UNIX gather/scatter sendto/recvfrom implementations and tests * run travis tests as sudo * try to run tests as sudo, 2nd attempt * fix warning * use mutex in reactor * lock-order-inversion in SocketReactor #2346 * add PMTU discovery #2329 (linux) * ICMPSocket does not check reply address #1921 * remove some ignored tests * add PMTU discovery #2329 (reconcile logic with #1921) * fix native receiveFrome() * reinstate ignoring of proxy errors * add testMTU to ignore list * add include atomic * NTPClient not checking reply address #2348 * some ICMP/MTU fixes * UDPSocketReader cleanup * resolve some socket inheritance warnings * add NTP time sync to ignored tests * SocketNotifier not thread-safe #2345 * prevent x64 samples build attempt for win32 * build TestApp and Library * fix ICMP tests * regen VS projects * regen VS projects and add missing 2012 files * remove debug prints
148 lines
2.8 KiB
C++
148 lines
2.8 KiB
C++
//
|
|
// ICMPSocket.cpp
|
|
//
|
|
// Library: Net
|
|
// Package: ICMP
|
|
// Module: ICMPSocket
|
|
//
|
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
|
// and Contributors.
|
|
//
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
//
|
|
|
|
|
|
#include "Poco/Net/ICMPSocket.h"
|
|
#include "Poco/Net/ICMPSocketImpl.h"
|
|
#include "Poco/Exception.h"
|
|
#include "Poco/Net/NetException.h"
|
|
|
|
|
|
using Poco::InvalidArgumentException;
|
|
|
|
|
|
namespace Poco {
|
|
namespace Net {
|
|
|
|
|
|
ICMPSocket::ICMPSocket(IPAddress::Family family, int dataSize, int ttl, int timeout):
|
|
Socket(new ICMPSocketImpl(family, dataSize, ttl, timeout))
|
|
{
|
|
}
|
|
|
|
|
|
ICMPSocket::ICMPSocket(const Socket& socket):
|
|
Socket(socket)
|
|
{
|
|
if (!dynamic_cast<ICMPSocketImpl*>(impl()))
|
|
throw InvalidArgumentException("Cannot assign incompatible socket");
|
|
}
|
|
|
|
|
|
ICMPSocket::ICMPSocket(SocketImpl* pImpl):
|
|
Socket(pImpl)
|
|
{
|
|
if (!dynamic_cast<ICMPSocketImpl*>(impl()))
|
|
throw InvalidArgumentException("Cannot assign incompatible socket");
|
|
}
|
|
|
|
|
|
ICMPSocket::~ICMPSocket()
|
|
{
|
|
}
|
|
|
|
|
|
ICMPSocket& ICMPSocket::operator = (const Socket& socket)
|
|
{
|
|
if (dynamic_cast<ICMPSocketImpl*>(socket.impl()))
|
|
Socket::operator = (socket);
|
|
else
|
|
throw InvalidArgumentException("Cannot assign incompatible socket");
|
|
return *this;
|
|
}
|
|
|
|
|
|
int ICMPSocket::sendTo(const SocketAddress& address, int flags)
|
|
{
|
|
return impl()->sendTo(0, 0, address, flags);
|
|
}
|
|
|
|
|
|
int ICMPSocket::receiveFrom(SocketAddress& address, int flags)
|
|
{
|
|
return impl()->receiveFrom(0, 0, address, flags);
|
|
}
|
|
|
|
|
|
int ICMPSocket::dataSize() const
|
|
{
|
|
return static_cast<ICMPSocketImpl*>(impl())->dataSize();
|
|
}
|
|
|
|
|
|
int ICMPSocket::packetSize() const
|
|
{
|
|
return static_cast<ICMPSocketImpl*>(impl())->packetSize();
|
|
}
|
|
|
|
|
|
int ICMPSocket::ttl() const
|
|
{
|
|
return static_cast<ICMPSocketImpl*>(impl())->ttl();
|
|
}
|
|
|
|
|
|
int ICMPSocket::timeout() const
|
|
{
|
|
return static_cast<ICMPSocketImpl*>(impl())->timeout();
|
|
}
|
|
|
|
|
|
Poco::UInt16 ICMPSocket::mtu(const SocketAddress& address, Poco::UInt16 sz)
|
|
{
|
|
if (address.family() != IPAddress::IPv4) return 0;
|
|
|
|
SocketAddress returnAddress(address);
|
|
for (; sz >= 68 /*RFC791*/; --sz)
|
|
{
|
|
ICMPSocket icmpSocket(address.family(), sz);
|
|
|
|
#ifdef IP_DONTFRAGMENT
|
|
icmpSocket.setOption(IPPROTO_IP, IP_DONTFRAGMENT, 1);
|
|
#elif defined(IP_MTU_DISCOVER)
|
|
icmpSocket.setOption(IPPROTO_IP, IP_MTU_DISCOVER, IP_PMTUDISC_DO);
|
|
#elif defined(IP_DONTFRAG)
|
|
icmpSocket.setOption(IPPROTO_IP, IP_DONTFRAG, 1);
|
|
#else
|
|
throw NotImplementedException("ICMPSocket::mtu()");
|
|
#endif
|
|
|
|
try
|
|
{
|
|
icmpSocket.sendTo(address);
|
|
icmpSocket.receiveFrom(returnAddress);
|
|
poco_assert_dbg (returnAddress == address);
|
|
return sz;
|
|
}
|
|
catch (ICMPFragmentationException&)
|
|
{
|
|
// PMTU fragmentation, continue discovery
|
|
continue;
|
|
}
|
|
catch (NetException& ex)
|
|
{
|
|
// local MTU limit, continue discovery
|
|
if (ex.code() == POCO_EMSGSIZE)
|
|
continue;
|
|
}
|
|
catch (Exception&)
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
} } // namespace Poco::Net
|