1 /* @(#)getrpcent.c 2.2 88/07/29 4.0 RPCSRC */
2 #if !defined(lint) && defined(SCCSIDS)
3 static char sccsid
[] = "@(#)getrpcent.c 1.9 87/08/11 Copyr 1984 Sun Micro";
7 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
8 * unrestricted use provided that this legend is included on all tape
9 * media and as a part of the software program in whole or part. Users
10 * may copy or modify Sun RPC without charge, but are not authorized
11 * to license or distribute it to anyone else except as part of a product or
12 * program developed by the user.
14 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
15 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
18 * Sun RPC is provided with no support and without any obligation on the
19 * part of Sun Microsystems, Inc. to assist in its use, correction,
20 * modification or enhancement.
22 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
23 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
24 * OR ANY PART THEREOF.
26 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
27 * or profits or other special, indirect and consequential damages, even if
28 * Sun has been advised of the possibility of such damages.
30 * Sun Microsystems, Inc.
32 * Mountain View, California 94043
36 * Copyright (c) 1985 by Sun Microsystems, Inc.
40 #include <sys/types.h>
43 #include <sys/socket.h>
54 char *rpc_aliases
[MAXALIASES
];
58 } *rpcdata
, *_rpcdata();
60 static struct rpcent
*interpret();
61 struct hostent
*gethostent();
63 extern char *index(); /* Changed from static by roland@gnu */
65 static char RPCDB
[] = _PATH_RPC
; /* Changed from "/etc/rpc" by roland@gnu */
67 static struct rpcdata
*
70 register struct rpcdata
*d
= rpcdata
;
73 d
= (struct rpcdata
*)calloc(1, sizeof (struct rpcdata
));
80 getrpcbynumber(number
)
83 register struct rpcdata
*d
= _rpcdata();
84 register struct rpcent
*p
;
86 char adrstr
[16], *val
= NULL
;
92 while (p
= getrpcent()) {
93 if (p
->r_number
== number
)
102 const char *name
; /* const added by roland@gnu */
108 while(rpc
= getrpcent()) {
109 if (strcmp(rpc
->r_name
, name
) == 0)
111 for (rp
= rpc
->r_aliases
; *rp
!= NULL
; rp
++) {
112 if (strcmp(*rp
, name
) == 0)
123 register struct rpcdata
*d
= _rpcdata();
128 d
->rpcf
= fopen(RPCDB
, "r");
139 register struct rpcdata
*d
= _rpcdata();
143 if (d
->current
&& !d
->stayopen
) {
147 if (d
->rpcf
&& !d
->stayopen
) {
158 char *key
= NULL
, *val
= NULL
;
160 register struct rpcdata
*d
= _rpcdata();
164 if (d
->rpcf
== NULL
&& (d
->rpcf
= fopen(RPCDB
, "r")) == NULL
)
166 if (fgets(d
->line
, BUFSIZ
, d
->rpcf
) == NULL
)
168 return interpret(d
->line
, strlen(d
->line
));
171 static struct rpcent
*
174 register struct rpcdata
*d
= _rpcdata();
176 register char *cp
, **q
;
180 strncpy(d
->line
, val
, len
);
184 return (getrpcent());
190 return (getrpcent());
198 return (getrpcent());
201 /* THIS STUFF IS INTERNET SPECIFIC */
202 d
->rpc
.r_name
= d
->line
;
203 while (*cp
== ' ' || *cp
== '\t')
205 d
->rpc
.r_number
= atoi(cp
);
206 q
= d
->rpc
.r_aliases
= d
->rpc_aliases
;
217 if (*cp
== ' ' || *cp
== '\t') {
221 if (q
< &(d
->rpc_aliases
[MAXALIASES
- 1]))