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 * $NetBSD: getrpcent.c,v 1.17 2000/01/22 22:19:17 mycroft Exp $
32 * $FreeBSD: src/lib/libc/rpc/getrpcent.c,v 1.14 2003/02/27 13:40:01 nectar Exp $
33 * $DragonFly: src/lib/libc/rpc/getrpcent.c,v 1.4 2005/11/13 12:27:04 swildner Exp $
37 * Copyright (c) 1984 by Sun Microsystems, Inc.
40 #include "namespace.h"
41 #include <sys/types.h>
43 #include <netinet/in.h>
44 #include <arpa/inet.h>
54 #include <rpcsvc/yp_prot.h>
55 #include <rpcsvc/ypclnt.h>
57 #include "un-namespace.h"
58 #include "libc_private.h"
63 static struct rpcdata
{
67 char *rpc_aliases
[MAXALIASES
];
77 static struct rpcent
*interpret(char *val
, size_t len
);
80 static int __yp_nomap
= 0;
83 #define RPCDB "/etc/rpc"
85 static struct rpcdata
*_rpcdata(void);
87 static struct rpcdata
*
90 struct rpcdata
*d
= rpcdata
;
93 d
= (struct rpcdata
*)calloc(1, sizeof (struct rpcdata
));
100 getrpcbynumber(int number
)
107 struct rpcdata
*d
= _rpcdata();
112 if (!__yp_nomap
&& _yp_check(&d
->domain
)) {
113 sprintf(adrstr
, "%d", number
);
114 reason
= yp_match(d
->domain
, "rpc.bynumber", adrstr
, strlen(adrstr
),
115 &d
->current
, &d
->currentlen
);
127 d
->current
[d
->currentlen
] = '\0';
128 p
= interpret(d
->current
, d
->currentlen
);
136 while ((p
= getrpcent()) != NULL
) {
137 if (p
->r_number
== number
)
145 getrpcbyname(char *name
)
147 struct rpcent
*rpc
= NULL
;
150 assert(name
!= NULL
);
153 while ((rpc
= getrpcent()) != NULL
) {
154 if (strcmp(rpc
->r_name
, name
) == 0)
156 for (rp
= rpc
->r_aliases
; *rp
!= NULL
; rp
++) {
157 if (strcmp(*rp
, name
) == 0)
169 struct rpcdata
*d
= _rpcdata();
174 if (!__yp_nomap
&& _yp_check(NULL
)) {
184 d
->rpcf
= fopen(RPCDB
, "r");
193 struct rpcdata
*d
= _rpcdata();
198 if (!__yp_nomap
&& _yp_check(NULL
)) {
199 if (d
->current
&& !d
->stayopen
)
207 if (d
->rpcf
&& !d
->stayopen
) {
216 struct rpcdata
*d
= _rpcdata();
227 if (!__yp_nomap
&& _yp_check(&d
->domain
)) {
228 if (d
->current
== NULL
&& d
->currentlen
== 0) {
229 reason
= yp_first(d
->domain
, "rpc.bynumber",
230 &d
->current
, &d
->currentlen
,
233 reason
= yp_next(d
->domain
, "rpc.bynumber",
234 d
->current
, d
->currentlen
,
235 &d
->current
, &d
->currentlen
,
250 hp
= interpret(val
, vallen
);
256 if (d
->rpcf
== NULL
&& (d
->rpcf
= fopen(RPCDB
, "r")) == NULL
)
258 /* -1 so there is room to append a \n below */
259 if (fgets(d
->line
, BUFSIZ
- 1, d
->rpcf
) == NULL
)
261 return (interpret(d
->line
, strlen(d
->line
)));
264 static struct rpcent
*
265 interpret(char *val
, size_t len
)
267 struct rpcdata
*d
= _rpcdata();
275 strncpy(d
->line
, val
, BUFSIZ
);
276 d
->line
[BUFSIZ
] = '\0';
280 return (getrpcent());
281 cp
= strpbrk(p
, "#\n");
283 return (getrpcent());
285 cp
= strpbrk(p
, " \t");
287 return (getrpcent());
289 /* THIS STUFF IS INTERNET SPECIFIC */
290 d
->rpc
.r_name
= d
->line
;
291 while (*cp
== ' ' || *cp
== '\t')
293 d
->rpc
.r_number
= atoi(cp
);
294 q
= d
->rpc
.r_aliases
= d
->rpc_aliases
;
295 cp
= strpbrk(cp
, " \t");
299 if (*cp
== ' ' || *cp
== '\t') {
303 if (q
< &(d
->rpc_aliases
[MAXALIASES
- 1]))
305 cp
= strpbrk(cp
, " \t");