SNTP (Simple Network Time Protocol) is a simple version of NTP (Network Time Protocol) used for synchronizing computer clocks on the Internet. It is widely used by routers and computers to make sure that their clocks are reasonably accurate. This version of SNTP is for machines running DOS and it will let you fetch the time from a public NTP server on the Internet and optionally set your system time to that time.
The executable (sntp.exe) is only 40KB in size. I use it to check and set the time on a PC XT which does not have a clock/calendar chip - it gets done right in the autoexec.bat file after DHCP runs to get an address. Like magic, the time is set when the machine boots up! The same trick can be used to keep the clock accurate on newer machines.
Here is a screenshot of SNTP in action:
SNTP fetching the current time from pool.ntp.org
(Note: DOSBox is great for getting screen shots, but it doesn't actually let you set the time! On a virtual machine running DOS or a real PC the time would get set, but under DOSBox it just happily reports the time is set and does nothing.)
Basically, if you have any old PC running DOS with something that looks like a network connection you should be able to run SNTP.
SNTP uses the mTCP TCP/IP library for DOS. To use SNTP you need a working network connection and an IP address for your DOS machine. Instructions for getting an IP address can be found in the mTCP setup instructions. Setup is not difficult and once it is done it is good for all of the mTCP applications.
The SNTP command line looks like this:
sntp [options] <ntp server>
|-help||Show a help message|
|-port <n>||Contact server on port <n> (default=123)|
|-retries <n>||Number of times to retry if no answer (default=1)|
|-set||Set the system time|
|-timeout <n>||Seconds to wait for a server response (default=3)|
The NTP server parameter can be any NTP server on the network. I recommend using pool.ntp.org. Details on this collection of servers can be found at http://www.pool.ntp.org/.
Before running SNTP you should set the 'TZ' environment variable in DOS. The date and time that you get from the NTP server will be in Universal Coordinated Time and needs to be adjusted for your local timezone. The TZ environment variable tells the code what your local timezone is and how to make that adjustment.
Here are some example timezone settings:
|set TZ=CST5CDT6,M3.2.0/02:00:00,M11.1.0/02:00:00||Set timezone to US Central Standard|
|set TZ=EST4EDT5,M3.2.0/02:00:00,M11.1.0/02:00:00||US Eastern Standard|
|set TZ=UTC-1||One hour east of GMT, somewhere in Europe|
|set TZ=CET-2CDT||Two hours east of GMT, DST is observed|
Note that the US time strings look ugly - this is because the US Congress felt the need to move when daylight savings time starts. The string gives SNTP the exact instructions for when daylight savings time starts and ends.
Some of you might note that the time offset is opposite of what Windows uses. That is because the program is using the POSIX standard for setting the TZ environment variable. Sorry, that is just the way it is. If you are west of GMT the offset is positive and if you are east of GMT the offset is negative.
If you want to see the full rules for setting the TZ environment variable including how to set it for complex daylight savings rules, please see the Open Watcom documentation:
Look for the section entitled "The TZ Environment Variable."
SNTP uses the UDP protocol to contact the NTP server. UDP is not a reliable way to send packets on the network, so packets are often lost. The -retries option can be used to improve the chances that SNTP will be able to get a reponse from an NTP server.
By default SNTP only tells you the time that it received from the NTP server. If you want the time to be set on your system use the -set option.
SNTP sets a return value so that you can tell what it did. If SNTP set the time the return value will be zero. Otherwise, the return value will be 1. You can use this in a batch file:
echo Calling SNTP to set the time
sntp -set pool.ntp.org
if errorlevel 1 goto errmsg
echo System time set
echo System time not set! Please set it by hand
After setting your timezone information ...
|sntp pool.ntp.org||Get the time from pool.ntp.org|
|sntp -retries 3 pool.ntp.org||Same as above, but retry up to three times|
|sntp -set pool.ntp.org||Set the system time to the NTP time|
SNTP is included with the other mTCP applications. They can be downloaded from the main mTCP page here.
Aside from the SNTP.EXE program and a packet driver to talk to your Ethernet card, no other downloads are needed. Everything that SNTP needs to connect on the Internet is included in the program.
SNTP is accurate to within about one second. NTP servers will return time stamps with much higher resolution but after you deal with network jitter and delays it is not as accurate. Combine that with DOS which has a default timer resolution of 55ms and there is just no point in trying to make it more accurate. One second is great for most of us on older hardware.
SNTP can use DNS names or raw IP addresses. Use DNS names where possible because servers can change their IP addresses and DNS protects you against that. Also, large pools of NTP servers will use DNS to do load balancing and to direct your request to the nearest server which helps to improve the accuracy of the time sent to your computer.
Nothing is perfect but we can try ...
The SNTP client is part of the mTCP project which features a TCP/IP library for DOS and several TCP/IP applications that use the library. The applications include a DHCP client, a Telnet client, an FTP client, an IRC client, an FTP server, Ping, Netcat, and an HTTP file fetcher. All of the software is open source and is licensed under the GPL, version 3. More information about mTCP can be found at the mTCP project page.
Have a comment or need help? Please email me at firstname.lastname@example.org.
Link: mTCP main project page
Created August 21st, 2010, Last updated December 23nd, 2013
(C)opyright Michael B. Brutman, email@example.com