Listing 1.2
Second Level Encoding


int L2_Encode( uchar *dst, const uchar *name, const uchar *scope )
  {
  int lenpos;
  int i;
  int j;

  /* First Level Encode the NetBIOS Name.
   * Prefix it with label length.
   * (dec 32 == 0x20)
   */
  if( NULL == L1_Encode( &dst[1], name ) )
    return( -1 );
  dst[0] = 0x20;
  lenpos = 33;

  /* Copy each scope label to dst,
   * adding the length byte as an
   * afterthought.
   */
  if( '\0' != *scope )
    {
    do
      {
      for( i = 0, j = (lenpos + 1);
           ('.' != scope[i]) && ('\0' != scope[i]);
           i++, j++)
        dst[j] = scope[i];

      dst[lenpos] = (uchar)i;
      lenpos     += i + 1;
      scope      += i;
      } while( '.' == *(scope++) );
    dst[lenpos] = '\0';
    }

  return( lenpos + 1 );
  } /* L2_Encode */


$Revision: 1.12 $
$Date: 2003/02/18 21:43:58 $
[W3C Validated] Copyright © 1999-2003 Christopher R. Hertel 
Released under the terms of the LGPL