Code Monkey home page Code Monkey logo

sntp's Introduction

% sntp(1) | A bare-bones SNTP client

NAME

SNTP - A bare-bones SNTP client

SYNOPSES

sntp server port?

DESCRIPTION

Super bare bones SNTP client. Implementing a full NTP client is quite complex, just getting the time from an NTP server is not, most applications do not need sub second accuracy, or even second accuracy. This program should be fine for those use cases.

Most of the complexity of this solution is in dealing with the IPv4/IPv6 connection. They really did make it ugly.

To build and run you will require two things make and a C compiler. Type 'make' to build the example program called 'sntp' and type 'make run' to build and run the 'sntp' program. It will attempt to connect to a NTP pool specified in the makefile.

Building the program also produces a library, 'libsntp.a', the SNTP library is incredibly simple, much like the program, containing just one function:

int sntp(const char *server, unsigned port, unsigned long *seconds, unsigned long *fractional);

This function returns zero on success, and negative on failure. You must provide a SNTP server to connect to (either a hostname, an IPv4, or an IPv6 address), a port (the default port for NTP is port 123, set the port to zero to auto select this) and two variables into which the time will placed on success, on failure both values will be set to zero. This function will block until the client either returns success or failure.

A non-blocking version of the 'sntp' function would be trivial to make, it would require only a file descriptor and a single variable describing the program position to be stored and passed into the 'sntp' function between calls.

References:

LICENSE

All code and documentation is released into the public domain where this is allowed, do what thou wilt.

RETURN CODE

The 'sntp' program returns '1' on failure and '0' on success.

sntp's People

Contributors

howerj avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.