[ntp:questions] sntp code: what pack_ntp is doung,
Pg
toarunpg at gmail.com
Wed Apr 9 12:09:56 UTC 2008
hi all,
i am trying to work on SNTP by using the opensource code from ntp.org.
i downloaded the code and its working. but i am not understanding what
the function pack_ntp() is doing. its in the file main.c
this is the code:
void pack_ntp (unsigned char *packet, int length, ntp_data *data) {
/* Pack the essential data into an NTP packet, bypassing struct layout
and
endian problems. Note that it ignores fields irrelevant to SNTP. */
int i, k;
double d;
memset(packet,0,(size_t)length);
packet[0] = (data->status<<6)|(data->version<<3)|data->mode;
packet[1] = data->stratum;
packet[2] = data->polling;
packet[3] = data->precision;
d = data->originate/NTP_SCALE; // 2e32
for (i = 0; i < 8; ++i) {
if ((k = (int)(d *= 256.0)) >= 256) k = 255;
packet[NTP_ORIGINATE+i] = k;
d -= k;
}
d = data->receive/NTP_SCALE;
for (i = 0; i < 8; ++i) {
if ((k = (int)(d *= 256.0)) >= 256) k = 255;
packet[NTP_RECEIVE+i] = k;
d -= k;
}
d = data->transmit/NTP_SCALE;
for (i = 0; i < 8; ++i) {
if ((k = (int)(d *= 256.0)) >= 256) k = 255;
packet[NTP_TRANSMIT+i] = k;
d -= k;
}
}
in this what is happening after deviding by NTP_SCALE and what is
happening inside for loop.
if you are having time, pls help me.
with thanks in advance,
arun.pg
More information about the questions
mailing list