if (ysd->dom_client) { clnt_destroy (ysd->dom_client); close (ysd->dom_socket); }
__yp_bind (const char *domain, dom_binding **ypdb){  struct sockaddr_in clnt_saddr;  struct ypbind_resp ypbr;  dom_binding *ysd = NULL;  int clnt_sock;  CLIENT *client;  int is_new = 0;  int try;  if ((domain == NULL) || (domain[0] == '\0'))    return YPERR_BADARGS;  if (ypdb != NULL)    {      ysd = *ypdb;      while (ysd != NULL)	{	  if (strcmp (domain, ysd->dom_domain) == 0)	    break;	  ysd = ysd->dom_pnext;	}    }  if (ysd == NULL)    {      is_new = 1;      ysd = (dom_binding *) calloc (1, sizeof *ysd);      ysd->dom_socket = -1;      ysd->dom_vers = -1;    }  try = 0;  do    {      ++try;      if (try > MAXTRIES)        {          if (is_new)            free (ysd);          return YPERR_YPBIND;        }#if USE_BINDINGDIR      if (ysd->dom_vers < 1 && try == 1) /* Try binding dir only first time */	{	  char path[sizeof (BINDINGDIR) - 1 + strlen (domain) + 10];	  struct iovec vec[2];	  u_short port;	  int fd;	  sprintf (path, "%s/%s.%ld", BINDINGDIR, domain, YPBINDVERS);	  fd = open (path, O_RDONLY);	  if (fd >= 0)	    {	      /* We have a binding file and could save a RPC call */	      vec[0].iov_base = &port;	      vec[0].iov_len = sizeof (port);	      vec[1].iov_base = &ypbr;	      vec[1].iov_len = sizeof (ypbr);	      if (readv (fd, vec, 2) == vec[0].iov_len + vec[1].iov_len)		{		  memset (&ysd->dom_server_addr, '\0',			  sizeof ysd->dom_server_addr);		  ysd->dom_server_addr.sin_family = AF_INET;		  memcpy (&ysd->dom_server_addr.sin_port,			  ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port,			  sizeof (ysd->dom_server_addr.sin_port));		  memcpy (&ysd->dom_server_addr.sin_addr.s_addr,			  ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr,			  sizeof (ysd->dom_server_addr.sin_addr.s_addr));		  ysd->dom_vers = YPVERS;		  strncpy (ysd->dom_domain, domain, YPMAXDOMAIN);		  ysd->dom_domain[YPMAXDOMAIN] = '\0';		}	      close (fd);	    }	}#endif /* USE_BINDINGDIR */      if (ysd->dom_vers == -1)	{	  if(ysd->dom_client)	    {	      clnt_destroy(ysd->dom_client);	      ysd->dom_client = NULL;	      ysd->dom_socket = -1;	    }          memset (&clnt_saddr, '\0', sizeof clnt_saddr);          clnt_saddr.sin_family = AF_INET;          clnt_saddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);          clnt_sock = RPC_ANYSOCK;          client = clnttcp_create (&clnt_saddr, YPBINDPROG, YPBINDVERS,                                   &clnt_sock, 0, 0);          if (client == NULL)            {              if (is_new)                free (ysd);              return YPERR_YPBIND;            }          /*          ** Check the port number -- should be < IPPORT_RESERVED.          ** If not, it's possible someone has registered a bogus          ** ypbind with the portmapper and is trying to trick us.          */          if (ntohs (clnt_saddr.sin_port) >= IPPORT_RESERVED)            {              clnt_destroy (client);              if (is_new)                free (ysd);              return YPERR_YPBIND;            }          if (clnt_call (client, YPBINDPROC_DOMAIN,                         (xdrproc_t) xdr_domainname, (caddr_t) &domain,                         (xdrproc_t) xdr_ypbind_resp,                         (caddr_t) &ypbr, RPCTIMEOUT) != RPC_SUCCESS)            {              clnt_destroy (client);	      close (clnt_sock);              if (is_new)                free (ysd);              return YPERR_YPBIND;            }          clnt_destroy (client);	  close (clnt_sock);          if (ypbr.ypbind_status != YPBIND_SUCC_VAL)            {	      fprintf (stderr, _("YPBINDPROC_DOMAIN: %s\n"),		       ypbinderr_string (ypbr.ypbind_resp_u.ypbind_error));	      if (is_new)		free (ysd);	      return YPERR_DOMAIN;	    }          memset (&ysd->dom_server_addr, '\0', sizeof ysd->dom_server_addr);          ysd->dom_server_addr.sin_family = AF_INET;          memcpy (&ysd->dom_server_addr.sin_port,                  ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port,                  sizeof (ysd->dom_server_addr.sin_port));          memcpy (&ysd->dom_server_addr.sin_addr.s_addr,                  ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr,                  sizeof (ysd->dom_server_addr.sin_addr.s_addr));          ysd->dom_vers = YPVERS;          strncpy (ysd->dom_domain, domain, YPMAXDOMAIN);	  ysd->dom_domain[YPMAXDOMAIN] = '\0';        }      if (ysd->dom_client)	{	  clnt_destroy (ysd->dom_client);	  close (ysd->dom_socket);	}      ysd->dom_socket = RPC_ANYSOCK;      ysd->dom_client = clntudp_create (&ysd->dom_server_addr, YPPROG, YPVERS,                                        UDPTIMEOUT, &ysd->dom_socket);      if (ysd->dom_client == NULL)        ysd->dom_vers = -1;    }  while (ysd->dom_client == NULL);  /* If the program exists, close the socket */  if (fcntl (ysd->dom_socket, F_SETFD, 1) == -1)    perror ("fcntl: F_SETFD");  if (is_new && ypdb != NULL)    {      ysd->dom_pnext = *ypdb;      *ypdb = ysd;    }  return YPERR_SUCCESS;}