1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| void request_process_loop(int fd)
{
struct sockaddr src_addr;
socklen_t src_addrlen = sizeof(src_addr);
uint8_t buf[48];
uint32_t recv_time[2];
struct sockaddr_in sinaddr;
struct timeval tm;
tm.tv_sec = 1;
tm.tv_usec = 0;
setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tm, sizeof(tm));
memset(&sinaddr, 0, sizeof(sinaddr));
sinaddr.sin_family = AF_INET;
sinaddr.sin_port = htons(123);
sinaddr.sin_addr.s_addr = htonl (INADDR_ANY);
if (0 != bind(fd, (struct sockaddr *)&sinaddr, sizeof(sinaddr)))
{
LOG_E("Bind error");
closesocket(fd);
return;
}
while (1)
{
while (recvfrom(fd, buf,
48, 0,
&src_addr,
&src_addrlen)
<48 ) /* invalid request */
{
if(param_get_ntpmode() !&#061; 0) /* 此函数与TCP协议栈无关 */
{
return;
}
}
sendto( fd, buf, 48, 0, &src_addr , src_addrlen);
}
} |