Ignore:
Timestamp:
03/02/10 19:08:42 (15 years ago)
Author:
tim
Message:

merged remaining smb_deps items into regfi

began formatting API comments for use with doxygen

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/byteorder.h

    r111 r168  
    1 /* 
     1/*
    22 * Branched from Samba project Subversion repository, version #2:
    33 *  http://websvn.samba.org/cgi-bin/viewcvs.cgi/trunk/source/include/byteorder.h
     
    2828#define _BYTEORDER_H
    2929
    30 /*
    31    This file implements macros for machine independent short and
    32    int manipulation
     30/**
     31 * @file
     32 *
     33 * This file implements macros for machine independent short and
     34 * int manipulation
     35
     36@verbatim
    3337
    3438Here is a description of this file that I emailed to the samba list once:
     
    5458Ok, now to the macros themselves. I'll take a simple example, say we
    5559want to extract a 2 byte integer from a SMB packet and put it into a
    56 type called uint16 that is in the local machines byte order, and you
    57 want to do it with only the assumption that uint16 is _at_least_ 16
     60type called uint16_t that is in the local machines byte order, and you
     61want to do it with only the assumption that uint16_t is _at_least_ 16
    5862bits long (this last condition is very important for architectures
    5963that don't have any int types that are 2 bytes long)
     
    6569#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
    6670
    67 then to extract a uint16 value at offset 25 in a buffer you do this:
     71then to extract a uint16_t value at offset 25 in a buffer you do this:
    6872
    6973char *buffer = foo_bar();
    70 uint16 xx = SVAL(buffer,25);
     74uint16_t xx = SVAL(buffer,25);
    7175
    7276We are using the byteoder independence of the ANSI C bitshifts to do
     
    98102it also defines lots of intermediate macros, just ignore those :-)
    99103
     104@endverbatim
     105
    100106*/
    101107
     
    124130#define SSVALX(buf,pos,val) (CVAL_NC(buf,pos)=(unsigned char)((val)&0xFF),CVAL_NC(buf,pos+1)=(unsigned char)((val)>>8))
    125131#define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16))
    126 #define SVALS(buf,pos) ((int16)SVAL(buf,pos))
    127 #define IVALS(buf,pos) ((int32)IVAL(buf,pos))
    128 #define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16)(val)))
    129 #define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32)(val)))
    130 #define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val)))
    131 #define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val)))
     132#define SVALS(buf,pos) ((int16_t)SVAL(buf,pos))
     133#define IVALS(buf,pos) ((int32_t)IVAL(buf,pos))
     134#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16_t)(val)))
     135#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32_t)(val)))
     136#define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16_t)(val)))
     137#define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32_t)(val)))
    132138
    133139#else /* CAREFUL_ALIGNMENT */
     
    136142   alignment errors */
    137143/*
    138    WARNING: This section is dependent on the length of int16 and int32
     144   WARNING: This section is dependent on the length of int16_t and int32_t
    139145   being correct
    140146*/
    141147
    142148/* get single value from an SMB buffer */
    143 #define SVAL(buf,pos) (*(const uint16 *)((const char *)(buf) + (pos)))
    144 #define SVAL_NC(buf,pos) (*(uint16 *)((char *)(buf) + (pos))) /* Non const version of above. */
    145 #define IVAL(buf,pos) (*(const uint32 *)((const char *)(buf) + (pos)))
    146 #define IVAL_NC(buf,pos) (*(uint32 *)((char *)(buf) + (pos))) /* Non const version of above. */
    147 #define SVALS(buf,pos) (*(const int16 *)((const char *)(buf) + (pos)))
    148 #define SVALS_NC(buf,pos) (*(int16 *)((char *)(buf) + (pos))) /* Non const version of above. */
    149 #define IVALS(buf,pos) (*(const int32 *)((const char *)(buf) + (pos)))
    150 #define IVALS_NC(buf,pos) (*(int32 *)((char *)(buf) + (pos))) /* Non const version of above. */
     149#define SVAL(buf,pos) (*(const uint16_t *)((const char *)(buf) + (pos)))
     150#define SVAL_NC(buf,pos) (*(uint16_t *)((char *)(buf) + (pos))) /* Non const version of above. */
     151#define IVAL(buf,pos) (*(const uint32_t *)((const char *)(buf) + (pos)))
     152#define IVAL_NC(buf,pos) (*(uint32_t *)((char *)(buf) + (pos))) /* Non const version of above. */
     153#define SVALS(buf,pos) (*(const int16_t *)((const char *)(buf) + (pos)))
     154#define SVALS_NC(buf,pos) (*(int16_t *)((char *)(buf) + (pos))) /* Non const version of above. */
     155#define IVALS(buf,pos) (*(const int32_t *)((const char *)(buf) + (pos)))
     156#define IVALS_NC(buf,pos) (*(int32_t *)((char *)(buf) + (pos))) /* Non const version of above. */
    151157
    152158/* store single value in an SMB buffer */
    153 #define SSVAL(buf,pos,val) SVAL_NC(buf,pos)=((uint16)(val))
    154 #define SIVAL(buf,pos,val) IVAL_NC(buf,pos)=((uint32)(val))
    155 #define SSVALS(buf,pos,val) SVALS_NC(buf,pos)=((int16)(val))
    156 #define SIVALS(buf,pos,val) IVALS_NC(buf,pos)=((int32)(val))
     159#define SSVAL(buf,pos,val) SVAL_NC(buf,pos)=((uint16_t)(val))
     160#define SIVAL(buf,pos,val) IVAL_NC(buf,pos)=((uint32_t)(val))
     161#define SSVALS(buf,pos,val) SVALS_NC(buf,pos)=((int16_t)(val))
     162#define SIVALS(buf,pos,val) IVALS_NC(buf,pos)=((int32_t)(val))
    157163
    158164#endif /* CAREFUL_ALIGNMENT */
Note: See TracChangeset for help on using the changeset viewer.