AW: [En-Nut-Discussion] SNTP problems
Oliver Schulz
Oliver.Schulz at bong.de
Fri Apr 23 10:28:13 CEST 2004
Hello,
on the first look, I would say, that you forgat to allocate heap space
for *data.
Please add a line, like this: data = NutHeapAllocClear(sizeof(*data))
Since Nut/OS release 3.4.1, there are some time related functions
available, among them also a (working) sntp client in /pro/sntp.c.
Cheers,
Oliver.
-----Ursprungliche Nachricht-----
Von: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de]Im Auftrag von tomek w
Gesendet: Freitag, 23. April 2004 02:36
An: en-nut-discussion at egnite.de
Betreff: [En-Nut-Discussion] SNTP problems
Hi everyone.
I am working on some project now and i need to synchronise Ethernut
board using SNTP.
I cut a little source code of Lars H. Andersson's SNTP implementation
but it doesn't work, neither the non-modified code.
What could be the problem? What i am doing wrong?
Here is part of my sorce code:
typedef struct _sntpframe sntpframe;
struct _sntpframe {
u_char mode;
u_char stratum;
u_char poll;
u_char precision;
u_long root_delay;
u_long root_dispersion;
u_long reference_identifier;
u_long reference_ts_sec;
u_long reference_ts_frac;
u_long originate_ts_sec;
u_long originate_ts_frac;
u_long receive_ts_sec;
u_long receive_ts_frac;
u_long transmit_ts_sec;
u_long transmit_ts_frac;
};
sntpframe *data;
u_long server_addr;
server_addr=inet_addr("150.254.183.15");
u_short NTPort = 123;
int len;
UDPSOCKET *sock = NULL;
u_long rec_addr = 0;
u_short port;
u_short bufsize = 256;
sock = NutUdpCreateSocket(0);
data->mode = 0x1B;
NutUdpSetSockOpt(sock, SO_RCVBUF, &bufsize, sizeof(bufsize));
NutUdpSendTo(sock, server_addr,NTPort, data, sizeof(*data));
len = NutUdpReceiveFrom(sock, &rec_addr, &port, data, sizeof(*data),
5000);
NutUdpDestroySocket(sock);
It returns sth not equal to 0 for createsocket, 0 for udpsend and 0 for
udpreceive.
I checked the server adress with windows ntp client and it works all the
time.
Thanks for any help.
_____
Do you Yahoo!?
Yahoo! Photos: High-quality
<http://pa.yahoo.com/*http://us.rd.yahoo.com/evt=23765/*http://photos.ya
hoo.com/ph/print_splash> 4x6 digital prints for 25c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.egnite.de/pipermail/en-nut-discussion/attachments/20040423/19ce5430/attachment.html>
More information about the En-Nut-Discussion
mailing list