/* 
   Unix SMB/Netbios implementation.
   Version 1.9.
   NBT netbios library routines
   Copyright (C) Andrew Tridgell 1994-1998
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   
*/

#include "includes.h"

extern int DEBUGLEVEL;


/*******************************************************************
  useful for debugging messages
  ******************************************************************/
char *nmb_namestr(struct nmb_name *n)
{
  static int i=0;
  static fstring ret[4];
  char *p = ret[i];

  nmb_safe_namestr(n, p, sizeof(fstring));

  i = (i+1)%4;
  return(p);
}

/*******************************************************************
  useful for debugging messages
  ******************************************************************/
void nmb_safe_namestr(struct nmb_name *n, char *str, size_t len)
{
  if (!n->scope[0])
    slprintf(str, len-1, "%s<%02x>",n->name,n->name_type);
  else
    slprintf(str, len-1, "%s<%02x>.%s",n->name,n->name_type,n->scope);
}

/*******************************************************************
  build a nmb name
 *******************************************************************/
void make_nmb_name( struct nmb_name *n, const char *name, int type, const char *this_scope )
{
	memset( (char *)n, '\0', sizeof(struct nmb_name) );
	StrnCpy( n->name, name, 15 );
	strupper( n->name );
	n->name_type = (unsigned int)type & 0xFF;
	StrnCpy( n->scope, this_scope, 63 );
	strupper( n->scope );
}
