Listing 2.2.
Reading and Writing Integer Values


ushort smb_GetShort( uchar *src, int offset )
  /* ---------------------------------------------------- **
   * Read a short integer converting to host byte order
   * from a byte array in SMB byte order.
   * ---------------------------------------------------- **
   */
  {
  ushort tmp;

  /* Low order byte is first in the buffer. */
  tmp  = (ushort)(src[offset]);

  /* High order byte is next in the buffer. */
  tmp |= ( (ushort)(src[offset+1]) << 8 );

  return( tmp );
  } /* smb_GetShort */

void smb_SetShort( uchar *dst, int offset, ushort val )
  /* ---------------------------------------------------- **
   * Write a short integer in host byte order to the
   * buffer in SMB byte order.
   * ---------------------------------------------------- **
   */
  {
  /* Low order byte first. */
  dst[offset]   = (uchar)(val & 0xFF);

  /* High order byte next. */
  dst[offset+1] = (uchar)((val >> 8) & 0xFF);
  } /* smb_SetShort */

ulong smb_GetLong( uchar *src, int offset )
  /* ---------------------------------------------------- **
   * Read a long integer converting to host byte order
   * from a byte array in SMB byte order.
   * ---------------------------------------------------- **
   */
  {
  ulong tmp;

  tmp  = (ulong)(src[offset]);
  tmp |= ( (ulong)(src[offset+1]) << 8 );
  tmp |= ( (ulong)(src[offset+2]) << 16 );
  tmp |= ( (ulong)(src[offset+3]) << 24 );
  return( tmp );
  } /* smb_GetLong */

void smb_SetLong( uchar *dst, int offset, ulong val )
  /* ---------------------------------------------------- **
   * Write a long integer in host byte order to the
   * buffer in SMB byte order.
   * ---------------------------------------------------- **
   */
  {
  dst[offset]   = (uchar)(val & 0xFF);
  dst[offset+1] = (uchar)((val >> 8) & 0xFF);
  dst[offset+2] = (uchar)((val >> 16) & 0xFF);
  dst[offset+3] = (uchar)((val >> 24) & 0xFF);
  } /* smb_SetLong */


$Revision: 1.2 $
$Date: 2002/07/30 02:12:00 $
[W3C Validated] Copyright © 2002 Christopher R. Hertel 
Released under the terms of the LGPL