/*
 *	$Source: /afs/sipb.mit.edu/project/sipb-athena/repository/src/moira/update/hostname.c,v $
 *	$Header: /afs/sipb.mit.edu/project/sipb-athena/repository/src/moira/update/hostname.c,v 1.2 1996/06/02 07:44:28 ghudson Exp $
 */
/*  (c) Copyright 1988 by the Massachusetts Institute of Technology. */
/*  For copying and distribution information, please see the file */
/*  <mit-copyright.h>. */

#ifndef lint
static char *rcsid_hostname_c = "$Header: /afs/sipb.mit.edu/project/sipb-athena/repository/src/moira/update/hostname.c,v 1.2 1996/06/02 07:44:28 ghudson Exp $";
#endif	lint

/* PrincipalHostname, borrowed from rcmd.c in Kerberos code */
#include <mit-copyright.h>
#include <stdio.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <ctype.h>
#include <strings.h>
char *
PrincipalHostname(alias)
     char *alias;
{
     struct hostent *h;
     char *phost = alias;
     if ((h=gethostbyname(alias)) != (struct hostent *)NULL) {
	  char *p = index(h->h_name, '.');
	  if (p)
	       *p = NULL;
	  p = phost = h->h_name;
	  do {
	       if (isupper(*p))
		    *p = tolower(*p);
	  } while (*p++);
     }
     return(phost);
}
