/*****************************************************************/
/**                                                             **/
/**             (C) Copyright 1992 the Regents of the           **/
/**        University of California.  All Rights Reserved.      **/
/**                                                             **/
/**        This work was produced under the sponsorship of      **/
/**         the U.S. Department of Energy.  The Government      **/
/**                retains certain rights therein.              **/
/**                                                             **/
/**                         Written by                          **/
/**         Distributed Programming Environments Project        **/
/**           Computer Software and Networking Division,        **/
/**                   Livermore Computer Center,                **/
/**            Lawrence Livermore National Laboratory           **/
/**                                                             **/
/*****************************************************************/
 
#include "Tpasswd.i" 			 /* import the interface */

UserName sumpter = "sumpter"; 

 
main(argc,argv) 
   int argc; 
   char *argv[]; 
{ 
   int status;
   int timeout = 300; 
  
   Bind_address addr; 
   Control (lookup) inst; 		 /* declare the instance */
   Passwd ret_val; 

   /* set up the server address */
   isode_addr_from_hostname(&addr, argv[1], Initiator);

   /*** Begin client/server activity ***/ 
  
   printf("Binding..."); fflush(stdout);

   /* bind to the lookup service */
   Bind_addr(inst,Asn_1_ber,&addr,timeout ); 
 
   /* perform a lookup operation */

   Give inst 
   { 
      I_lookupUser(sumpter); 
   } 
   Exceptions 				 /* exceptions */
    {
      On Com_error(status)		 /* a communications error */
	 {
	    printf("communications error = %d", status);
	    exit(1);
	 }
    }
 
   /* get the result of the operation */

   Accept inst
   { 
      On R_lookupUser(ret_val) 
          Roprinti("Passwd", &ret_val, lookup);  
					 /* print the value returned */
   } 
 
   Unbind(inst); 			 /* disconnect from the server */

   printf("test completed\n");
   return(0); 
} 
 

#include <netdb.h> 

isode_addr_from_hostname(addr,hostname,role)
   Bind_address *addr; 
   char *hostname;
   Bind_role role;
{
   char addrbuffer[64]; 
   unsigned char *ipvalue; 
   struct hostent *hostip;

   hostip = gethostbyname(hostname);

   if (hostip == NULL) {
     printf("Invalid host server name: %s\n",hostname);
     exit (1);
   }

   /* Get server address */

   ipvalue = (unsigned char *)(hostip->h_addr); 

   sprintf(addrbuffer,"#521/Internet=%ld.%ld.%ld.%ld+18000", 
           ipvalue[0], ipvalue[1], ipvalue[2], ipvalue[3]); 
 
   Init_isode_addr(addr,role,addrbuffer); 
 
   return(0);
}
