netatalk  4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
byteorder.h File Reference
#include <arpa/inet.h>

Go to the source code of this file.

Macros

#define CVAL(buf, pos)   ((unsigned)(((const unsigned char *)(buf))[pos]))
 
#define CVAL_NC(buf, pos)   (((unsigned char *)(buf))[pos])
 
#define PVAL(buf, pos)   (CVAL(buf,pos))
 
#define SCVAL(buf, pos, val)   (CVAL_NC(buf,pos) = (val))
 
#define SVAL(buf, pos)   (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
 
#define SVALS(buf, pos)   ((int16_t)SVAL(buf,pos))
 
#define IVAL(buf, pos)   (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16)
 
#define IVALS(buf, pos)   ((int32_t)IVAL(buf,pos))
 
#define LVAL(buf, pos)   (IVAL(buf,pos)|((uint64_t)IVAL(buf,(pos)+4))<<32)
 
#define LVALS(buf, pos)   ((int64_t)LVAL(buf,pos))
 
#define SSVALX(buf, pos, val)   (CVAL_NC(buf,pos)=(unsigned char)((val)&0xFF),CVAL_NC(buf,pos+1)=(unsigned char)((val)>>8))
 
#define SIVALX(buf, pos, val)   (SSVALX(buf,pos,((val)&0xFFFF)),SSVALX(buf,pos+2,(val)>>16))
 
#define SLVALX(buf, pos, val)   (SIVALX(buf,pos,((val)&0xFFFFFFFF)),SIVALX(buf,pos+4,(val)>>32))
 
#define SSVAL(buf, pos, val)   SSVALX((buf),(pos),((uint16_t)(val)))
 
#define SSVALS(buf, pos, val)   SSVALX((buf),(pos),((int16_t)(val)))
 
#define SIVAL(buf, pos, val)   SIVALX((buf),(pos),((uint32_t)(val)))
 
#define SIVALS(buf, pos, val)   SIVALX((buf),(pos),((int32_t)(val)))
 
#define SLVAL(buf, pos, val)   SLVALX((buf),(pos),((uint64_t)(val)))
 
#define SLVALS(buf, pos, val)   SLVALX((buf),(pos),((int64_t)(val)))
 
#define SREV(x)   ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))
 
#define IREV(x)   ((SREV((uint32_t)(x))<<16) | (SREV(((uint32_t)(x))>>16)))
 
#define LREV(x)   (((uint64_t)IREV(x)<<32) | (IREV((x)>>32)))
 
#define RSVAL(buf, pos)   SREV(SVAL(buf,pos))
 
#define RSVALS(buf, pos)   SREV(SVALS(buf,pos))
 
#define RIVAL(buf, pos)   IREV(IVAL(buf,pos))
 
#define RIVALS(buf, pos)   IREV(IVALS(buf,pos))
 
#define RLVAL(buf, pos)   LREV(LVAL(buf,pos))
 
#define RLVALS(buf, pos)   LREV(LVALS(buf,pos))
 
#define RSSVAL(buf, pos, val)   SSVAL(buf,pos,SREV(val))
 
#define RSSVALS(buf, pos, val)   SSVALS(buf,pos,SREV(val))
 
#define RSIVAL(buf, pos, val)   SIVAL(buf,pos,IREV(val))
 
#define RSIVALS(buf, pos, val)   SIVALS(buf,pos,IREV(val))
 
#define RSLVAL(buf, pos, val)   SLVAL(buf,pos,LREV(val))
 
#define RSLVALS(buf, pos, val)   SLVALS(buf,pos,LREV(val))
 
#define ALIGN4(p, base)   ((p) + ((4 - (PTR_DIFF((p), (base)) & 3)) & 3))
 
#define ALIGN2(p, base)   ((p) + ((2 - (PTR_DIFF((p), (base)) & 1)) & 1))
 

Detailed Description

Macros for machine independent short and int manipulation.

Derived from Samba's byteorder.h by Andrew Tridgell, where SVAL/IVAL always decode little-endian SMB wire format using byte-order independent arithmetic, and RSVAL/RIVAL always decode big-endian (NMB) wire format.

The netatalk version replaces this with a big-endian conditional that changes the semantics: SVAL/IVAL read in host-native byte order (safe unaligned access), and RSVAL/RIVAL read in the opposite byte order. This was done to support AFP (a big-endian protocol) and native-order in-memory Unicode on big-endian Unix servers.

Macro Definition Documentation

◆ ALIGN2

#define ALIGN2 (   p,
  base 
)    ((p) + ((2 - (PTR_DIFF((p), (base)) & 1)) & 1))

◆ ALIGN4

