4 #include "resources/net/client_socket.h"
5 #include "resources/net/udp.h"
7 #include "time_source.h"
10 class ntp_client
: time_source
{
38 p
<net::client_socket
> client
;
47 void set(p
<net::udp
> u
) {
48 client
= u
->create_client();
49 client
->connect(net::ipv4_addr::from_le(213 << 24 | 134 << 16 | 184 << 8 | 12), ntp_port
);
54 time_source::time_stamp
get_timestamp() {
55 pkg
->flags
= ntp_cli
| ntp_ver4
| ntp_alarm
;
57 pkg
->ref_clock_id
= to_be32(0x494e4954);
59 client
->write(buffer::to_mem(pkg
));
61 buffer buf
= buffer::to_mem(pkg
);
64 time_source::time_stamp timestamp
= from_be32(buf
.cast
<ntp_packet
>()->rec_time_stamp
[0]);
66 /* NTP uses Jan 01 1900 as a base, we need Jan 01 1970 */
67 timestamp
-= 2208988800;