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
30 * @(#)getrpcent.c 1.14 91/03/11 Copyr 1984 Sun Micro
31 * $FreeBSD: src/lib/libc/rpc/getrpcent.c,v 1.10 1999/08/28 00:00:39 peter Exp $
32 * $DragonFly: src/lib/libc/rpc/getrpcent.c,v 1.2 2003/06/17 04:26:44 dillon Exp $
36 * Copyright (c) 1984 by Sun Microsystems, Inc.
41 #include <sys/types.h>
45 #include <rpcsvc/yp_prot.h>
46 #include <rpcsvc/ypclnt.h>
56 char *rpc_aliases[MAXALIASES];
67 static int __yp_nomap = 0;
68 extern int _yp_check(char **);
71 static struct rpcent *interpret();
72 struct hostent *gethostent();
75 static char RPCDB[] = "/etc/rpc";
77 static struct rpcdata *
80 register struct rpcdata *d = rpcdata;
83 d = (struct rpcdata *)calloc(1, sizeof (struct rpcdata));
90 getrpcbynumber(number)
93 register struct rpcdata *d = _rpcdata();
94 register struct rpcent *p;
103 if (!__yp_nomap && _yp_check(&d->domain)) {
104 sprintf(adrstr, "%d", number);
105 reason = yp_match(d->domain, "rpc.bynumber", adrstr, strlen(adrstr),
106 &d->current, &d->currentlen);
118 d->current[d->currentlen] = '\0';
119 p = interpret(d->current, d->currentlen);
120 (void) free(d->current);
126 while ((p = getrpcent())) {
127 if (p->r_number == number)
138 struct rpcent *rpc = NULL;
142 while ((rpc = getrpcent())) {
143 if (strcmp(rpc->r_name, name) == 0)
145 for (rp = rpc->r_aliases; *rp != NULL; rp++) {
146 if (strcmp(*rp, name) == 0)
159 register struct rpcdata *d = _rpcdata();
164 if (!__yp_nomap && _yp_check(NULL)) {
174 d->rpcf = fopen(RPCDB, "r");
183 register struct rpcdata *d = _rpcdata();
188 if (!__yp_nomap && _yp_check(NULL)) {
189 if (d->current && !d->stayopen)
197 if (d->rpcf && !d->stayopen) {
206 register struct rpcdata *d = _rpcdata();
217 if (!__yp_nomap && _yp_check(&d->domain)) {
218 if (d->current == NULL && d->currentlen == 0) {
219 reason = yp_first(d->domain, "rpc.bynumber",
220 &d->current, &d->currentlen,
223 reason = yp_next(d->domain, "rpc.bynumber",
224 d->current, d->currentlen,
225 &d->current, &d->currentlen,
240 hp = interpret(val, vallen);
246 if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL)
248 /* -1 so there is room to append a \n below */
249 if (fgets(d->line, BUFSIZ - 1, d->rpcf) == NULL)
251 return (interpret(d->line, strlen(d->line)));
254 static struct rpcent *
259 register struct rpcdata *d = _rpcdata();
261 register char *cp, **q;
265 (void) strncpy(d->line, val, BUFSIZ);
266 d->line[BUFSIZ] = '\0';
270 return (getrpcent());
271 cp = strpbrk(p, "#\n");
273 return (getrpcent());
275 cp = strpbrk(p, " \t");
277 return (getrpcent());
279 /* THIS STUFF IS INTERNET SPECIFIC */
280 d->rpc.r_name = d->line;
281 while (*cp == ' ' || *cp == '\t')
283 d->rpc.r_number = atoi(cp);
284 q = d->rpc.r_aliases = d->rpc_aliases;
285 cp = strpbrk(cp, " \t");
289 if (*cp == ' ' || *cp == '\t') {
293 if (q < &(d->rpc_aliases[MAXALIASES - 1]))
295 cp = strpbrk(cp, " \t");