if (ysd == NULL) return YPERR_RESRC;
__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;  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);    }#if USE_BINDINGDIR  if (ysd->dom_client == NULL)    {      /* Try binding dir at first if we have no binding */      char path[sizeof (BINDINGDIR) + strlen (domain) + 10];      struct iovec vec[2];      unsigned short port;      int fd;      sprintf (path, "%s/%s.%d", 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) == sizeof (port) + sizeof (ypbr))	    {	      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));	      strncpy (ysd->dom_domain, domain, YPMAXDOMAIN);	      ysd->dom_domain[YPMAXDOMAIN] = '\0';	      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)		/* If the program exits, close the socket */		if (fcntl (ysd->dom_socket, F_SETFD, 1) == -1)		  perror ("fcntl: F_SETFD");	    }	  close (fd);	}    }#endif /* USE_BINDINGDIR */  if (ysd->dom_client == NULL)    {      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);	  if (is_new)	    free (ysd);	  return YPERR_YPBIND;	}      clnt_destroy (client);      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));      strncpy (ysd->dom_domain, domain, YPMAXDOMAIN);      ysd->dom_domain[YPMAXDOMAIN] = '\0';      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)	/* If the program exits, close the socket */	if (fcntl (ysd->dom_socket, F_SETFD, 1) == -1)	  perror ("fcntl: F_SETFD");    }  if (ysd->dom_client == NULL)    {      if (is_new)	free (ysd);      return YPERR_YPSERV;    }  if (is_new && ypdb != NULL)    {      ysd->dom_pnext = *ypdb;      *ypdb = ysd;    }  return YPERR_SUCCESS;}