📄 csntp.htm
字号:
<p> </p>
<p><a name="operator CNtpTimePacket"></a><big><strong><font face="Arial">CNtpTime::operator
CNtpTimePacket</font></strong></big></p>
<p><strong><font face="Arial">operator CNtpTimePacket() const;</font></strong></p>
<p><font face="Arial"><strong>Remarks</strong></font></p>
<p><font face="Arial">Returns a CNtpTimePacket representation of an Ntp time. This
structure is the actual value which gets transmitted to the SNTP server.</font></p>
<p> </p>
<p><a name="operator unsigned __int64"></a><big><strong><font face="Arial">CNtpTime::operator
unsigned __int64</font></strong></big></p>
<p><strong><font face="Arial">operator unsigned __int64() const;</font></strong></p>
<p><font face="Arial"><strong>Remarks</strong></font></p>
<p><font face="Arial">Returns an unsigned int64 representation of the Ntp time.</font></p>
<p> </p>
<p><a name="Seconds"></a><big><strong><font face="Arial">CNtpTime::Seconds</font></strong></big></p>
<p><strong><font face="Arial">DWORD Seconds() const;</font></strong></p>
<p><font face="Arial"><strong>Remarks</strong></font></p>
<p><font face="Arial">Returns the total number of seconds which this Ntp time represents</font></p>
<p> </p>
<p><a name="Fraction"></a><big><strong><font face="Arial">CNtpTime::Fraction</font></strong></big></p>
<p><strong><font face="Arial">DWORD Fraction() const;</font></strong></p>
<p><font face="Arial"><strong>Remarks</strong></font></p>
<p><font face="Arial">Returns the fractional part of seconds which this Ntp time
represents.</font></p>
<p> </p>
<p><a name="GetCurrentTime"></a><big><strong><font face="Arial">CNtpTime::GetCurrentTime</font></strong></big></p>
<p><strong><font face="Arial">static CNtpTime GetCurrentTime();</font></strong></p>
<p><font face="Arial"><strong>Remarks</strong></font></p>
<p><font face="Arial">Constructs an NtpTime instance which represents the current UTC time
of the machine.</font></p>
<p> </p>
<p><a name="MsToNtpFraction"></a><big><strong><font face="Arial">CNtpTime::MsToNtpFraction</font></strong></big></p>
<p><font face="Arial"><strong>static DWORD MsToNtpFraction(WORD </strong><em>wMilliSeconds</em><strong>);</strong></font></p>
<p><font face="Arial"><strong>Remarks</strong></font></p>
<p><font face="Arial">Converts a count of milliseconds to an Ntp fractional.</font></p>
<p> </p>
<p><a name="NtpFractionToMs"></a><big><strong><font face="Arial">CNtpTime::NtpFractionToMs</font></strong></big></p>
<p><font face="Arial"><strong>static WORD NtpFractionToMs(DWORD </strong><em>dwFraction</em><strong>);</strong></font></p>
<p><font face="Arial"><strong>Remarks</strong></font></p>
<p><font face="Arial">Converts an Ntp fractional to a count of milliseconds.</font></p>
<p> </p>
<p><a name="NtpFractionToSecond"></a><big><strong><font face="Arial">CNtpTime::NtpFractionToSecond</font></strong></big></p>
<p><font face="Arial"><strong>static double NtpFractionToSecond(DWORD </strong><em>dwFraction</em><strong>);</strong></font></p>
<p><font face="Arial"><strong>Remarks</strong></font></p>
<p><font face="Arial">Converts an Ntp fractional to a fraction of a second as a floating
point value.</font></p>
<p> </p>
<p> </p>
<p><a name="m_nLeapIndicator"></a><big><strong><font face="Arial">NtpServerResponse::m_nLeapIndicator</font></strong></big></p>
<p><strong><font face="Arial">int m_nLeapIndicator; </font></strong></p>
<p><font face="Arial"><strong>Remarks</strong></font></p>
<p><font face="Arial">This value will contain one of the following values:</font></p>
<p><font face="Arial">0: no warning<br>
1: last minute in day has 61 seconds<br>
2: last minute has 59 seconds<br>
3: clock not synchronized<br>
</font></p>
<p><a name="m_nStratum"></a><big><strong><font face="Arial">NtpServerResponse::m_nStratum</font></strong></big></p>
<p><strong><font face="Arial">int m_nStratum; </font></strong></p>
<p><font face="Arial"><strong>Remarks</strong></font></p>
<p><font face="Arial">This value will contain the stratum level of the server. It will be
one of the following values:</font></p>
<p><font face="Arial">0: unspecified or unavailable<br>
1: primary reference (e.g., radio clock)<br>
2-15: secondary reference (via NTP or SNTP)<br>
16-255: reserved<br>
</font></p>
<p><a name="m_nOriginateTime"></a><big><strong><font face="Arial">NtpServerResponse::m_nOriginateTime</font></strong></big></p>
<p><strong><font face="Arial">CNtpTime m_OriginateTime; </font></strong></p>
<p><strong><font face="Arial">Remarks</font></strong></p>
<p><font face="Arial">This is the client time when the request was sent from the client to
the SNTP server.</font></p>
<p> </p>
<p><a name="m_ReceiveTime"></a><big><strong><font face="Arial">NtpServerResponse::m_ReceiveTime</font></strong></big></p>
<p><strong><font face="Arial">CNtpTime m_ReceiveTime; </font></strong></p>
<p><strong><font face="Arial">Remarks</font></strong></p>
<p><font face="Arial">This is the server time when the request was received by the SNTP
server from the client.</font></p>
<p> </p>
<p><a name="m_TransmitTime"></a><big><strong><font face="Arial">NtpServerResponse::m_TransmitTime</font></strong></big></p>
<p><strong><font face="Arial">CNtpTime m_TransmitTime; </font></strong></p>
<p><strong><font face="Arial">Remarks</font></strong></p>
<p><font face="Arial">This is the server time when the server sent the request back to the
client.</font></p>
<p> </p>
<p><a name="m_DestinationTime"></a><big><strong><font face="Arial">NtpServerResponse::m_DestinationTime</font></strong></big></p>
<p><strong><font face="Arial">CNtpTime m_DestinationTime; </font></strong></p>
<p><strong><font face="Arial">Remarks</font></strong></p>
<p><font face="Arial">This is the client time when the reply was received by the client.</font></p>
<p> </p>
<p><a name="m_RoundTripDelay"></a><big><strong><font face="Arial">NtpServerResponse::m_RoundTripDelay</font></strong></big></p>
<p><strong><font face="Arial">double m_RoundTripDelay; </font></strong></p>
<p><strong><font face="Arial">Remarks</font></strong></p>
<p><font face="Arial">This is the round trip time in seconds for the Ntp request. It is
calculated as:</font></p>
<p><em><font face="Arial">m_RoundTripDelay = (m_DestinationTime - m_OriginateTime) -
(m_ReceiveTime - m_TransmitTime);</font></em></p>
<p> </p>
<p><a name="m_LocalClockOffset"></a><big><strong><font face="Arial">NtpServerResponse::m_LocalClockOffset</font></strong></big></p>
<p><strong><font face="Arial">double m_LocalClockOffset; </font></strong></p>
<p><strong><font face="Arial">Remarks</font></strong></p>
<p><font face="Arial">This is the local clock offset relative to the server. This is
calculated as:</font></p>
<p><em><font face="Arial">LocalClockOffset = ((m_ReceiveTime - m_OriginateTime) +
(m_TransmitTime - m_DestinationTime)) / 2.</font></em></p>
<p><font face="Arial">This value can then be used to set the local time by a simple call
as follows:</font></p>
<p><font face="Arial">CNtpTime newSynchronizedTime(CNtpTime::GetCurrentTime() +
m_LocalClockOffset);<br>
</font></p>
<p> </p>
<p><a name="CSNTPClient"></a><big><strong><font face="Arial">CSNTPClient::CSNTPClient</font></strong></big></p>
<p><strong><font face="Arial">CSNTPClient();</font></strong></p>
<p><font face="Arial"><strong>Remarks</strong></font></p>
<p><font face="Arial">Standard C++ constructor which initializes the timeout to a default
value of 5 seconds.</font></p>
<p> </p>
<p><a name="GetServerTime"></a><big><strong><font face="Arial">CSNTPClient::GetServerTime</font></strong></big></p>
<p><font face="Arial"><strong>BOOL GetServerTime(LPCTSTR </strong><em>pszHostName</em><strong>,
NtpServerResponse& </strong><em>response</em><strong>, int </strong><em>nPort</em><strong>
= 123);</strong></font></p>
<p><strong><font face="Arial">Parameters</font></strong></p>
<p><font face="Arial"><em>pszHostName</em> The network address of the SNTP server to
connect to: a machine name such as “ntp.maths.tcd.ie”, or a dotted number such
as “128.56.22.8” will both work.</font></p>
<p><font face="Arial"><em>response</em> Upon a successful call to this function, this will
contain all the information relating to the SNTP server.</font></p>
<p><font face="Arial"><em>nPort</em> This is the port number of which to make a SNTP
request. The default value is 123.</font></p>
<p><strong><font face="Arial">Return Value</font></strong></p>
<p><font face="Arial">If the function succeeds, the return value is nonzero. If the
function fails, the return value is zero. To get extended error information, call <b>GetLastError</b>.
</font></p>
<p><font face="Arial"><strong>Remarks</strong></font></p>
<p><font face="Arial">This performs the actual SNTP query and returns the relevant
information back in the response structure. You are then free to decide if you want to set
the local time using the values retrieved.</font></p>
<p> </p>
<p><a name="GetTimeout"></a><big><strong><font face="Arial">CSNTPClient::GetTimeout</font></strong></big></p>
<p><strong><font face="Arial">DWORD GetTimeout() const;</font></strong></p>
<p><strong><font face="Arial">Return Value</font></strong></p>
<p><font face="Arial">The current timeout to use for socket calls which will block while
doing the SNTP query.</font></p>
<p> </p>
<p><a name="SetTimeout"></a><big><strong><font face="Arial">CSNTPClient::SetTimeout</font></strong></big></p>
<p><font face="Arial"><strong>void SetTimeout(DWORD </strong><em>dwTimeout</em><strong>);</strong></font></p>
<p><strong><font face="Arial">Parameters</font></strong></p>
<p><font face="Arial"><em>dwTimeout</em> The new timeout to use for socket calls which
will block while doing the SNTP query.</font></p>
<p> </p>
<p><a name="SetClientTime"></a><big><strong><font face="Arial">CSNTPClient::SetClientTime</font></strong></big></p>
<p><font face="Arial"><strong>BOOL SetClientTime(const CNtpTime& </strong><em>NewTime</em><strong>);</strong></font></p>
<p><strong><font face="Arial">Parameters</font></strong></p>
<p><font face="Arial"><em>NewTime</em> An Ntp time representation of the time to be use to
set the client time.</font></p>
<p><strong><font face="Arial">Return Value</font></strong></p>
<p><font face="Arial">If the function succeeds, the return value is nonzero. If the
function fails, the return value is zero. To get extended error information, call <b>GetLastError</b>.
</font></p>
<p><font face="Arial"><strong>Remarks</strong></font></p>
<p><font face="Arial">Given a time, this function will set the client system time.
Internally it looks after setting privileges which is required on NT because of its
security mode..</font></p>
<p> </p>
<p> </p>
<p> </p>
<p><font face="Arial"><big><a name="Enhancements"></a></big><font color="#000000" size="4"><strong>PLANNED
ENHANCEMENTS</strong></font> </font>
<ul>
<li><font color="#000000" size="3" face="Arial">If you have any other suggested
improvements, please let me know so that I can incorporate them into the next release.</font></li>
</ul>
<p> </p>
<p> </p>
<p> </p>
<p><font face="Arial"><a name="Contact"></a><font color="#000000" size="4"><strong>CONTACTING
THE AUTHOR</strong></font></font></p>
<p><font color="#000000" size="3" face="Arial">PJ Naughter<br>
Email: <a href="mailto:pjna@naughter.com">pjna@naughter.com</a><br>
Web: <a href="http://www.naughter.com">http://www.naughter.com</a><br>
21 September 2003</font></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -