Thread: NTP and C

  1. #1
    Registered User
    Join Date
    Jul 2008

    NTP and C

    Is there any simple way to get Network time (UTC) in ansi C through NTP or other protocols?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Depends on how you define "simple". There are libraries that allow you to access the network, such as Winsock(2) for Windows, and the BSD socket API for many other OS's [these two are, at least in essense, the SAME, just named slightly differently between Windows and other OS']. This allows you to use the TCP/IP protocol, which NTP relies on.

    Then it's a case of implementing the NTP client behaviour. I have never worked on that, so I can't say. But here's an implementation:

    The ntpclient.c, which is the main part of that code, is 700+ lines. Not what I'd call trivial, but if you know what you are doing, it would probably be done in a couple of weeks.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed