2024年4月16日发(作者:)
203 maxfd1 = sockfd + 1;
204
205
206 _sec = TIMEOUT;
207 _usec = 0;
208
209 if (select(maxfd1, &readfds, NULL, NULL, &timeout) > 0) {
210 if (FD_ISSET(sockfd, &readfds))
211 {
212 if ((nbytes = recv(sockfd, buf, BUFSIZE, 0)) < 0)
213 {
214 perror("recv error");
215 exit(-1);
216 }
217
218 //计算C/S时间偏移量
219 gettimeofday(&recvtv, NULL);
220 offset = get_offset((struct ntphdr *) buf, &recvtv);
221 ////更新系统时间
222
223 gettimeofday(&tv, NULL);
224
225 _sec += (int) offset +28800;
226 _usec += offset - (int) offset;
227
228 local = localtime((time_t *) &_sec);
229 strftime(dateBuf, 64, "%Y-%m-%d %H:%M:%S", local);
230 sprintf(cmd, "system busybox date -s "%s"", dateBuf);
231
232 printf("%s n", ctime((time_t *) &_sec));
233
234
235 }
236 }
237
238 close(sockfd);
239
240 return 0;
241 }


发布评论