00001 /* -*- c++ -*- 00002 marshall.h 00003 $Id: marshall.h,v 1.4 1999/04/30 00:59:43 haldar Exp $ 00004 00005 safely marshall and unmarshall 2 and 4 byte quantities into 00006 possibly unaligned feilds 00007 00008 NOTE: unlike the normal version of marshall, we marshall the bytes 00009 in *HOST*BYTE*ORDER* and *not* network byte order. we do this since 00010 all the other quanities in the packets will be in host byte order, and 00011 we want consistency. 00012 00013 */ 00014 00015 #ifndef _cmu_marshall_h_ 00016 #define _cmu_marshall_h_ 00017 00018 /*#ifdef sparc */ 00019 00020 /*#define GET4BYTE(x) ( (*(((unsigned char *)(x)) ) << 24) \ 00021 | (*(((unsigned char *)(x))+1) << 16) \ 00022 | (*(((unsigned char *)(x))+2) << 8) \ 00023 | (*(((unsigned char *)(x))+3) )) 00024 */ 00025 /* #define GET2BYTE(x) ( (*(((unsigned char *)(x)) ) << 8) \ 00026 | (*(((unsigned char *)(x))+1) )) 00027 */ 00028 /* let x,y be ptrs to ints, copy *x into *y */ 00029 /* #define STORE4BYTE(x,y) (((unsigned char *)y)[0] = ((unsigned char *)x)[0] ,\ 00030 ((unsigned char *)y)[1] = ((unsigned char *)x)[1] ,\ 00031 ((unsigned char *)y)[2] = ((unsigned char *)x)[2] ,\ 00032 ((unsigned char *)y)[3] = ((unsigned char *)x)[3] ) 00033 */ 00034 00035 /* #define STORE2BYTE(x,y) (((unsigned char *)y)[0] = ((unsigned char *)x)[0] ,\ 00036 ((unsigned char *)y)[1] = ((unsigned char *)x)[1] ) 00037 */ 00038 00039 /*#else 00040 00041 #include <sys/types.h> 00042 00043 #define GET4BYTE(x) *((u_int32_t*) (x)) 00044 00045 #define GET2BYTE(x) *((u_int16_t*) (x)) */ 00046 00047 /* let x,y be ptrs to ints, copy *x into *y */ 00048 /*#define STORE4BYTE(x,y) (*((u_int32_t*) (x)) = *y) 00049 00050 #define STORE2BYTE(x,y) (*((u_int16_t*) (x)) = *y) 00051 00052 #endif */ 00053 00054 /* changing STORE4BYTE and STORE2BYTE functions as they break in 00055 freeBSD; the old cmu version of STORE4BYTE used arrays to set the 00056 value: 00057 #define STORE4BYTE(x,y) (((unsigned char *)y)[0] = ((unsigned char *)x)[0] ,\ 00058 ((unsigned char *)y)[1] = ((unsigned char *)x)[1] ,\ 00059 ((unsigned char *)y)[2] = ((unsigned char *)x)[2] ,\ 00060 ((unsigned char *)y)[3] = ((unsigned char *)x)[3] ) 00061 which doesn;t work on freeBSD (with gcc version 2.7.2.1). 00062 the newer versions are tested to work in sunos/solaris/freeBSD 00063 --Padma, 04/99 */ 00064 00065 #define STORE4BYTE(x,y) ((*((unsigned char *)y)) = ((*x) >> 24) & 255 ,\ 00066 (*((unsigned char *)y+1)) = ((*x) >> 16) & 255 ,\ 00067 (*((unsigned char *)y+2)) = ((*x) >> 8) & 255 ,\ 00068 (*((unsigned char *)y+3)) = (*x) & 255 ) 00069 00070 #define STORE2BYTE(x,y) ((*((unsigned char *)y)) = ((*x) >> 8) & 255 ,\ 00071 (*((unsigned char *)y+1)) = (*x) & 255 ) 00072 00073 #define GET2BYTE(x) (((*(unsigned char *)(x)) << 8) |\ 00074 (*(((unsigned char *)(x))+1))) 00075 00076 #define GET4BYTE(x) (((*(unsigned char *)(x)) << 24) |\ 00077 (*(((unsigned char *)(x))+1) << 16) |\ 00078 (*(((unsigned char *)(x))+2) << 8) |\ 00079 (*(((unsigned char *)(x))+3))) 00080 00081 00082 #endif /* _cmu_marshall_h_ */