#define ALIGN4 (   p,
  base 
)    ((p) + ((4 - (PTR_DIFF((p), (base)) & 3)) & 3))

◆ CVAL

#define CVAL (   buf,
  pos 
)    ((unsigned)(((const unsigned char *)(buf))[pos]))

◆ CVAL_NC

#define CVAL_NC (   buf,
  pos 
)    (((unsigned char *)(buf))[pos])

Non-const version of CVAL

◆ IREV

#define IREV (   x)    ((SREV((uint32_t)(x))<<16) | (SREV(((uint32_t)(x))>>16)))

◆ IVAL

#define IVAL (   buf,
  pos 
)    (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16)

◆ IVALS

#define IVALS (   buf,
  pos 
)    ((int32_t)IVAL(buf,pos))

◆ LREV

#define LREV (   x)    (((uint64_t)IREV(x)<<32) | (IREV((x)>>32)))

◆ LVAL

#define LVAL (   buf,
  pos 
)    (IVAL(buf,pos)|((uint64_t)IVAL(buf,(pos)+4))<<32)

◆ LVALS

#define LVALS (   buf,
  pos 
)    ((int64_t)LVAL(buf,pos))

◆ PVAL

#define PVAL (   buf,
  pos 
)    (CVAL(buf,pos))

◆ RIVAL

#define RIVAL (   buf,
  pos 
)    IREV(IVAL(buf,pos))

◆ RIVALS

#define RIVALS (   buf,
  pos 
)    IREV(IVALS(buf,pos))

◆ RLVAL

#define RLVAL (   buf,
  pos 
)    LREV(LVAL(buf,pos))

◆ RLVALS

#define RLVALS (   buf,
  pos 
)    LREV(LVALS(buf,pos))

◆ RSIVAL

#define RSIVAL (   buf,
  pos,
  val 
)    SIVAL(buf,pos,IREV(val))

◆ RSIVALS

#define RSIVALS (   buf,
  pos,
  val 
)    SIVALS(buf,pos,IREV(val))

◆ RSLVAL

#define RSLVAL (   buf,
  pos,
  val 
)    SLVAL(buf,pos,LREV(val))

◆ RSLVALS

#define RSLVALS (   buf,
  pos,
  val 
)    SLVALS(buf,pos,LREV(val))

◆ RSSVAL

#define RSSVAL (   buf,
  pos,
  val 
)    SSVAL(buf,pos,SREV(val))

◆ RSSVALS

#define RSSVALS (   buf,
  pos,
  val 
)    SSVALS(buf,pos,SREV(val))

◆ RSVAL

#define RSVAL (   buf,
  pos 
)    SREV(SVAL(buf,pos))

◆ RSVALS

#define RSVALS (   buf,
  pos 
)    SREV(SVALS(buf,pos))

◆ SCVAL

#define SCVAL (   buf,
  pos,
  val 
)    (CVAL_NC(buf,pos) = (val))

◆ SIVAL

#define SIVAL (   buf,
  pos,
  val 
)    SIVALX((buf),(pos),((uint32_t)(val)))

◆ SIVALS

#define SIVALS (   buf,
  pos,
  val 
)    SIVALX((buf),(pos),((int32_t)(val)))

◆ SIVALX

#define SIVALX (   buf,
  pos,
  val 
)    (SSVALX(buf,pos,((val)&0xFFFF)),SSVALX(buf,pos+2,(val)>>16))

◆ SLVAL

#define SLVAL (   buf,
  pos,
  val 
)    SLVALX((buf),(pos),((uint64_t)(val)))

◆ SLVALS

#define SLVALS (   buf,
  pos,
  val 
)    SLVALX((buf),(pos),((int64_t)(val)))

◆ SLVALX

#define SLVALX (   buf,
  pos,
  val 
)    (SIVALX(buf,pos,((val)&0xFFFFFFFF)),SIVALX(buf,pos+4,(val)>>32))

◆ SREV

#define SREV (   x)    ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))

◆ SSVAL

#define SSVAL (   buf,
  pos,
  val 
)    SSVALX((buf),(pos),((uint16_t)(val)))

◆ SSVALS

#define SSVALS (   buf,
  pos,
  val 
)    SSVALX((buf),(pos),((int16_t)(val)))

◆ SSVALX

#define SSVALX (   buf,
  pos,
  val 
)    (CVAL_NC(buf,pos)=(unsigned char)((val)&0xFF),CVAL_NC(buf,pos+1)=(unsigned char)((val)>>8))

◆ SVAL

#define SVAL (   buf,
  pos 
)    (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)

◆ SVALS

#define SVALS (   buf,
  pos 
)    ((int16_t)SVAL(buf,pos))