[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] NTP server connections



Erryn Duncan <errynd@dlux.net> writes:
}Has anyone tried to write a MacPerl script to connect to an NTP server, get
}the timestamp, and convert the 64 bit unsigned integer to text?
}
}The rfc2030 states:
}
}>   Since NTP timestamps are cherished data and, in fact, represent the
}>   main product of the protocol, a special timestamp format has been
}>   established. NTP timestamps are represented as a 64-bit unsigned
}>   fixed-point number, in seconds relative to 0h on 1 January 1900. The
}>   integer part is in the first 32 bits and the fraction part in the
}>   last 32 bits. In the fraction part, the non-significant low order can
}>   be set to 0.
}
}What packages do I need?  Does anyone have an approach to this problem?

You mean like this?

#!perl

use Net::Time qw(inet_time);
print inet_time."\n";

To do this, you need Net::Time, part of Graham Barr's libnet package.  You can get the MacPerl port of libnet at <ftp://mors.gsfc.nasa.gov/pub/MacPerl/Scripts/>.  Read the pod (start up Shuck and open the :Net:Time.pm file) in Net::Time, but note that I've modified Net::Time to give Macintosh time (seconds past Jan 1 1904) rather than Unix time (seconds past Jan 1 1970).  If you want to go back to seconds past Jan 1 1900, the conversion is to add 4 * 31536000 to the inet_time you get back from MacPerl (or 2208988800 to the Unix time).   You will also need to create a Net::Config for this to work this simply; otherwise give inet_time the name of the time server you want to use.

Net::Time is doing RFC868, but you should be able to hack it to get a fractional part if you want from an RFC2020 time server (which I've just done but my timeserver doesn't seem to give more than four bytes back anyway).

}
}--Erryn
}
}
}
}| Erryn Duncan
}| PGP ID: A2A19021 
}
}
}
}***** Want to unsubscribe from this list?
}***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch


---
Paul J. Schinder
NASA Goddard Space Flight Center
Code 693, Greenbelt, MD 20771
schinder@pjstoaster.pg.md.us



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch