
CPJNSNTPClient
v1.13 An MFC class to encapsulate the
SNTP protocol
Included is an MFC class to support the SNTP protocol. SNTP
for those not familiar with all the internet protocols is the protocol used to support
time synchronization.
Features
- Simple and clean C++ interface.
- The interface provided is synchronous which
provides an easier programming model than using asynchronous sockets.
- A configurable timeout for the connection
can be set through the class API.
- The classes are fully Unicode compliant and include Unicode build
configurations
in the project solution file.
The
enclosed
zip file contains the CPJNSNTPClient source code and a
simple console program which exercises the class.
Copyright
- You are allowed to include the source code in
any product (commercial, shareware, freeware or otherwise) when your product
is released in binary form.
- You are allowed to modify the source code in
any way you want except you cannot modify the copyright details at the top
of each module.
- If you want to distribute source code with
your application, then you are only allowed to distribute versions released
by the author. This is to maintain a single distribution point for the
source code.
Updates
v1.0 (9 August 1998)
10 August 1998
- Program now includes a VC 5 make file instead of VC 6
V1.01 (17 November 1998)
- m_nOriginateTime was getting set incorrectly in the SNTP response.
Has now been fixed.
- GetLastError now works when a timeout occurs
V1.02 (25 June 2000)
- Fixed an issue where the packing order of the
NtpBasicInfo struct was causing problems. Now packing is set to 1 byte for
this struct.
V1.03 (35 July 2000)
- Added Windows CE 2.11 compatibility. Thanks to Andre
Rippstein for the work.
V1.04 (29 March 2001)
- Updated copyright message
- Fixed a handle leak RevertSetTimePriviledge where the
process token was not been closed
V1.05 (25 August 2002)
- Updated sample app to work correctly for the Unicode
configurations
- Sample app now uses CWinApp instance in sample app
- Sample app now uses MFC support for initializing
Winsock stack
- Sample app now uses MFC support for parsing its command
line.
V1.06 (13 March 2003)
- Fixed a bug in CNtpSocket::IsReadible in the setup of
the timval structure. Thanks to "InBloom Support" for reporting this.
V1.07 (21 September 2003)
- Class now uses CWSocket class (which you will need to
download separately) to provide sockets
capability. This now allows the class to support connecting via a Socks 5
proxy.
V1.08 (17 March 2005)
- Updated to work with the latest release of CWSocket. Thanks to Alex Dron for reporting this issue.
- Addition of a preprocessor macro "PJNSNTP_EXT_CLASS" which allows the code to be easily added to an extension DLL.
- General tidy up of the code in CSNTPClient::GetServerTime
- Replaced the macro _WIN32_WCE with PJNSNTP_NO_PRIVILEDGE_CODE. This allows the privilege code to also be excluded on desktop versions of Windows if so desired.
- Reviewed and updated all the TRACE statements for correctness.
V1.09 (4 April 2005)
- Fix for a bug in the calculation of the m_RoundTripDelay value. Thanks to Euan Lee for reporting this bug.
18 May 2005
- Updated usage section for the code.
v1.10 (10 July 2005)
- Undone the change made on 04-04-2005 as the calculation of the round trip time calculation was correct. For details on the
formulae used, please check out RFC 2030. Thanks to Thomas Fejes for reporting this problem.
v1.11 (12 September 2005)
- Fixed problem where code did not handle graceful disconnects when reading the SNTP response.
- Reworked the class to now pass exceptions rather than use a Win32 style return value.
- Renamed the classes to use a prefix of PJN. This is in line with the SMTP class I also provide.
v1.12 (5 July 2006)
- Updated copyright details.
- Updated the documentation to use the same style as the web site.
- Code now uses newer C++ style casts instead of C style casts.
- Optimized CPJNNTPTime constructor code.
- Optimized CPJNSNTPClient constructor code
- Replaced calls to ZeroMemory with memset
- Updated code to work with latest version of CWSocket class.
- Made the code more robust in its handling of the m_hToken variable
- Optimized the privilege handling code to avoid the need for the
m_bTakenPrivilege variable.
- Verified all code compiles cleanly on VC 2005
- Renamed PJNSNTP_NO_PRIVILEDGE_CODE macro to PJNSNTP_NO_PRIVILEGE_CODE
v1.13 (11 July 2008)
- Updated copyright details.
- Updated sample app to clean compile on VC 2008
- Removed VC 6 style classwizard comments from the code.
- The code has now been updated to support VC 2005 or later only.
- Code now compiles cleanly using Code Analysis (/analyze)