Is there any simple way to get Network time (UTC) in ansi C through NTP or other protocols?
Is there any simple way to get Network time (UTC) in ansi C through NTP or other protocols?
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.