Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

vipnsgethostbyname.c

Go to the documentation of this file.
00001 /********************************************************
00002  * Myricom VI-GM  networking software and documentation *
00003  * Copyright (c) 2001 by Myricom, Inc.                  *
00004  * All rights reserved.                                 *
00005  * See the file `COPYING' for copyright notice.         *
00006  ********************************************************/
00007 
00013 #include <stdlib.h>
00014 #include <string.h>
00015 
00016 #include "vipl_priv.h"
00017 
00018 
00066 VIP_ENTRY_POINT VIP_RETURN
00067 VipNSGetHostByName (VIP_NIC_HANDLE NicHandle,
00068                     VIP_CHAR * Name,
00069                     VIP_NET_ADDRESS * Address, VIP_ULONG NameIndex)
00070 {
00071   VIP_UCHAR *gm_buffer;
00072   VIP_UINT32 gm_node_id;
00073   VIP_NIC *vip_nic_ptr;
00074   gm_status_t gm_status;
00075   VIP_DEBUG_LABEL (("VipNSGetHostByName"));
00076 
00077   if (Name == NULL)
00078     {
00079       VIP_DEBUG (("Name is null"));
00080       return VIP_INVALID_PARAMETER;
00081     }
00082 
00083   if (strlen (Name) == 0)
00084     {
00085       VIP_DEBUG (("Name is empty"));
00086       return VIP_ERROR_NAMESERVICE;
00087     }
00088 
00089   if (Address == NULL)
00090     {
00091       VIP_DEBUG (("Address is null"));
00092       return VIP_INVALID_PARAMETER;
00093     }
00094 
00095   /* check net address (host part) */
00096   if (Address->HostAddressLen < VI_GM_MAC_ADDRESS_LEN)
00097     {
00098       VIP_DEBUG (("Host Address Length is too small (should be %d)",
00099                   VI_GM_MAC_ADDRESS_LEN));
00100       return VIP_INVALID_PARAMETER;
00101     }
00102 
00103   /* check nic handle */
00104   vip_nic_ptr = (VIP_NIC *) NicHandle;
00105   if (VIP_INVALID_NIC_HANDLE (vip_nic_ptr))
00106     {
00107       VIP_DEBUG (("Invalid NIC handle"));
00108       return VIP_INVALID_PARAMETER;
00109     }
00110   VIP_MUTEX_LOCK (&(vip_nic_ptr->vip_gm_ptr->lock));
00111   VIP_PROGRESSION (vip_nic_ptr->vip_gm_ptr);
00112   VIP_MUTEX_LOCK (&(vip_nic_ptr->lock));
00113 
00114   /* check if the name service is initialized */
00115   if (vip_nic_ptr->ns_initialized == VIP_FALSE)
00116     {
00117       VIP_DEBUG (("Name service not previously initialized"));
00118       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock));
00119       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->vip_gm_ptr->lock));
00120       return VIP_ERROR_NAMESERVICE;
00121     }
00122 
00123   /* allocate temp GM hostname */
00124   gm_buffer = malloc (strlen (Name) + 32);
00125 
00126   if (gm_buffer == NULL)
00127     {
00128       VIP_DEBUG (("Not enough memory to allocate internal buffer"));
00129       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock));
00130       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->vip_gm_ptr->lock));
00131       return VIP_ERROR_RESOURCE;
00132     }
00133 
00134   /* generate the GM hostname */
00135   if (NameIndex > 0)
00136     {
00137       sprintf (gm_buffer, "%s:%ld", Name, NameIndex);
00138     }
00139   else
00140     {
00141       strcpy (gm_buffer, Name);
00142     }
00143 
00144   /* check the GM hostname */
00145   VIP_ENTER_IOCTL (vip_nic_ptr->vip_gm_ptr);
00146   gm_node_id = gm_host_name_to_node_id (vip_nic_ptr->vip_gm_ptr->gm_port,
00147                                         gm_buffer);
00148   VIP_EXIT_IOCTL (vip_nic_ptr->vip_gm_ptr);
00149 
00150   if (gm_node_id == GM_NO_SUCH_NODE_ID)
00151     {
00152       free (gm_buffer);
00153       VIP_DEBUG (("GM does not know %s", gm_buffer));
00154       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock));
00155       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->vip_gm_ptr->lock));
00156       return VIP_ERROR_NAMESERVICE;
00157     }
00158 
00159   /* update the NET address */
00160   VIP_ENTER_IOCTL (vip_nic_ptr->vip_gm_ptr);
00161   gm_status = gm_node_id_to_unique_id (vip_nic_ptr->vip_gm_ptr->gm_port,
00162                                        gm_node_id, Address->HostAddress);
00163   VIP_EXIT_IOCTL (vip_nic_ptr->vip_gm_ptr);
00164 
00165   if (gm_status != GM_SUCCESS)
00166     {
00167       free (gm_buffer);
00168       VIP_DEBUG_GM (("Unable to get the MAC address of the GM node id %d",
00169                      gm_node_id));
00170       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock));
00171       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->vip_gm_ptr->lock));
00172       return VIP_ERROR_NAMESERVICE;
00173     }
00174 
00175   Address->HostAddressLen = VI_GM_MAC_ADDRESS_LEN;
00176   free (gm_buffer);
00177 
00178   VIP_DEBUG (("Success"));
00179   VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock));
00180   VIP_MUTEX_UNLOCK (&(vip_nic_ptr->vip_gm_ptr->lock));
00181   return VIP_SUCCESS;
00182 }
VI-GM-1.3 by Myricom © 1997-2006. Documentation generated on 20 May 2006 by doxygen 1.4.4.