4 * Masami Komiya <mkomiya@sonare.it> 2005
15 #if ((CONFIG_COMMANDS & CFG_CMD_NET) && (CONFIG_COMMANDS & CFG_CMD_SNTP))
17 #define SNTP_TIMEOUT 10
19 static int SntpOurPort;
24 struct sntp_pkt_t pkt;
25 int pktlen = SNTP_PACKET_LEN;
28 debug ("%s\n", __FUNCTION__);
30 memset (&pkt, 0, sizeof(pkt));
32 pkt.li = NTP_LI_NOLEAP;
34 pkt.mode = NTP_MODE_CLIENT;
36 memcpy ((char *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE, (char *)&pkt, pktlen);
38 SntpOurPort = 10000 + (get_timer(0) % 4096);
39 sport = NTP_SERVICE_PORT;
41 NetSendUDPPacket (NetServerEther, NetNtpServerIP, sport, SntpOurPort, pktlen);
48 NetState = NETLOOP_FAIL;
53 SntpHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
55 struct sntp_pkt_t rpkt;
58 debug ("%s\n", __FUNCTION__);
60 if (dest != SntpOurPort) return;
62 memcpy ((unsigned char *)&rpkt, pkt, len);
64 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
65 to_tm(ntohl(rpkt.transmit_timestamp), &tm);
66 printf ("Date: %4d-%02d-%02d Time: %2d:%02d:%02d\n",
67 tm.tm_year, tm.tm_mon, tm.tm_mday,
68 tm.tm_hour, tm.tm_min, tm.tm_sec);
69 to_tm(ntohl(rpkt.transmit_timestamp) - 2208988800u + NetTimeOffset, &tm);
70 #if (CONFIG_COMMANDS & CFG_CMD_DATE)
73 printf ("Date: %4d-%02d-%02d Time: %2d:%02d:%02d\n",
74 tm.tm_year, tm.tm_mon, tm.tm_mday,
75 tm.tm_hour, tm.tm_min, tm.tm_sec);
78 NetState = NETLOOP_SUCCESS;
84 debug ("%s\n", __FUNCTION__);
86 NetSetTimeout (SNTP_TIMEOUT * CFG_HZ, SntpTimeout);
87 NetSetHandler(SntpHandler);
88 memset (NetServerEther, 0, 6);
93 #endif /* CONFIG_COMMANDS & CFG_CMD_SNTP */