aboutsummaryrefslogtreecommitdiff
path: root/sys/netncp
diff options
context:
space:
mode:
authorMarius Strobl <marius@FreeBSD.org>2005-01-03 18:03:00 +0000
committerMarius Strobl <marius@FreeBSD.org>2005-01-03 18:03:00 +0000
commit93f4f5a5605b2749b26c9138dcf215177d5ce174 (patch)
tree497bb53d1054427b49422fa3646b449b81582e54 /sys/netncp
parent87695ac7ae1e715b1a06acf0ad288b5b437b6b0f (diff)
downloadsrc-93f4f5a5605b2749b26c9138dcf215177d5ce174.tar.gz
src-93f4f5a5605b2749b26c9138dcf215177d5ce174.zip
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
Notes
Notes: svn path=/head/; revision=139644
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 62c7ce4ad69c..3697635b6e27 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