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.4 2005/11/13 12:27:04 swildner 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 struct rpcdata
*d
= rpcdata
;
83 d
= (struct rpcdata
*)calloc(1, sizeof (struct rpcdata
));
90 getrpcbynumber(int number
)
92 struct rpcdata
*d
= _rpcdata();
102 if (!__yp_nomap
&& _yp_check(&d
->domain
)) {
103 sprintf(adrstr
, "%d", number
);
104 reason
= yp_match(d
->domain
, "rpc.bynumber", adrstr
, strlen(adrstr
),
105 &d
->current
, &d
->currentlen
);
117 d
->current
[d
->currentlen
] = '\0';
118 p
= interpret(d
->current
, d
->currentlen
);
125 while ((p
= getrpcent())) {
126 if (p
->r_number
== number
)
134 getrpcbyname(char *name
)
136 struct rpcent
*rpc
= NULL
;
140 while ((rpc
= getrpcent())) {
141 if (strcmp(rpc
->r_name
, name
) == 0)
143 for (rp
= rpc
->r_aliases
; *rp
!= NULL
; rp
++) {
144 if (strcmp(*rp
, name
) == 0)
156 struct rpcdata
*d
= _rpcdata();
161 if (!__yp_nomap
&& _yp_check(NULL
)) {
171 d
->rpcf
= fopen(RPCDB
, "r");
180 struct rpcdata
*d
= _rpcdata();
185 if (!__yp_nomap
&& _yp_check(NULL
)) {
186 if (d
->current
&& !d
->stayopen
)
194 if (d
->rpcf
&& !d
->stayopen
) {
203 struct rpcdata
*d
= _rpcdata();
214 if (!__yp_nomap
&& _yp_check(&d
->domain
)) {
215 if (d
->current
== NULL
&& d
->currentlen
== 0) {
216 reason
= yp_first(d
->domain
, "rpc.bynumber",
217 &d
->current
, &d
->currentlen
,
220 reason
= yp_next(d
->domain
, "rpc.bynumber",
221 d
->current
, d
->currentlen
,
222 &d
->current
, &d
->currentlen
,
237 hp
= interpret(val
, vallen
);
243 if (d
->rpcf
== NULL
&& (d
->rpcf
= fopen(RPCDB
, "r")) == NULL
)
245 /* -1 so there is room to append a \n below */
246 if (fgets(d
->line
, BUFSIZ
- 1, d
->rpcf
) == NULL
)
248 return (interpret(d
->line
, strlen(d
->line
)));
251 static struct rpcent
*
252 interpret(char *val
, int len
)
254 struct rpcdata
*d
= _rpcdata();
260 strncpy(d
->line
, val
, BUFSIZ
);
261 d
->line
[BUFSIZ
] = '\0';
265 return (getrpcent());
266 cp
= strpbrk(p
, "#\n");
268 return (getrpcent());
270 cp
= strpbrk(p
, " \t");
272 return (getrpcent());
274 /* THIS STUFF IS INTERNET SPECIFIC */
275 d
->rpc
.r_name
= d
->line
;
276 while (*cp
== ' ' || *cp
== '\t')
278 d
->rpc
.r_number
= atoi(cp
);
279 q
= d
->rpc
.r_aliases
= d
->rpc_aliases
;
280 cp
= strpbrk(cp
, " \t");
284 if (*cp
== ' ' || *cp
== '\t') {
288 if (q
< &(d
->rpc_aliases
[MAXALIASES
- 1]))
290 cp
= strpbrk(cp
, " \t");