/*****************************************************************/
/**                                                             **/
/**             (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" 

#include <elros/ipads.h>
 
#include <netdb.h> 
 
extern unsigned long Stksize; 
int anycount = 0; 

char *ip;
struct hostent *hostip;
char addrbuffer[64]; 
unsigned char *ipvalue; 
 
static char * sumpter = "sumpter"; 

 
main(argc,argv) 
   int argc; 
   char *argv[]; 
{ 
   Task MyId; 
   int lookup_task(); 
   int MAXTASKS = 10; /* Max concurrency */ 
   Stksize = 100 * 1024; 
 
   /* Parse command line args */
 
   if (argc < 2) {
      printf("First arg must be server host name\n");
      exit (1);
   }

   ip = argv[1];

   hostip = gethostbyname(ip);

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

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

   sprintf(addrbuffer,"#521/Internet=%ld.%ld.%ld.%ld+18000", 
           ipvalue[0], ipvalue[1], ipvalue[2], ipvalue[3]); 
 
   /* Start tasking */
   while ( 1 ) 
   { 
     while ( anycount < MAXTASKS ) 
     { 
        MyId = Ego(); 
        Newtask( lookup_task, MyId ); 
        anycount++; 
     } 
     SLEEP; 
   } 
 
   return(0); 
}  
 
 
int lookup_task() 
{ 
   Control (lookup) inst; 
   Passwd ret_val; 
  
   int i; 
   int timeout = 300; 
   Bind_address addr; 
   char appconname[20]; 
   char prsntconname[20]; 
 
 
   /* Get server address */

   Init_isode_addr(&addr,Initiator,addrbuffer); 
 
   strcpy( appconname, "1.17.1.5.1"); 
   strcpy( prsntconname, "1.17.1.5.2"); 
   __ROc_lookup_information.acn = appconname;  
   __ROc_lookup_information.pcn = prsntconname;  
  
   /*** Begin client/server activity ***/

   printf("Binding..."); fflush(stdout);
  
   Bind_addr( inst, Asn_1_ber, &addr, timeout ); 
 
   Give inst 
   { 
      I_lookupUser(sumpter); 
   } 
 
   Accept inst 
   { 
      On R_lookupUser(ret_val) 
          printf("Got reply \n");  
   } 
 
   Unbind(inst); 

   printf("Unbound\n");
   printf("task completed\n");
  
   anycount--; 
   Wake((Task)Tvarb); 

   return 0; 
} 
