1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/xie_tong-ntp_time

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
ntp_time.h 1.9 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
xietong Отправлено 27.07.2017 11:42 0473ab5
/********************************************************************************
源代码来自网络,经本人精简ntp部分,供大家参考
*********************************************************************************/
#ifndef __NTP_TIME_H__
#define __NTP_TIME_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <time.h>
// #include <stdarg.h>
// #include <netinet/in.h>
// #include <sys/socket.h>
// #include <sys/types.h>
// #include <arpa/inet.h>
// #include <sys/select.h>
// #include <sys/param.h>
// #include <sys/stat.h>
// #include <fcntl.h>
//授时服务器 端口默认 123
#define DEF_NTP_SERVER "ntp.neu.edu.cn" //东北大学网络授时服务,为您提供高精度的网络授时服务
#define DEF_NTP_SERVER_IP "202.112.31.197"
#define DEF_NTP_PORT 123
//默认请求数据包填充
#define LI 0 //协议头中的元素
#define VN 3 //版本
#define MODE 3 //模式 : 客户端请求
#define STRATUM 0
#define POLL 4 //连续信息间的最大间隔
#define PREC -6 //本地时钟精度
//校验时间计算用到的宏
//ntp时间从年开始,本地时间从年开始,这是两者之间的差值
#define JAN_1970 0x83aa7e80 //3600s*24h*(365days*70years+17days)
//x*10^(-6)*2^32 微妙数转 NtpTime 结构的 fraction 部分
#define NTPFRAC(x) (4294 * (x) + ((1981 * (x)) >> 11))
//NTPFRAC的逆运算
#define USEC(x) (((x) >> 12) - 759 * ((((x) >> 10) + 32768) >> 16))
#define MKSEC(ntpt) ((ntpt).integer - JAN_1970)
#define MKUSEC(ntpt) (USEC((ntpt).fraction))
#define TTLUSEC(sec, usec) ((long long)(sec)*1000000 + (usec))
#define GETSEC(us) ((us) / 1000000)
#define GETUSEC(us) ((us) % 1000000)
#define DATA(i) ntohl(((unsigned int *)data)[i])
#define PDEBUG(fmt, args...) printf("[%s:%d]" fmt "\n", __func__, __LINE__, ##args)
//ntp时间戳结构
typedef struct
{
unsigned int integer;
unsigned int fraction;
} NtpTime;
#endif

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/xie_tong-ntp_time.git
git@api.gitlife.ru:oschina-mirror/xie_tong-ntp_time.git
oschina-mirror
xie_tong-ntp_time
xie_tong-ntp_time
master