I’m ready to cry… I have the Perl script to handle a NTP server request. It works. I’m trying to translate it into Lua…and I can’t.
The Perl is here: http://www.kloth.net/software/sntp.php
In particular, I just can’t figure out how to pack in Lua! Here’s the code that is driving me up the wall.
$ntp_msg = pack(“B8 C3 N10 B32”, ‘00011011’, (0)x12, int($LocalTime0), $LocalTime0FB);
LI=0, VN=3, Mode=3 (client), remainder msg is 12 nulls
and the local TxTimestamp derived from $LocalTime1
After this, I will have to do some unpacking:
unpack the received ntp-message into long integer and binary values
( $Byte1, $Stratum, $Poll, $Precision,
$RootDelay, $RootDelayFB, $RootDisp, $RootDispFB, $ReferenceIdent,
$ReferenceTime, $ReferenceTimeFB, $OriginateTime, $OriginateTimeFB,
$ReceiveTime, $ReceiveTimeFB, $TransmitTime, $TransmitTimeFB) =
unpack (“a C3 n B16 n B16 H8 N B32 N B32 N B32 N B32”, $ntp_msg);
again unpack the received ntp-message into hex and ASCII values
( $dummy, $dummy, $dummy, $dummy,
$RootDelayH, $RootDelayFH, $RootDispH, $RootDispFH, $ReferenceIdentT,
$ReferenceTimeH, $ReferenceTimeFH, $OriginateTimeH, $OriginateTimeFH,
$ReceiveTimeH, $ReceiveTimeFH, $TransmitTimeH, $TransmitTimeFH) =
unpack (“a C3 H4 H4 H4 H4 a4 H8 H8 H8 H8 H8 H8 H8 H8”, $ntp_msg);
$LI = unpack(“C”, $Byte1 & “\xC0”) >> 6;
$VN = unpack(“C”, $Byte1 & “\x38”) >> 3;
$Mode = unpack(“C”, $Byte1 & “\x07”);
Please help!!! [import]uid: 37366 topic_id: 23880 reply_id: 323880[/import]