From 94e3701a51cb5dab7e1641e993c087b64c1694b7 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Mon, 14 Mar 2011 11:20:57 +0100 Subject: [PATCH] [lib] Add TIMESTAMP endianess converters Add the functions owl_hton_timestamp() and owl_ntoh_timestamp(). --- libowlps/libowlps.c | 26 ++++++++++++++++++++++++++ libowlps/owlps.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/libowlps/libowlps.c b/libowlps/libowlps.c index 3e58613..bc7edeb 100644 --- a/libowlps/libowlps.c +++ b/libowlps/libowlps.c @@ -165,6 +165,32 @@ uint_fast32_t owl_time_elapsed(TIMESTAMP sup, TIMESTAMP inf) +/* + * Converts a TIMESTAMP from host endianess to network endianess. + */ +TIMESTAMP owl_hton_timestamp(TIMESTAMP date) +{ + TIMESTAMP d ; + d.tv_sec = htonl(date.tv_sec) ; + d.tv_nsec = htonl(date.tv_nsec) ; + return d ; +} + + + +/* + * Converts a TIMESTAMP from network endianess to host endianess. + */ +TIMESTAMP owl_ntoh_timestamp(TIMESTAMP date) +{ + TIMESTAMP d ; + d.tv_sec = ntohl(date.tv_sec) ; + d.tv_nsec = ntohl(date.tv_nsec) ; + return d ; +} + + + /* * Compares two MAC addresses. * Returns TRUE if they are identical, FALSE otherwise. diff --git a/libowlps/owlps.h b/libowlps/owlps.h index 46e9224..51fe315 100644 --- a/libowlps/owlps.h +++ b/libowlps/owlps.h @@ -229,6 +229,8 @@ void owl_timestamp_round_to_ms(TIMESTAMP *now) ; TIMESTAMP owl_timeval_to_timestamp(const struct timeval d) ; uint64_t owl_timestamp_to_ms(TIMESTAMP date) ; uint_fast32_t owl_time_elapsed(TIMESTAMP sup, TIMESTAMP inf) ; +TIMESTAMP owl_hton_timestamp(TIMESTAMP date) ; +TIMESTAMP owl_ntoh_timestamp(TIMESTAMP date) ; // Network int owl_create_udp_trx_socket(char *server_address,