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
This commit is contained in:
parent
bc71cd74fa
commit
6d9b3e65a0
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user