From: Florian Forster Date: Sat, 13 Jan 2007 11:21:16 +0000 (+0100) Subject: common.c: Implemented `ntohll' and `htonll'. X-Git-Tag: collectd-4.0.0~249 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=0c89ec2e2b332c6085aad92ba34b933ab3d441a4;p=collectd.git common.c: Implemented `ntohll' and `htonll'. --- diff --git a/src/common.c b/src/common.c index 6da5e33c..cf2a6398 100644 --- a/src/common.c +++ b/src/common.c @@ -29,6 +29,11 @@ # include #endif +/* for ntohl and htonl */ +#if HAVE_ARPA_INET_H +# include +#endif + extern int operating_mode; #ifdef HAVE_LIBKSTAT @@ -601,3 +606,21 @@ long long get_kstat_value (kstat_t *ksp, char *name) return (retval); } #endif /* HAVE_LIBKSTAT */ + +unsigned long long ntohll (unsigned long long n) +{ +#if __BYTE_ORDER == __BIG_ENDIAN + return (n); +#else + return (((unsigned long long) ntohl (n)) << 32) + ntohl (n >> 32); +#endif +} + +unsigned long long htonll (unsigned long long n) +{ +#if __BYTE_ORDER == __BIG_ENDIAN + return (n); +#else + return (((unsigned long long) htonl (n)) << 32) + htonl (n >> 32); +#endif +} diff --git a/src/common.h b/src/common.h index 8f32b227..6cf86677 100644 --- a/src/common.h +++ b/src/common.h @@ -152,4 +152,7 @@ int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name); long long get_kstat_value (kstat_t *ksp, char *name); #endif +unsigned long long ntohll (unsigned long long n); +unsigned long long htonll (unsigned long long n); + #endif /* COMMON_H */