diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2014-02-07 22:28:10 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-02-10 09:02:20 +0100 |
commit | 8abaf1ad7137e0802761d85b456591de9eaa7a5f (patch) | |
tree | b64f85443b1c1dad529ddff59024b3f7b81eb8c7 /include | |
parent | b104688cbb9c4d1e04b8a97e64b65a2bca614697 (diff) | |
download | barebox-8abaf1ad7137e0802761d85b456591de9eaa7a5f.tar.gz barebox-8abaf1ad7137e0802761d85b456591de9eaa7a5f.tar.xz |
net: provide alternatives to {ntoh, hton}[sl] funtions with cleaner semantics
ntohl always converts 32 bits even on archs where sizeof(long) == 8.
"ntoh32" is a much more intuitive name here. Also the name of the 64 bit
variant that is also added isn't questionable.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r-- | include/byteorder.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/include/byteorder.h b/include/byteorder.h new file mode 100644 index 0000000000..4b255a5fab --- /dev/null +++ b/include/byteorder.h @@ -0,0 +1,24 @@ +#ifndef __BYTEORDER_H__ +#define __BYTEORDER_H__ + +/* + * The standard macros for converting between host and network byte order are + * badly named. So ntohl converts 32 bits even on architectures where a long is + * 64 bit wide although the 'l' suffix suggests that it's working on longs. + * + * So this file introduces variants that use the bitcount as suffix instead of + * 's' or 'l'. + */ + +#include <asm/byteorder.h> + +#define ntoh16(x) __be16_to_cpu(x) +#define hton16(x) __cpu_to_be16(x) + +#define ntoh32(x) __be32_to_cpu(x) +#define hton32(x) __cpu_to_be32(x) + +#define ntoh64(x) __be64_to_cpu(x) +#define hton64(x) __cpu_to_be64(x) + +#endif /* __BYTEORDER_H__ */ |