100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > windows系统下向NTP服务器请求时间代码 C语言 vs windows socket udp

windows系统下向NTP服务器请求时间代码 C语言 vs windows socket udp

时间:2023-01-10 10:59:32

相关推荐

windows系统下向NTP服务器请求时间代码  C语言 vs windows socket udp

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#ifdef _WIN32

#include <string.h>

#include<WS2tcpip.h>

#include <windows.h>

#pragma comment(lib,"ws2_32.lib")

#else

#include "logLib.h"

#include "socket.h"

#endif

#define DIFF 4294.967296

#define GAP 2208988800

#define NTP_VERSION 3

#define NTP_MODE_CLIENT 0x3

#define NTP_HEADER_VERSION_SET(_header, _x) (_header |= ((_x & 0x7) << 0))

#define NTP_HEADER_MODE_SET(_header, _x) (_header |= ((_x & 0x7) << 3))

typedef struct

{

unsigned int seconds;

unsigned int fraction;

} ntp_timestamp;

typedef struct

{

int header;

int root_delay;

int root_dispersion;

int reference_identifier;

ntp_timestamp

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。