I have enabled all xinetd services and I am calling it from the c program. Everything works fine but when I call the time service, it returns 4 bytes value that is unreadable. Following is one sample output.
So, How do I convert this output into a readable format?
According to Wikipedia:
After decoding to native byte order (Via
ntohl()
or friends), you can then do what you like with the value. Note that it won't work as-is with functions that take atime_t
likectime()
because the normal Unix epoch (The 0 point) is a different date. Luckily, that can be worked around by subtracting the offset of the epoch from the time protocol's 0 point from the provided time.Here's an example program that connects to the time service of the given IP address or hostname passed as its sole command line argument and prints out both the value received and a human-readable date string (Using the above mentioned offset to convert to a normal Unix time value):