Listing 1.12
Listing ADDR_ENTRY Records


#include "NS_RDaddr.h"

int Find_RDLength( uchar *msg )
  /* ---------------------------------------------------- **
   * Calculate the offset of the RDLENGTH field within a
   * POSITIVE NAME QUERY RESPONSE.
   * ---------------------------------------------------- **
   */
  {
  int len;

  len = 12                        /* Length of the header */
      + strlen( &msg[12] ) + 1    /* NBT Name length      */
      + 2 + 2 + 4;                /* Type, Class, & TTL   */
  return( len );
  } /* Find_RDLength */


void List_Addr_Entry( uchar *msg )
  /* ---------------------------------------------------- **
   * This function nicely prints the contents of an
   * RDATA.ADDR_ENTRY[] array.
   * ---------------------------------------------------- **
   */
  {
  ushort numIPs;
  ushort flags;
  int    offset;
  int    i;

  offset = Find_RDLength( msg );
  numIPs = Get_RDLength( msg, offset ) / 6;
  offset += 2;  /* Move past the RDLENGTH field. */

  for( i = 0; i < numIPs ; i++, offset += 6 )
    {
    /* Read the NB_FLAGS field. */
    flags = Get_RD_NB_Flags( msg, offset );

    /* If there are more than one, number the entries. */
    if( numIPs > 1 )
      printf( "ADDR_ENTRY[%d]: ", i );

    /* Print the IP address. */
    printf( "%d.%d.%d.%d\t",
            msg[offset+2], msg[offset+3],
            msg[offset+4], msg[offset+5] );

    /* Group or Unique. */
    if( GROUP_BIT & flags )
      printf( "<Group>\t" );
    else
      printf( "<Unique>\t" );

    /* Finally, the owner node type. */
    switch( ONT_MASK & flags )
      {
      case ONT_B: printf( "<B-node>\n" ); break;
      case ONT_P: printf( "<P-node>\n" ); break;
      case ONT_M: printf( "<M-node>\n" ); break;
      case ONT_H: printf( "<H-node>\n" ); break;
      }
    }
  } /* List_Addr_Entry */


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