Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

rpc_host.cc

Go to the documentation of this file.
00001 
00002 #include "rcs_defs.hh"          /* EXTERN_C_STD_HEADERS  */
00003 
00004 #ifdef EXTERN_C_STD_HEADERS
00005 extern "C"
00006 {
00007 #endif
00008 #include <string.h>
00009 #include <stdlib.h>
00010 
00011 #include <rpc/rpc.h>            /* CLIENT */
00012 #ifdef __MSDOS__
00013 #include <rpc/p_prot.h>
00014 #include <rpc/p_clnt.h>
00015 #include <rpc/clnt.h>
00016 #include <netinet/in.h>         /* struct sockaddr_in */
00017 #else
00018 #include <rpc/pmap_prot.h>
00019 
00020 #ifndef sunos4
00021 #include <rpc/pmap_clnt.h>
00022 #else
00023   extern bool_t pmap_set ();
00024   extern bool_t pmap_unset ();
00025   extern struct pmaplist *pmap_getmaps (struct sockaddr_in *);
00026   enum clnt_stat pmap_rmtcall ();
00027   enum clnt_stat clnt_broadcast ();
00028   extern u_short pmap_getport ();
00029 
00030 #endif
00031 #endif
00032 
00033 #include <sys/types.h>          /* u_short (needed by socket.h) */
00034   /* u_char (needed by netinet/in.h) */
00035 #ifdef VXWORKS
00036 #include <hostLib.h>            /* getHostByName() */
00037 #include <rpcLib.h>             /* rpcTaskInit() */
00038 #else
00039 #include <netdb.h>              /* gethostbyname(), struct hostent */
00040 #endif
00041 #include <sys/socket.h>         /* AF_INET,sockaddr_in  */
00042 
00043 #ifdef EXTERN_C_STD_HEADERS
00044 }
00045 #endif
00046 
00047 #include "rpc_host.hh"
00048 #include "rcs_prnt.hh"          /* rcs_print_error() */
00049 
00050 RPC_HOST::RPC_HOST (char *host_name)
00051 {
00052   name = NULL;
00053   socket_address = NULL;
00054 #ifndef VXWORKS
00055   host_entry = NULL;
00056 #endif
00057   name = (char *) malloc (strlen (host_name) + 1);
00058   if (NULL != name)
00059     {
00060       strcpy (name, host_name);
00061     }
00062   else
00063     {
00064       rcs_print_error ("RPC_HOST: Couldn't malloc space for name.\n");
00065       return;
00066     }
00067 
00068 #ifndef VXWORKS
00069   host_entry = gethostbyname (name);
00070   if (NULL == host_entry)
00071     {
00072       rcs_print_error ("RPC_HOST: Error from gethostbyname. \n");
00073       return;
00074     }
00075   socket_address = new sockaddr_in;
00076   if (NULL != socket_address)
00077     {
00078 #ifdef __MSDOS__
00079       socket_address->sin_addr.s_addr =
00080         *((u_long *) host_entry->h_addr_list[0]);
00081 #else
00082       socket_address->sin_addr.s_addr = *((int *) host_entry->h_addr_list[0]);
00083 #endif
00084       socket_address->sin_family = host_entry->h_addrtype;
00085     }
00086 #else
00087   rpcTaskInit ();
00088   socket_address = new sockaddr_in;
00089   if (NULL != socket_address)
00090     {
00091       socket_address->sin_addr.s_addr = hostGetByName (name);
00092       if (socket_address->sin_addr.s_addr == ERROR)
00093         {
00094           rcs_print_error ("RPC_HOST: Couldn't get host address for (%s).\n",
00095                            name);
00096           delete socket_address;
00097           socket_address = NULL;
00098           return;
00099         }
00100       socket_address->sin_family = AF_INET;
00101     }
00102 #endif
00103 }
00104 
00105 
00106 RPC_HOST::~RPC_HOST ()
00107 {
00108   if (NULL != name)
00109     {
00110       free (name);
00111       name = NULL;
00112     }
00113   if (NULL != socket_address)
00114     {
00115       delete socket_address;
00116       socket_address = NULL;
00117     }
00118 }
00119 
00120 int
00121 RPC_HOST::check_if_prog_registered (unsigned long prog)
00122 {
00123   if (NULL == socket_address)
00124     {
00125       return -1;
00126     }
00127 #ifdef MSDOS
00128   pmap_entry = (pmaplist RCS_FAR *) pmap_getmaps (
00129                                                   ((sockaddr_in far *)
00130                                                    socket_address));
00131 #else
00132   pmap_entry = (pmaplist RCS_FAR *) pmap_getmaps (socket_address);
00133 #endif
00134   if (NULL == pmap_entry)
00135     {
00136       return (-1);
00137     }
00138   int retval = 0;
00139   while (NULL != pmap_entry)
00140     {
00141       pmaplist *next_entry;
00142       if (pmap_entry->pml_map.pm_prog == prog &&
00143           pmap_entry->pml_map.pm_prot == IPPROTO_TCP)
00144         {
00145           retval = 1;
00146         }
00147       next_entry = pmap_entry->pml_next;
00148       delete pmap_entry;
00149       pmap_entry = next_entry;
00150     }
00151   return retval;
00152 }

Generated on Sun Dec 2 15:56:52 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001