"Fossies" - the Fresh Open Source Software Archive

Member "mod_ntlm2-0.1/smbval/byteorder.h" (21 Feb 2003, 3091 Bytes) of package /linux/www/apache_httpd_modules/old/mod_ntlm2-0.1.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* mod_ntlm file: $Id: byteorder.h,v 1.3 2003/02/21 01:55:14 casz Exp $ */
    2 
    3 #ifndef BYTEORDER_H
    4 #define BYTEORDER_H
    5 
    6 /* 
    7  * Unix SMB/Netbios implementation. Version 1.9. SMB Byte handling
    8  * Copyright (C) Andrew Tridgell 1992-1995  This program is free software; 
    9  * you can redistribute it and/or modify it under the terms of the GNU
   10  * General Public License as published by the Free Software Foundation;
   11  * either version 2 of the License, or (at your option) any later version. 
   12  * This program is distributed in the hope that it will be useful, but
   13  * WITHOUT ANY WARRANTY; without even the implied warranty of
   14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General 
   15  * Public License for more details.  You should have received a copy of the
   16  * GNU General Public License along with this program; if not, write to the
   17  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
   18 
   19 /* 
   20  * This file implements macros for machine independent short and  int
   21  * manipulation */
   22 
   23 #undef CAREFUL_ALIGNMENT
   24 
   25 /* we know that the 386 can handle misalignment and has the "right" 
   26  * byteorder */
   27 #ifdef __i386__
   28 #define CAREFUL_ALIGNMENT 0
   29 #endif
   30 
   31 #ifndef CAREFUL_ALIGNMENT
   32 #define CAREFUL_ALIGNMENT 1
   33 #endif
   34 
   35 #define CVAL(buf,pos) (((unsigned char *)(buf))[pos])
   36 #define PVAL(buf,pos) ((unsigned)CVAL(buf,pos))
   37 #define SCVAL(buf,pos,val) (CVAL(buf,pos) = (val))
   38 
   39 #if CAREFUL_ALIGNMENT
   40 #define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
   41 #define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16)
   42 #define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8)
   43 #define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16))
   44 #define SVALS(buf,pos) ((int16)SVAL(buf,pos))
   45 #define IVALS(buf,pos) ((int32)IVAL(buf,pos))
   46 #define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16)(val)))
   47 #define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32)(val)))
   48 #define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val)))
   49 #define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val)))
   50 #else
   51 /* this handles things for architectures like the 386 that can handle
   52  * alignment errors */
   53 /* 
   54  * WARNING: This section is dependent on the length of int16 and int32
   55  * being correct  */
   56 #define SVAL(buf,pos) (*(uint16 *)((char *)(buf) + (pos)))
   57 #define IVAL(buf,pos) (*(uint32 *)((char *)(buf) + (pos)))
   58 #define SVALS(buf,pos) (*(int16 *)((char *)(buf) + (pos)))
   59 #define IVALS(buf,pos) (*(int32 *)((char *)(buf) + (pos)))
   60 #define SSVAL(buf,pos,val) SVAL(buf,pos)=((uint16)(val))
   61 #define SIVAL(buf,pos,val) IVAL(buf,pos)=((uint32)(val))
   62 #define SSVALS(buf,pos,val) SVALS(buf,pos)=((int16)(val))
   63 #define SIVALS(buf,pos,val) IVALS(buf,pos)=((int32)(val))
   64 #endif
   65 
   66 /* now the reverse routines - these are used in nmb packets (mostly) */
   67 #define SREV(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))
   68 #define IREV(x) ((SREV(x)<<16) | (SREV((x)>>16)))
   69 
   70 #define RSVAL(buf,pos) SREV(SVAL(buf,pos))
   71 #define RIVAL(buf,pos) IREV(IVAL(buf,pos))
   72 #define RSSVAL(buf,pos,val) SSVAL(buf,pos,SREV(val))
   73 #define RSIVAL(buf,pos,val) SIVAL(buf,pos,IREV(val))
   74 
   75 #endif
   76