NTP and C

This is a discussion on NTP and C within the C Programming forums, part of the General Programming Boards category; Is there any simple way to get Network time (UTC) in ansi C through NTP or other protocols?...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    8

    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
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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:
    http://doolittle.icarus.com/ntpclient/

    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.

    --
    Mats
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21