Possible Duplicate:
Is there any C/C++ library to connect with a remote NTP server?
I’m searching for a working code in c/c++ that gets the time and date from the server(ntp.belnet.be). It works with UDP and uses port 123.
Can someone help?
//sending pakket
memset(&sntp_msg_header, 0, sizeof sntp_msg_header);
sntp_msg_header.flags = 27;
sntp_msg_header.originate_timestamp_secs = time(NULL);
// Get data in rxmsg
...
...
// print time
timeval = ntohl(rxmsg.transmit_timestamp_secs) - ((70ul * 365ul + 17ul) * 86400ul);
printf("%s", ctime(&timeval));
This is what i have so far. But i can’t get the correct data out of it.
I hope this is more information.
This is a code snippet in linux. Hope this will help. I don’t know how to convert it to c++.