HS NTP C Source Library


HS NTP is a software library in C (supplied with full source code) which implements the client side of Network Time Protocol (NTP) over UDP socket layer according to RFC1769 and RFC1305. HS NTP Library allows a user application to synchronize local system time to remote NTP server time.

The use of HS NTP C Source Library is Royalty Free.

HS NTP includes the C source for the following platforms:

  Windows    Linux    Apple MAC OS X    Apple iPhone iOS   WinCE (Windows Embedded CE)


  • NTP Client Operation
  • Server name resolution
  • Non-blocking asynchonous operation
  • Supports millisecond resolution

How It Works

First user application calls HS NTP initialization function supplying pointers to callback functions in user code for timer management and for reporting NTP events to user.

To obtain time difference between local system and remote NTP server, the user application calls HsNtpGetTime function, specifying NTP server name or IP address and source UDP port to use.

HS NTP library then resolves the server name, formats and sends NTP time request packet according to RFC1305 and RFC1769 standard. Once HS NTP has received NTP time reply from NTP server it analyses the reply and reports the resulting time difference to user application via callback function. The parameters to this event callback contain the offset value in seconds necessary to apply to local clock in order to synchronize it to the time at remote NTP server.

Modular design makes it easy to port HS NTP protocol module to any environment. HS NTP internally at a lower layer interfaces to HS Sock library which provides UDP transport services. User application need not worry about Winsock on Windows or BSD sockets on linux or MAC OS X or iPhone iOS - HS NTP does all transmission, reception and event handling over socket layer.

API Summary

  • int HsNtpInit(hs_ntp_api_t *api);
  • int HsNtpDestroy(void);
  • int HsNtpGetTime(hs_ntp_session_t *s);
  • unsigned char *HsNtpGetErrStr (int rc);

HS NTP Library Architecture

The library includes several comonents which link to customer's application:

HS NTP Library File Structure

Core HS NTP Library

  • hsntp.c (18 functions, 603 lines)
  • hsntp.h (101 lines)
  • hsntp_if.h (118 lines)

UDP / TCP Socket interface library

  • hssock.c (19 functions, 760 lines)
  • hssock.h (70 lines)
  • hssock_if.h (136 lines)

List management library

  • hslist.c (15 functions, 391 lines)
  • hslist.h (84 lines)

HS NTP Demo Application

  • HsNtpDemo.c (15 functions, 686 lines)
  • StdAfx.h (47 lines)
  • resource.h (66 lines)
  • script1.rc (139 lines)


Hillstone Software provides additional services for customization, porting and integration of the library code to better suit the needs of your products