#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <paths.h>
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include <rpcsvc/yp.h>
#include <rpcsvc/ypclnt.h>
#include "ypinternal.h"
char _yp_domain[HOST_NAME_MAX+1];
int _yplib_timeout = 10;
extern CLIENT *
clntudp_bufcreate_simple(struct sockaddr_in *raddr, u_long program, u_long version,
struct timeval wait, int *sockp, u_int sendsz, u_int recvsz);
int
_yp_dobind(const char *dom, struct dom_binding **ypdb)
{
struct dom_binding *ypbinding;
struct timeval tv;
int connected = 1;
int s;
if (dom == NULL || strlen(dom) == 0)
return YPERR_BADARGS;
ypbinding = calloc(1, sizeof (*ypbinding));
if (ypbinding == NULL)
return YPERR_RESRC;
again:
s = ypconnect(SOCK_DGRAM);
if (s == -1) {
free(ypbinding);
return YPERR_YPBIND;
}
ypbinding->dom_socket = s;
ypbinding->dom_server_addr.sin_port = -1;
tv.tv_sec = _yplib_timeout / 2;
tv.tv_usec = 0;
ypbinding->dom_client = clntudp_bufcreate_simple(&ypbinding->dom_server_addr,
YPPROG, YPVERS, tv, &ypbinding->dom_socket, UDPMSGSIZE, UDPMSGSIZE);
if (ypbinding->dom_client == NULL) {
close(ypbinding->dom_socket);
ypbinding->dom_socket = -1;
clnt_pcreateerror("clntudp_create");
goto again;
}
clnt_control(ypbinding->dom_client, CLSET_CONNECTED, &connected);
*ypdb = ypbinding;
return 0;
}
void
_yp_unbind(struct dom_binding *ypb)
{
close(ypb->dom_socket);
if (ypb->dom_client)
clnt_destroy(ypb->dom_client);
free(ypb);
}
int
yp_bind(const char *dom)
{
struct dom_binding *ysd;
int r;
r = _yp_dobind(dom, &ysd);
if (r == 0)
_yp_unbind(ysd);
return r;
}
DEF_WEAK(yp_bind);
void
yp_unbind(const char *dom)
{
}