2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1992-1995
6 Copyright 2006 The FreeRADIUS server project
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 This file implements macros for machine independent short and
28 #include <freeradius-devel/ident.h>
29 RCSIDH(byteorder_h, "$Id$")
31 #undef CAREFUL_ALIGNMENT
33 /* we know that the 386 can handle misalignment and has the "right"
36 #define CAREFUL_ALIGNMENT 0
39 #ifndef CAREFUL_ALIGNMENT
40 #define CAREFUL_ALIGNMENT 1
43 #define CVAL(buf,pos) (((unsigned char *)(buf))[pos])
44 #define PVAL(buf,pos) ((unsigned)CVAL(buf,pos))
45 #define SCVAL(buf,pos,val) (CVAL(buf,pos) = (val))
49 #define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
50 #define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16)
51 #define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8)
52 #define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16))
53 #define SVALS(buf,pos) ((int16)SVAL(buf,pos))
54 #define IVALS(buf,pos) ((int32)IVAL(buf,pos))
55 #define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16)(val)))
56 #define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32)(val)))
57 #define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val)))
58 #define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val)))
60 /* this handles things for architectures like the 386 that can handle
63 WARNING: This section is dependent on the length of int16 and int32
66 #define SVAL(buf,pos) (*(uint16 *)((char *)(buf) + (pos)))
67 #define IVAL(buf,pos) (*(uint32 *)((char *)(buf) + (pos)))
68 #define SVALS(buf,pos) (*(int16 *)((char *)(buf) + (pos)))
69 #define IVALS(buf,pos) (*(int32 *)((char *)(buf) + (pos)))
70 #define SSVAL(buf,pos,val) SVAL(buf,pos)=((uint16)(val))
71 #define SIVAL(buf,pos,val) IVAL(buf,pos)=((uint32)(val))
72 #define SSVALS(buf,pos,val) SVALS(buf,pos)=((int16)(val))
73 #define SIVALS(buf,pos,val) IVALS(buf,pos)=((int32)(val))
77 /* now the reverse routines - these are used in nmb packets (mostly) */
78 #define SREV(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))
79 #define IREV(x) ((SREV(x)<<16) | (SREV((x)>>16)))
81 #define RSVAL(buf,pos) SREV(SVAL(buf,pos))
82 #define RIVAL(buf,pos) IREV(IVAL(buf,pos))
83 #define RSSVAL(buf,pos,val) SSVAL(buf,pos,SREV(val))
84 #define RSIVAL(buf,pos,val) SIVAL(buf,pos,IREV(val))