// 向广播地址发 SNTP 请求
int s = socket(AF_INET, SOCK_DGRAM, 0);
int on = 1;
setsockopt(s, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on));
struct sockaddr_in dst;
dst.sin_family = AF_INET;
dst.sin_port = htons(123);
inet_pton(AF_INET, "255.255.255.255", &dst.sin_addr);
uint8_t req[48] = {0}; req[0] = 0x1B; // NTP v3 client
sendto(s, req, 48, 0, (struct sockaddr*)&dst, sizeof(dst));
// recvfrom 收响应:时间戳在 40-43 字节(1900基准)