YPCLNT(3N) UNIX Programmer's Manual 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 - yellow pages client interface SYNOPSIS #include <rpcsvc/ypclnt.h> 9 yp_bind(indomain); char *indomain; 9 void yp_unbind(indomain) char *indomain; 9 yp_get_default_domain(outdomain); char **outdomain; 9 yp_match(indomain, inmap, inkey, inkeylen, outval, outvallen) char *indomain; char *inmap; char *inkey; int inkeylen; char **outval; int *outvallen; 9 yp_first(indomain, inmap, outkey, outkeylen, outval, outvallen) char *indomain; char *inmap; char **outkey; int *outkeylen; char **outval; int *outvallen; 9 yp_next(indomain, inmap, inkey, inkeylen, outkey, outkeylen, outval, outvallen); char *indomain; char *inmap; char *inkey; int inkeylen; char **outkey; int *outkeylen; char **outval; int *outvallen; 9 yp_all(indomain, inmap, incallback); char *indomain; char *inmap; struct ypall_callback incallback; 9 yp_order(indomain, inmap, outorder); char *indomain; char *inmap; int *outorder; 9 yp_master(indomain, inmap, outname); char *indomain; char *inmap; char **outname; Printed 12/27/86 14 September 1985 1 9 YPCLNT(3N) UNIX Programmer's Manual YPCLNT(3N) char *yperr_string(incode) int incode; 9 ypprot_err(incode) unsigned int incode; DESCRIPTION This package of functions provides an interface to the yel- low pages (YP) network lookup service. The package can be loaded from the standard library, /_l_i_b/_l_i_b_c._a. Refer to ypfiles(5) and ypserv(8) for an overview of the yellow pages, including the definitions of _m_a_p and _d_o_m_a_i_n , and a description of the various servers, databases, and commands that comprise the YP. All input parameters names begin with in. Output parameters begin with out. Output parameters of type _c_h_a_r ** should be addresses of uninitialized character pointers. Memory is allocated by the YP client package using _m_a_l_l_o_c(3), and may be freed if the user code has no continuing need for it. For each _o_u_t_k_e_y and _o_u_t_v_a_l, two extra bytes of memory are allo- cated at the end that contain NEWLINE and NULL, respec- tively, but these two bytes are not reflected in _o_u_t_k_e_y_l_e_n or _o_u_t_v_a_l_l_e_n . _i_n_d_o_m_a_i_n and _i_n_m_a_p strings must be non-null and null-terminated. String parameters which are accom- panied 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 (YPERR__x_x_x_x) otherwise. Failure codes are described under DIAGNOSTICS below. 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 yp_get_default_domain() , and use the returned _o_u_t_d_o_m_a_i_n as the _i_n_d_o_m_a_i_n parameter to successive YP calls. To use the YP services, the client process must be ``bound'' to a YP server that serves the appropriate domain using _y_p__b_i_n_d. Binding need not be done explicitly by user code; this is done automatically whenever a YP lookup function is called. _y_p__b_i_n_d can be called directly for processes that make use of a backup strategy (e.g., a local file) in cases when YP services are not available. 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. _y_p__u_n_b_i_n_d() is available at the client inter- face for processes that explicitly manage their socket Printed 12/27/86 14 September 1985 2 9 YPCLNT(3N) UNIX Programmer's Manual YPCLNT(3N) descriptors while accessing multiple domains. The call to _y_p__u_n_b_i_n_d() make the domain _u_n_b_o_u_n_d, 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 _y_p_b_i_n_d is running, and either a) the client process can't bind a server for the proper domain, or b) RPC requests to the server fail. If an error is not RPC-related, or if _y_p_b_i_n_d is not running, or if a bound _y_p_s_e_r_v 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. _y_p__m_a_t_c_h returns the value associated with a passed key. This key must be exact; no pattern matching is available. _y_p__f_i_r_s_t returns the first key-value pair from the named map in the named domain. _y_p__n_e_x_t() returns the next key-value pair in a named map. The _i_n_k_e_y parameter should be the _o_u_t_k_e_y returned from an initial call to _y_p__f_i_r_s_t() (to get the second key-value pair) or the one returned from the nth call to _y_p__n_e_x_t() (to get the nth + second key-value pair). The concept of first (and, for that matter, of next) is par- ticular to the structure of the YP map being processing; there is no relation in retrieval order to either the lexi- cal order within any original (non-YP) 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 _y_p__f_i_r_s_t() function is called on a particular map, and then the _y_p__n_e_x_t() function is repeatedly called on the same map at the same server until the call fails with a rea- son of YPERR_NOMORE, every entry in the data base will be seen exactly once. Further, if the same sequence of opera- tions 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 Printed 12/27/86 14 September 1985 3 YPCLNT(3N) UNIX Programmer's Manual YPCLNT(3N) 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. _y_p__a_l_l 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 transac- tion take place as a single RPC request and response. You can use _y_p__a_l_l just like any other YP procedure, identify the map in the normal manner, and supply the name of a func- tion which will be called to process each key-value pair within the map. You return from the call to _y_p__a_l_l only when the transaction is completed (successfully or unsuc- cessfully), or your ``_f_o_r_e_a_c_h'' function decides that it doesn't want to see any more key-value pairs. The third parameter to _y_p__a_l_l is struct ypall_callback *incallback { int (*foreach)(); char *data; }; The function _f_o_r_e_a_c_h is called foreach(instatus, inkey, inkeylen, inval, invallen, indata); int instatus; char *inkey; int inkeylen; char *inval; int invalllen; char *indata; The _i_n_s_t_a_t_u_s parameter will hold one of the return status values defined in <rpcsvc/yp_prot.h> - _e_i_t_h_e_r _Y_P__T_R_U_E or an error code. (See _y_p_p_r_o_t__e_r_r , below, for a function which converts a YP 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 _i_n_k_e_y and _i_n_v_a_l parameters is private to the _y_p__a_l_l function, and is overwritten with the arrival of each new key-value pair. It is the responsibility of the _f_o_r_e_a_c_h 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 _f_o_r_e_a_c_h function look exactly as they do in the server's map - if they were not newline- terminated or null-terminated in the map, they won't be here either. The _i_n_d_a_t_a parameter is the contents of the _i_n_c_a_l_l_b_a_c_k->_d_a_t_a element passed to _y_p__a_l_l . The _d_a_t_a element of the callback Printed 12/27/86 14 September 1985 4 YPCLNT(3N) UNIX Programmer's Manual YPCLNT(3N) structure may be used to share state information between the _f_o_r_e_a_c_h function and the mainline code. Its use is optional, and no part of the YP client package inspects its contents - cast it to something useful, or ignore it as you see fit. The _f_o_r_e_a_c_h 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 _f_o_r_e_a_c_h returns a non-zero value, it is not called again; the functional value of _y_p__a_l_l is then 0. _y_p__o_r_d_e_r returns the order number for a map. _y_p__m_a_s_t_e_r returns the machine name of the master YP server for a map. _y_p_e_r_r__s_t_r_i_n_g returns a pointer to an error message string that is null-terminated but contains no period or newline. _y_p_p_r_o_t__e_r_r takes a YP protocol error code as input, and returns a ypclnt layer error code, which may be used in turn as an input to _y_p_e_r_r__s_t_r_i_n_g . FILES /usr/include/rpcsvc/ypclnt.h /usr/include/rpcsvc/yp_prot.h SEE ALSO ypfiles(5), ypserv(8), DIAGNOSTICS All integer functions return 0 if the requested operation is successful, or one of the following errors if the operation fails. #define YPERR_BADARGS 1 /* args to function are bad */ #define YPERR_RPC 2 /* RPC failure - domain has been unbound */ #define YPERR_DOMAIN 3 /* can't bind to server on this domain */ #define YPERR_MAP 4 /* no such map in server's domain */ #define YPERR_KEY 5 /* no such key in map */ #define YPERR_YPERR 6 /* internal yp server or client error */ #define YPERR_RESRC 7 /* resource allocation failure */ #define YPERR_NOMORE 8 /* no more records in map database */ #define YPERR_PMAP 9 /* can't communicate with portmapper */ #define YPERR_YPBIND 10 /* can't communicate with ypbind */ #define YPERR_YPSERV 11 /* can't communicate with ypserv */ #define YPERR_NODOM 12 /* local domain name not set */ Printed 12/27/86 14 September 1985 5