2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user or with the express written consent of
8 * Sun Microsystems, Inc.
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 * Sun RPC is provided with no support and without any obligation on the
15 * part of Sun Microsystems, Inc. to assist in its use, correction,
16 * modification or enhancement.
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20 * OR ANY PART THEREOF.
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23 * or profits or other special, indirect and consequential damages, even if
24 * Sun has been advised of the possibility of such damages.
26 * Sun Microsystems, Inc.
28 * Mountain View, California 94043
31 #if defined(LIBC_SCCS) && !defined(lint)
32 /*static char *sccsid = "from: @(#)getrpcent.c 1.14 91/03/11 Copyr 1984 Sun Micro";*/
33 static char *rcsid = "$FreeBSD: src/lib/libc/rpc/getrpcent.c,v 1.10 1999/08/28 00:00:39 peter Exp $";
37 * Copyright (c) 1984 by Sun Microsystems, Inc.
42 #include <sys/types.h>
46 #include <rpcsvc/yp_prot.h>
47 #include <rpcsvc/ypclnt.h>
57 char *rpc_aliases[MAXALIASES];
68 static int __yp_nomap = 0;
69 extern int _yp_check(char **);
72 static struct rpcent *interpret();
73 struct hostent *gethostent();
76 static char RPCDB[] = "/etc/rpc";
78 static struct rpcdata *
81 register struct rpcdata *d = rpcdata;
84 d = (struct rpcdata *)calloc(1, sizeof (struct rpcdata));
91 getrpcbynumber(number)
94 register struct rpcdata *d = _rpcdata();
95 register struct rpcent *p;
104 if (!__yp_nomap && _yp_check(&d->domain)) {
105 sprintf(adrstr, "%d", number);
106 reason = yp_match(d->domain, "rpc.bynumber", adrstr, strlen(adrstr),
107 &d->current, &d->currentlen);
119 d->current[d->currentlen] = '\0';
120 p = interpret(d->current, d->currentlen);
121 (void) free(d->current);
127 while ((p = getrpcent())) {
128 if (p->r_number == number)
139 struct rpcent *rpc = NULL;
143 while ((rpc = getrpcent())) {
144 if (strcmp(rpc->r_name, name) == 0)
146 for (rp = rpc->r_aliases; *rp != NULL; rp++) {
147 if (strcmp(*rp, name) == 0)
160 register struct rpcdata *d = _rpcdata();
165 if (!__yp_nomap && _yp_check(NULL)) {
175 d->rpcf = fopen(RPCDB, "r");
184 register struct rpcdata *d = _rpcdata();
189 if (!__yp_nomap && _yp_check(NULL)) {
190 if (d->current && !d->stayopen)
198 if (d->rpcf && !d->stayopen) {
207 register struct rpcdata *d = _rpcdata();
218 if (!__yp_nomap && _yp_check(&d->domain)) {
219 if (d->current == NULL && d->currentlen == 0) {
220 reason = yp_first(d->domain, "rpc.bynumber",
221 &d->current, &d->currentlen,
224 reason = yp_next(d->domain, "rpc.bynumber",
225 d->current, d->currentlen,
226 &d->current, &d->currentlen,
241 hp = interpret(val, vallen);
247 if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL)
249 /* -1 so there is room to append a \n below */
250 if (fgets(d->line, BUFSIZ - 1, d->rpcf) == NULL)
252 return (interpret(d->line, strlen(d->line)));
255 static struct rpcent *
260 register struct rpcdata *d = _rpcdata();
262 register char *cp, **q;
266 (void) strncpy(d->line, val, BUFSIZ);
267 d->line[BUFSIZ] = '\0';
271 return (getrpcent());
272 cp = strpbrk(p, "#\n");
274 return (getrpcent());
276 cp = strpbrk(p, " \t");
278 return (getrpcent());
280 /* THIS STUFF IS INTERNET SPECIFIC */
281 d->rpc.r_name = d->line;
282 while (*cp == ' ' || *cp == '\t')
284 d->rpc.r_number = atoi(cp);
285 q = d->rpc.r_aliases = d->rpc_aliases;
286 cp = strpbrk(cp, " \t");
290 if (*cp == ' ' || *cp == '\t') {
294 if (q < &(d->rpc_aliases[MAXALIASES - 1]))
296 cp = strpbrk(cp, " \t");