| 1234567891011121314151617181920212223242526272829303132333435363738 |
- #ifndef NTPCLIENT_H
- #define NTPCLIENT_H
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <unistd.h>
- #include <time.h>
- #include <errno.h>
-
- #define NTP_PORT 123
- #define NTP_PACKET_SIZE 48
- typedef struct NTPClient_s {
- int sockfd;
- struct sockaddr server_addr;
- char ntp_packet[NTP_PACKET_SIZE];
- int flag;
- char *server;
- int port;
- } NTPClient;
-
- NTPClient* createNTPClient(const char* ntp_server, int port, int timeout_sec);
- // 销毁NTP客户端实例
- void destroyNTPClient(NTPClient* client) ;
- // 从NTP服务器获取当前时间
- int getCurrentTimeFromNTP(NTPClient* client, time_t* current_time) ;
- // 根据时间获取星期信息
- int getCurrentWeekday(time_t current_time,char *weekday) ;
- #endif // NTPCLIENT_H
|