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