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

vipnsgethostbyaddr.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 <string.h>
00014 
00015 #include "vipl_priv.h"
00016 
00017 
00060 VIP_ENTRY_POINT VIP_RETURN
00061 VipNSGetHostByAddr (VIP_NIC_HANDLE NicHandle,
00062                     VIP_NET_ADDRESS * Address,
00063                     VIP_CHAR * Name, VIP_ULONG * NameLen)
00064 {
00065   VIP_UCHAR *gm_name_ptr;
00066   VIP_ULONG gm_name_len;
00067   VIP_UINT32 gm_node_id;
00068   VIP_NIC *vip_nic_ptr;
00069   gm_status_t gm_status;
00070   VIP_DEBUG_LABEL (("VipNSGetHostByName"));
00071 
00072   if (Name == NULL)
00073     {
00074       VIP_DEBUG (("Name is null"));
00075       return VIP_INVALID_PARAMETER;
00076     }
00077 
00078   if (NameLen == NULL)
00079     {
00080       VIP_DEBUG (("NameLen is null"));
00081       return VIP_INVALID_PARAMETER;
00082     }
00083 
00084   if (Address == NULL)
00085     {
00086       VIP_DEBUG (("Address is null"));
00087       return VIP_INVALID_PARAMETER;
00088     }
00089 
00090   /* check net address (host part) */
00091   if (Address->HostAddressLen < VI_GM_MAC_ADDRESS_LEN)
00092     {
00093       VIP_DEBUG (("HostAddressLen field in Address is invalid (should be %d)",
00094                   VI_GM_MAC_ADDRESS_LEN));
00095       return VIP_INVALID_PARAMETER;
00096     }
00097 
00098   /* check nic handle */
00099   vip_nic_ptr = (VIP_NIC *) NicHandle;
00100   if (VIP_INVALID_NIC_HANDLE (vip_nic_ptr))
00101     {
00102       VIP_DEBUG (("Invalid NIC handle"));
00103       return VIP_INVALID_PARAMETER;
00104     }
00105   VIP_MUTEX_LOCK (&(vip_nic_ptr->vip_gm_ptr->lock));
00106   VIP_PROGRESSION (vip_nic_ptr->vip_gm_ptr);
00107   VIP_MUTEX_LOCK (&(vip_nic_ptr->lock));
00108 
00109   /* check if the name service is initialized */
00110   if (vip_nic_ptr->ns_initialized == VIP_FALSE)
00111     {
00112       VIP_DEBUG (("Name service not previously initialized"));
00113       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock));
00114       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->vip_gm_ptr->lock));
00115       return VIP_ERROR_NAMESERVICE;
00116     }
00117 
00118   /* check the MAC address */
00119   VIP_ENTER_IOCTL (vip_nic_ptr->vip_gm_ptr);
00120   gm_status = gm_unique_id_to_node_id (vip_nic_ptr->vip_gm_ptr->gm_port,
00121                                        Address->HostAddress, &gm_node_id);
00122   VIP_EXIT_IOCTL (vip_nic_ptr->vip_gm_ptr);
00123 
00124   if (gm_status != GM_SUCCESS)
00125     {
00126       VIP_DEBUG_GM (("Unable to get the GM node id of the Myrinet board "
00127                      "with MAC address %x:%x:%x:%x:%x:%c",
00128                      Address->HostAddress[0], Address->HostAddress[1],
00129                      Address->HostAddress[2], Address->HostAddress[3],
00130                      Address->HostAddress[4], Address->HostAddress[5]));
00131       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock));
00132       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->vip_gm_ptr->lock));
00133       return VIP_ERROR_NAMESERVICE;
00134     }
00135 
00136   if (gm_node_id == GM_NO_SUCH_NODE_ID)
00137     {
00138       VIP_DEBUG (("GM does not know this MAC address"));
00139       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock));
00140       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->vip_gm_ptr->lock));
00141       return VIP_ERROR_NAMESERVICE;
00142     }
00143 
00144   VIP_MUTEX_LOCK (&vip_gm_host_name_lock);
00145   VIP_ENTER_IOCTL (vip_nic_ptr->vip_gm_ptr);
00146   gm_name_ptr = gm_node_id_to_host_name (vip_nic_ptr->vip_gm_ptr->gm_port,
00147                                          gm_node_id);
00148   VIP_EXIT_IOCTL (vip_nic_ptr->vip_gm_ptr);
00149   gm_name_len = strlen (gm_name_ptr);
00150 
00151   /* check the NameLen */
00152   if (*NameLen <= gm_name_len)
00153     {
00154       *NameLen = gm_name_len + 1;
00155       VIP_MUTEX_UNLOCK (&vip_gm_host_name_lock);
00156       VIP_DEBUG (("NameLen is too small (requires %d)", gm_name_len + 1));
00157       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock));
00158       VIP_MUTEX_UNLOCK (&(vip_nic_ptr->vip_gm_ptr->lock));
00159       return VIP_INVALID_PARAMETER;
00160     }
00161 
00162   strcpy (Name, gm_name_ptr);
00163   *NameLen = gm_name_len;
00164 
00165   VIP_MUTEX_UNLOCK (&vip_gm_host_name_lock);
00166   VIP_DEBUG (("Success"));
00167   VIP_MUTEX_UNLOCK (&(vip_nic_ptr->lock));
00168   VIP_MUTEX_UNLOCK (&(vip_nic_ptr->vip_gm_ptr->lock));
00169   return VIP_SUCCESS;
00170 }
VI-GM-1.3 by Myricom © 1997-2006. Documentation generated on 20 May 2006 by doxygen 1.4.4.