1//
2// NTPPacket.h
3//
4// Library: Net
5// Package: NTP
6// Module: NTPPacket
7//
8// Definition of the NTPPacket 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_NTPPacket_INCLUDED
18#define Net_NTPPacket_INCLUDED
19
20
21#include "Poco/Foundation.h"
22#include "Poco/Net/Net.h"
23#include "Poco/Timestamp.h"
24
25namespace Poco {
26namespace Net {
27
28
29class Net_API NTPPacket
30 /// This class is the NTP packet abstraction.
31{
32public:
33 NTPPacket();
34 /// Creates an NTPPacket.
35
36 NTPPacket(Poco::UInt8 *packet);
37 /// Creates an NTPPacket.
38 ///
39 /// Assumed to have at least 48 bytes.
40
41 ~NTPPacket();
42 /// Destroys the NTPPacket.
43
44 void packet(Poco::UInt8 *packet) const;
45 /// Returns the NTP packet.
46 ///
47 /// Assumed to have at least 48 bytes.
48
49 void setPacket(Poco::UInt8 *packet);
50 /// Returns the NTP packet.
51 ///
52 /// Assumed to have exactly 48 bytes.
53
54 Poco::Int8 leapIndicator() const;
55 /// Returns the leap indicator.
56
57 Poco::Int8 version() const;
58 /// Returns the version.
59
60 Poco::Int8 mode() const;
61 /// Returns the mode.
62
63 Poco::Int8 stratum() const;
64 /// Returns the stratum.
65
66 Poco::Int8 pool() const;
67 /// Returns the pool.
68
69 Poco::Int8 precision() const;
70 /// Returns the precision
71
72 Poco::Int32 rootDelay() const;
73 /// Returns the root delay
74
75 Poco::Int32 rootDispersion() const;
76 /// Returns the root dispersion
77
78 Poco::Int32 referenceId() const;
79 /// Returns the reference id
80
81 Poco::Int64 referenceTimestamp() const;
82 /// Returns the reference timestamp
83
84 Poco::Int64 originateTimestamp() const;
85 /// Returns the originate timestamp
86
87 Poco::Int64 receiveTimestamp() const;
88 /// Returns the receive timestamp
89
90 Poco::Int64 transmitTimestamp() const;
91 /// Returns the transmit timestamp
92
93 Poco::Timestamp referenceTime() const;
94 /// Returns the reference time
95
96 Poco::Timestamp originateTime() const;
97 /// Returns the originate time
98
99 Poco::Timestamp receiveTime() const;
100 /// Returns the receive time
101
102 Poco::Timestamp transmitTime() const;
103 /// Returns the transmit time
104private:
105 Poco::Timestamp convertTime(Poco::Int64 tm) const;
106
107 Poco::Int8 _leapIndicator;
108 Poco::Int8 _version;
109 Poco::Int8 _mode;
110 Poco::Int8 _stratum;
111 Poco::Int8 _pool;
112 Poco::Int8 _precision;
113 Poco::Int32 _rootDelay;
114 Poco::Int32 _rootDispersion;
115 Poco::Int32 _referenceId;
116 Poco::Int64 _referenceTimestamp;
117 Poco::Int64 _originateTimestamp;
118 Poco::Int64 _receiveTimestamp;
119 Poco::Int64 _transmitTimestamp;
120};
121
122
123//
124// inlines
125//
126inline Poco::Int8 NTPPacket::leapIndicator() const
127{
128 return _leapIndicator;
129}
130
131
132inline Poco::Int8 NTPPacket::version() const
133{
134 return _version;
135}
136
137
138inline Poco::Int8 NTPPacket::mode() const
139{
140 return _mode;
141}
142
143
144inline Poco::Int8 NTPPacket::stratum() const
145{
146 return _stratum;
147}
148
149
150inline Poco::Int8 NTPPacket::pool() const
151{
152 return _pool;
153}
154
155
156inline Poco::Int8 NTPPacket::precision() const
157{
158 return _precision;
159}
160
161
162inline Poco::Int32 NTPPacket::rootDelay() const
163{
164 return _rootDelay;
165}
166
167
168inline Poco::Int32 NTPPacket::rootDispersion() const
169{
170 return _rootDispersion;
171}
172
173
174inline Poco::Int32 NTPPacket::referenceId() const
175{
176 return _referenceId;
177}
178
179
180inline Poco::Int64 NTPPacket::referenceTimestamp() const
181{
182 return _referenceTimestamp;
183}
184
185
186inline Poco::Int64 NTPPacket::originateTimestamp() const
187{
188 return _originateTimestamp;
189}
190
191
192inline Poco::Int64 NTPPacket::receiveTimestamp() const
193{
194 return _receiveTimestamp;
195}
196
197
198inline Poco::Int64 NTPPacket::transmitTimestamp() const
199{
200 return _transmitTimestamp;
201}
202
203
204} } // namespace Poco::Net
205
206
207#endif // Net_NTPPacket_INCLUDED
208