ypclnt(3N) ypclnt(3N)
NAME
ypclnt, yp_get_default_domain, yp_bind, yp_unbind, yp_match,
yp_first, yp_next, yp_all, yp_order, yp_master, yperr_string,
ypprot_err - YP client interface
SYNOPSIS
#include <rpcsvc/ypclnt.h>
#include <rpcsvc/ypprot.h>
DESCRIPTION
This package of functions provides an interface to the YP network
lookup service. The package can be loaded from the standard library,
/usr/lib/libnsl.{so,a}. Refer to ypfiles(4) and ypserv(1M) for an
overview of the YP name services, including the definitions of map
and domain, and a description of the various servers, databases, and
commands that comprise the YP name service.
All input parameters names begin with in. Output parameters begin
with out. Output parameters of type char ** should be addresses of
uninitialized character pointers. Memory is allocated by the YP
client package using malloc(3), and may be freed if the user code has
no continuing need for it. For each outkey and outval, two extra
bytes of memory are allocated at the end that contain NEWLINE and
NULL, respectively, but these two bytes are not reflected in
outkeylen or outvallen. indomain and inmap strings must be non-NULL
and NULL-terminated. String parameters which are accompanied by a
count parameter may not be NULL, but may point to NULL strings, with
the count parameter indicating this. Counted strings need not be
NULL-terminated.
All functions in this package of type int return 0 if they succeed,
and a failure code (YPERRxxxx) otherwise. Failure codes are
described under DIAGNOSTICS below.
Routines
int
ypbind (domain)
char *domain;
To use the YP name services, the client process must be bound
to a YP server that serves the appropriate domain using
ypbind(). Binding need not be done explicitly by user code;
this is done automatically whenever a YP lookup function is
called. ypbind() can be called directly for processes that
make use of a backup strategy (for example, a local file) in
cases when YP services are not available.
void
ypunbind (domain)
char *domain;
7/91 Page 1
ypclnt(3N) ypclnt(3N)
Each binding allocates (uses up) one client process socket
descriptor; each bound domain costs one socket descriptor.
However, multiple requests to the same domain use that same
descriptor. ypunbind() is available at the client interface
for processes that explicitly manage their socket descriptors
while accessing multiple domains. The call to ypunbind() make
the domain unbound, and free all per-process and per-node
resources used to bind it.
If an RPC failure results upon use of a binding, that domain
will be unbound automatically. At that point, the ypclnt()
layer will retry forever or until the operation succeeds,
provided that ypbind is running, and either
+ the client process cannot bind a server for the proper
domain, or
⊕ RPC requests to the server fail.
If an error is not RPC-related, or if ypbind is not running, or
if a bound ypserv process returns any answer (success or
failure), the ypclnt layer will return control to the user
code, either with an error code, or a success code and any
results.
int
ypgetdefaultdomain (domain)
char **domain;
The YP lookup calls require a map name and a domain name, at
minimum. It is assumed that the client process knows the name
of the map of interest. Client processes should fetch the
node's default domain by calling ypgetdefaultdomain(), and
use the returned domain as the domain parameter to successive
YP name service calls.
int
ypmatch(domain, inmap, inkey, inkeylen, outval, outvallen)
char *domain;
char *map;
char *key;
int keylen;
char **val;
int *vallen;
ypmatch() returns the value associated with a passed key.
This key must be exact; no pattern matching is available.
ypfirst(domain, map, key, keylen, val, vallen)
char *domain;
char *map;
Page 2 7/91
ypclnt(3N) ypclnt(3N)
char **key;
int *keylen;
char **val;
int *vallen;
ypfirst() returns the first key-value pair from the named map
in the named domain.
ypnext(domain, map, inkey, inkeylen, outkey, outkeylen, val, vallen)
char *domain;
char *map;
char *inkey;
int inkeylen;
char **outkey;
int *outkeylen;
char **val;
int *vallen;
ypnext() returns the next key-value pair in a named map. The
inkey parameter should be the outkey returned from an initial
call to ypfirst() (to get the second key-value pair) or the
one returned from the nth call to ypnext() (to get the nth +
second key-value pair).
The concept of first (and, for that matter, of next) is
particular to the structure of the YP map being processing;
there is no relation in retrieval order to either the lexical
order within any original (non-YP name service) data base, or
to any obvious numerical sorting order on the keys, values, or
key-value pairs. The only ordering guarantee made is that if
the ypfirst() function is called on a particular map, and then
the ypnext() function is repeatedly called on the same map at
the same server until the call fails with a reason of
YPERRNOMORE, every entry in the data base will be seen exactly
once. Further, if the same sequence of operations is performed
on the same map at the same server, the entries will be seen in
the same order.
Under conditions of heavy server load or server failure, it is
possible for the domain to become unbound, then bound once
again (perhaps to a different server) while a client is
running. This can cause a break in one of the enumeration
rules; specific entries may be seen twice by the client, or not
at all. This approach protects the client from error messages
that would otherwise be returned in the midst of the
enumeration. The next paragraph describes a better solution to
enumerating all entries in a map.
int
ypall(domain, map, callback)
char *domain;
7/91 Page 3
ypclnt(3N) ypclnt(3N)
char *map;
struct ypallcallback *callback;
ypall() provides a way to transfer an entire map from server
to client in a single request using TCP (rather than UDP as
with other functions in this package). The entire transaction
take place as a single RPC request and response. ypall() can
be used just like any other YP name service procedure, identify
the map in the normal manner, and supply the name of a function
which will be called to process each key-value pair within the
map. The call to ypall() returns only when the transaction is
completed (successfully or unsuccessfully), or the foreach
function decides that it does not want to see any more key-
value pairs.
The third parameter to ypall() is
struct ypallcallback *callback {
int (*foreach)();
char *data;
};
The function foreach is called
foreach(instatus, inkey, inkeylen, inval, invallen, indata)
int instatus;
char *inkey;
int inkeylen;
char *inval;
int invallen;
char *indata;
The instatus parameter will hold one of the return status
values defined in <rpcsvc/ypprot.h - either YPTRUE or an
error code. (See ypproterr(), below, for a function which
converts a YP name service protocol error code to a ypclnt
layer error code.)
The key and value parameters are somewhat different than
defined in the synopsis section above. First, the memory
pointed to by the inkey and inval parameters is private to the
ypall() function, and is overwritten with the arrival of each
new key-value pair. It is the responsibility of the foreach
function to do something useful with the contents of that
memory, but it does not own the memory itself. Key and value
objects presented to the foreach function look exactly as they
do in the server's map - if they were not NEWLINE-terminated or
NULL-terminated in the map, they will not be here either.
The indata parameter is the contents of the incallback->data
element passed to ypall(). The data element of the callback
structure may be used to share state information between the
foreach function and the mainline code. Its use is optional,
Page 4 7/91
ypclnt(3N) ypclnt(3N)
and no part of the YP client package inspects its contents -
cast it to something useful, or ignore it.
The foreach function is a Boolean. It should return zero to
indicate that it wants to be called again for further received
key-value pairs, or non-zero to stop the flow of key-value
pairs. If foreach returns a non-zero value, it is not called
again; the functional value of ypall() is then 0.
int
yporder(domain, map, order)
char *domain;
char *map;
unsigned long *order;
yporder() returns the order number for a map.
int
ypmaster(domain, map, master)
char *domain;
char *map;
char **master;
ypmaster() returns the machine name of the master YP server
for a map.
char
*yperrstring(code)
int code;
yperrstring() returns a pointer to an error message string
that is NULL-terminated but contains no period or NEWLINE.
int
ypproterr (ypprotocolerror)
unsigned int ypprotocolerror;
ypproterr() takes a YP name service protocol error code as
input, and returns a ypclnt layer error code, which may be used
in turn as an input to yperrstring().
FILES
/usr/lib/libnsl.a
SEE ALSO
ypserv(1M), malloc(3), ypupdate(3N), ypfiles(4)
DIAGNOSTICS
All integer functions return 0 if the requested operation is
successful, or one of the following errors if the operation fails.
7/91 Page 5
ypclnt(3N) ypclnt(3N)
#define YPERRBADARGS
1 /* args to function are bad */
#define YPERRRPC
2 /* RPC failure - domain has been unbound */
#define YPERRDOMAIN
3 /* can't bind to server on this domain */
#define YPERRMAP
4 /* no such map in server's domain */
#define YPERRKEY
5 /* no such key in map */
#define YPERRYPERR
6 /* internal yp server or client error */
#define YPERRRESRC
7 /* resource allocation failure */
#define YPERRNOMORE
8 /* no more records in map database */
#define YPERRPMAP
9 /* can't communicate with rpcbinder */
#define YPERRYPBIND
10 /* can't communicate with ypbind */
#define YPERRYPSERV
11 /* can't communicate with ypserv */
#define YPERRNODOM
12 /* local domain name not set */
#define YPERRBADDB
13 /* yp database is bad */
#define YPERRVERS
14 /* yp version mismatch */
#define YPERRACCESS
15 /* access violation */
#define YPERRBUSY
16 /* database busy */
Page 6 7/91