1 /*********************************************************************
2 * RPC for the Windows NT Operating System
3 * 1993 by Martin F. Gergeleit
4 * Users may use, copy or modify Sun RPC for the Windows NT Operating
5 * System according to the Sun copyright below.
7 * RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO
8 * WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE
9 * USE OF. USE ENTIRELY AT YOUR OWN RISK!!!
10 *********************************************************************/
12 /* @(#)getrpcent.c 2.2 88/07/29 4.0 RPCSRC */
13 #if !defined(lint) && defined(SCCSIDS)
14 static char sccsid[] = "@(#)getrpcent.c 1.9 87/08/11 Copyr 1984 Sun Micro";
18 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
19 * unrestricted use provided that this legend is included on all tape
20 * media and as a part of the software program in whole or part. Users
21 * may copy or modify Sun RPC without charge, but are not authorized
22 * to license or distribute it to anyone else except as part of a product or
23 * program developed by the user.
25 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
26 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
29 * Sun RPC is provided with no support and without any obligation on the
30 * part of Sun Microsystems, Inc. to assist in its use, correction,
31 * modification or enhancement.
33 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
34 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
35 * OR ANY PART THEREOF.
37 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
38 * or profits or other special, indirect and consequential damages, even if
39 * Sun has been advised of the possibility of such damages.
41 * Sun Microsystems, Inc.
43 * Mountain View, California 94043
47 * Copyright (c) 1985 by Sun Microsystems, Inc.
51 #include <sys/types.h>
55 #include <sys/socket.h>
58 // eventually we might be able to support autoconf via cygwin...
59 #if defined (_MSC_VER) || defined(__BORLANDC__)
60 # include "config_win32.h"
65 #ifndef HAVE_STRUCT_RPCENT
66 /* routines for parsing /etc/rpc */
67 #include <rpc/netdb.h> /* structures and routines to parse /etc/rpc */
79 char *rpc_aliases[MAXALIASES];
83 } *rpcdata, *_rpcdata();
85 static struct rpcent *interpret();
86 struct hostent *gethostent();
88 #define index(str,ch) strchr(str,ch)
95 static char RPCDB[1024];
97 static char RPCDB[] = "/etc/rpc";
100 static struct rpcdata *
103 register struct rpcdata *d = rpcdata;
108 if ((RPCDB[0] == '\0') && (str = getenv("SystemRoot"))) {
110 strcat(RPCDB, "\\system32\\drivers\\etc\\rpc");
115 d = (struct rpcdata *)calloc(1, sizeof (struct rpcdata));
122 getrpcbynumber(number)
125 register struct rpcdata *d = _rpcdata();
126 register struct rpcent *p;
128 char adrstr[16], *val = NULL;
134 while (p = getrpcent()) {
135 if (p->r_number == number)
150 while(rpc = getrpcent()) {
151 if (strcmp(rpc->r_name, name) == 0)
153 for (rp = rpc->r_aliases; *rp != NULL; rp++) {
154 if (strcmp(*rp, name) == 0)
165 register struct rpcdata *d = _rpcdata();
170 d->rpcf = fopen(RPCDB, "r");
181 register struct rpcdata *d = _rpcdata();
185 if (d->current && !d->stayopen) {
189 if (d->rpcf && !d->stayopen) {
200 char *key = NULL, *val = NULL;
202 register struct rpcdata *d = _rpcdata();
206 if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL)
208 if (fgets(d->line, BUFSIZ, d->rpcf) == NULL)
210 return interpret(d->line, strlen(d->line));
213 static struct rpcent *
217 register struct rpcdata *d = _rpcdata();
219 register char *cp, **q;
223 strncpy(d->line, val, len);
227 return (getrpcent());
233 return (getrpcent());
241 return (getrpcent());
244 /* THIS STUFF IS INTERNET SPECIFIC */
245 d->rpc.r_name = d->line;
246 while (*cp == ' ' || *cp == '\t')
248 d->rpc.r_number = atoi(cp);
249 q = d->rpc.r_aliases = d->rpc_aliases;
260 if (*cp == ' ' || *cp == '\t') {
264 if (q < &(d->rpc_aliases[MAXALIASES - 1]))