![]() |
General Programming »
Internet / Network »
General
Intermediate
CSNTPClient - An SNTP ImplementationBy PJ NaughterA collection of freeware MFC classes to encapsulate the SNTP protocol. |
VC6, MFC, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
Welcome to CSNTPClient, a collection of freeware MFC classes to encapsulate the SNTP protocol.
| Features |
| Usage |
| History |
| API Reference |
| Planned Enhancements |
| Contacting the Author |
#include sntp.h in which ever of your modules needs to make calls to the class.
History
V1.0 (8th August 1998)
V1.01 (16th November 1998)
GetLastError() now works when a timeout occurs.
API Reference
The API consists of the the classes:
CNtpTime:
This is an encapsulation of a time instance as used in the SNTP protocol. This consists of a 64 bit unsigned integer with the top 32 bits containing the number of seconds since 1st January 1900 and the lower 32 bits contain the fraction of seconds.
CNtpTime
operator=
operator-
operator+
operator SYSTEMTIME
operator CNtpTimePacket
operator unsigned __int64
Seconds
Fraction
GetCurrentTime
MsToNtpFraction
NtpFractionToMs
NtpFractionToSecond
NtpServerResponse
This is a simple encapsulation of the information retrieved from the SNTP server. It contains:
m_nLeapIndicator
m_nStratum
m_OriginateTime
m_ReceiveTime
m_TransmitTime
m_DestinationTime
m_RoundTripDelay
m_LocalClockOffset
CSNTPClient
The actual class to call to perform a time lookup is CSNTPClient and it consists of:
CSNTPClient
GetServerTime
GetTimeout
SetTimeout
SetClientTime
Parameters:
Remarks:
Standard C++ constructor.
Remarks:
Standard operator= for the class.
Remarks:
Standard operator- for the class.
Remarks:
Standard operator+ for the class.
Remarks:
Returns a SDK SYSTEMTIME representation of the Ntp time.
Remarks:
Returns a CNtpTimePacket representation of an Ntp time. This structure is the actual value which gets
transmitted to the SNTP server.
Remarks:
Returns an unsigned int64 representation of the Ntp time.
Remarks:
Returns the total number of seconds which this Ntp time represents.
Remarks:
Returns the fractional part of seconds which this Ntp time represents.
Remarks:
Constructs an NtpTime instance which represents the current UTC time of the machine.
Remarks:
Converts a count of milliseconds to an Ntp fractional.
Remarks:
Converts an Ntp fractional to a count of milliseconds.
Remarks:
Converts an Ntp fractional to a fraction of a second as a floating point value.
Remarks:
This value will contain one of the following values:
Remarks:
This value will contain the stratum level of the server. It will be one of the following values:
Remarks:
This is the client time when the request was sent from the client to the SNTP server.
Remarks:
This is the server time when the request was received by the SNTP server from the client.
Remarks:
This is the server time when the server sent the request back to the client.
Remarks:
This is the client time when the reply was received by the client.
Remarks:
This is the round trip time in seconds for the Ntp request. It is calculated as:
m_RoundTripDelay = (m_DestinationTime - m_OriginateTime) - (m_ReceiveTime - m_TransmitTime);
Remarks:
This is the local clock offset relative to the server. This is calculated as:
LocalClockOffset = ((m_ReceiveTime - m_OriginateTime) + (m_TransmitTime - m_DestinationTime)) / 2;
This value can then be used to set the local time by a simple call as follows:
CNtpTime newSynchronizedTime(CNtpTime::GetCurrentTime() + m_LocalClockOffset);
Remarks:
Standard C++ constructor which initializes the timeout to a default value of 5 seconds.
Return Value:
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
To get extended error information, call GetLastError().
Parameters:
Remarks:
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.
Return Value:
The current timeout to use for socket calls which will block while doing the SNTP query.
Parameters:
Return Value:
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
To get extended error information, call GetLastError().
Parameters:
Remarks:
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.
Contacting the Author
PJ Naughter
Email: pjn@indigo.ie
Web: http://www.naughter.com/a>
16th November 1998
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 7 Apr 2000 Editor: Valerie Bradley |
Copyright 2000 by PJ Naughter Everything else Copyright © CodeProject, 1999-2009 Web09 | Advertise on the Code Project |