summaryrefslogtreecommitdiffstats
path: root/sys/netncp
diff options
context:
space:
mode:
authormarius <marius@FreeBSD.org>2005-01-03 18:03:00 +0000
committermarius <marius@FreeBSD.org>2005-01-03 18:03:00 +0000
commit064653b217a3373de95a0378ad82df9645417d2e (patch)
tree497bb53d1054427b49422fa3646b449b81582e54 /sys/netncp
parent758ffb0989cb7f50d33f4651338db9e8ac338528 (diff)
downloadFreeBSD-src-064653b217a3373de95a0378ad82df9645417d2e.zip
FreeBSD-src-064653b217a3373de95a0378ad82df9645417d2e.tar.gz
Use byteorder(9) functions to implement the [g,s]et[d,w][b,l]e macros so
only one set is needed for either endianess. This also completes them for big endian archs and fixes the compilation of libncp, netncp, etc. there. Reviewed by: bp, rwatson Compile tested on: i386, sparc64 MFC after: 1 week
Diffstat (limited to 'sys/netncp')
-rw-r--r--sys/netncp/ncp_rq.h50
1 files changed, 14 insertions, 36 deletions
diff --git a/sys/netncp/ncp_rq.h b/sys/netncp/ncp_rq.h
index 62c7ce4..3697635 100644
--- a/sys/netncp/ncp_rq.h
+++ b/sys/netncp/ncp_rq.h
@@ -34,47 +34,25 @@
#ifndef _NETNCP_NCP_RQ_H_
#define _NETNCP_NCP_RQ_H_
-#include <machine/endian.h>
+#include <sys/endian.h>
#define getb(buf,ofs) (((const u_int8_t *)(buf))[ofs])
#define setb(buf,ofs,val) (((u_int8_t*)(buf))[ofs])=val
#define getbw(buf,ofs) ((u_int16_t)(getb(buf,ofs)))
-#if (BYTE_ORDER == LITTLE_ENDIAN)
-
-#define getwle(buf,ofs) (*((u_int16_t*)(&((u_int8_t*)(buf))[ofs])))
-#define getdle(buf,ofs) (*((u_int32_t*)(&((u_int8_t*)(buf))[ofs])))
-#define getwbe(buf,ofs) (ntohs(getwle(buf,ofs)))
-#define getdbe(buf,ofs) (ntohl(getdle(buf,ofs)))
-
-#define setwle(buf,ofs,val) getwle(buf,ofs)=val
-#define setwbe(buf,ofs,val) getwle(buf,ofs)=htons(val)
-#define setdle(buf,ofs,val) getdle(buf,ofs)=val
-#define setdbe(buf,ofs,val) getdle(buf,ofs)=htonl(val)
-
-#else
-#error "Macros for Big-Endians are incomplete"
-#define getwle(buf,ofs) ((u_int16_t)(getb(buf, ofs) | (getb(buf, ofs + 1) << 8)))
-#define getdle(buf,ofs) ((u_int32_t)(getb(buf, ofs) | \
- (getb(buf, ofs + 1) << 8) | \
- (getb(buf, ofs + 2) << 16) | \
- (getb(buf, ofs + 3) << 24)))
-#define getwbe(buf,ofs) (*((u_int16_t*)(&((u_int8_t*)(buf))[ofs])))
-#define getdbe(buf,ofs) (*((u_int32_t*)(&((u_int8_t*)(buf))[ofs])))
-/*
-#define setwle(buf,ofs,val) getwle(buf,ofs)=val
-#define setdle(buf,ofs,val) getdle(buf,ofs)=val
-*/
-#define setwbe(buf,ofs,val) getwle(buf,ofs)=val
-#define setdbe(buf,ofs,val) getdle(buf,ofs)=val
-/*
-#define htoles(x) ((u_int16_t)(x))
-#define letohs(x) ((u_int16_t)(x))
-#define htolel(x) ((u_int32_t)(x))
-#define letohl(x) ((u_int32_t)(x))
-*/
-#endif
-
+#define getwle(buf,ofs) (le16toh(*((u_int16_t*)(&((u_int8_t*)(buf))[ofs]))))
+#define getdle(buf,ofs) (le32toh(*((u_int32_t*)(&((u_int8_t*)(buf))[ofs]))))
+#define getwbe(buf,ofs) (be16toh(*((u_int16_t*)(&((u_int8_t*)(buf))[ofs]))))
+#define getdbe(buf,ofs) (be32toh(*((u_int32_t*)(&((u_int8_t*)(buf))[ofs]))))
+
+#define setwle(buf,ofs,val) \
+ (*((u_int16_t*)(&((u_int8_t*)(buf))[ofs])))=htole16(val)
+#define setdle(buf,ofs,val) \
+ (*((u_int32_t*)(&((u_int8_t*)(buf))[ofs])))=htole32(val)
+#define setwbe(buf,ofs,val) \
+ (*((u_int16_t*)(&((u_int8_t*)(buf))[ofs])))=htobe16(val)
+#define setdbe(buf,ofs,val) \
+ (*((u_int32_t*)(&((u_int8_t*)(buf))[ofs])))=htobe32(val)
#ifdef _KERNEL
OpenPOWER on IntegriCloud