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

static char sccsid_Bind_addr[] = "@(#)STDbind_addr.c	1.40 11/13/92 10:50:37 LLNL ";

/*
	Embedded Language for Remote Operations Services
	ELROS

	AUTHOR:		Robyne M. Sumpter
			Network Systems Division

	DATE WRITTEN:	10/11/90

	ROUTINE:	Bind_addr

PURPOSE:
	Establish an association between two entities.  The currently 
 	supported platforms are all in this source file and are #ifdef
	to include the code.
	


IN:

OUT:


CALLED ROUTINES:
	

	
MODIFICATION HISTORY:


*/

#include <elros/instance.h>
#include <elros/binds.h>
#include <elros/specifics.h>



#ifdef __STDC__
#include <stdarg.h>

int __ROr_STDBind_addr(__RO_Instance_Record *inst, 
                       __RO_Presentation_rules rules,
                       __RO_Address *addr_struct,
                       int timeout,
                       ...)

#else /* __STDC__ */
#include <varargs.h>

int __ROr_STDBind_addr( inst, rules, addr_struct, timeout, va_alist)

   __RO_Instance_Record	*inst;
   __RO_Presentation_rules rules;
   __RO_Address		*addr_struct;
   int			timeout;
   va_dcl

#endif /* __STDC__ */

{
#ifdef __RO_PLATFORM_ISODE
   va_list ap;
   User_data *udata;

#ifdef __STDC__
   va_start(ap,timeout);
#else
   va_start(ap);
#endif

   udata = va_arg(ap, User_data *);
   va_end(ap);
#endif /* __RO_PLATFORM_ISODE */

   switch( addr_struct->platform )
   {
      case Isode:
#ifdef __RO_PLATFORM_ISODE
   	 if (udata && inst->decl_class != __ROm_class_GIVEACCEPT)
		__RO_RETURN_RUNTIME( inst, __ROx_BIND_BADDECLCLASS);
         return(  __ROr_ISODEBind_addr( inst, rules, addr_struct, timeout, udata ) );
#else
         __RO_RETURN_RUNTIME( inst, __ROx_BIND_BADPLATFORM );
#endif

      case Puresockets:
#ifdef __RO_PLATFORM_PURESOCKETS
         return(  __ROr_SOCKBind_addr( inst, rules, addr_struct, timeout ) );
#else
         __RO_RETURN_RUNTIME( inst, __ROx_BIND_BADPLATFORM );
#endif

      default:
         __RO_RETURN_RUNTIME( inst, __ROx_BIND_BADPLATFORM );
   }
}



#include <sys/types.h>
#include <netdb.h>
#ifndef IN_H
#define IN_H
#include <netinet/in.h>
#endif

u_long __ROv_IPAddress;
int __ROv_IPAddress_initialized = 0;

int __ROr_initialize_IPAddress()

{
   char here[64];
   struct hostent *ip;

   (void)gethostname(here, sizeof(here));
   ip = gethostbyname( here );
   __ROv_IPAddress = *((u_long *)ip->h_addr);
   __ROv_IPAddress_initialized = 1;

#ifdef CRAY
   __ROv_IPAddress >>= 32;
#endif

   return(SUCCESS);
}

int __ROr_set_IPAddress(a)

   u_long *a;

{
   if (!__ROv_IPAddress_initialized)
      __ROr_initialize_IPAddress();

   *a = __ROv_IPAddress;

   return(SUCCESS);
}


int __ROr_verify_IPAddress(a)

   u_long a;

{
   if (!__ROv_IPAddress_initialized)
      __ROr_initialize_IPAddress();

   if (a == __ROv_IPAddress)
      return 1;
   else
      return 0;
}


