]>
git.saurik.com Git - apple/libinfo.git/blob - rpc.subproj/getrpcent.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
26 * unrestricted use provided that this legend is included on all tape
27 * media and as a part of the software program in whole or part. Users
28 * may copy or modify Sun RPC without charge, but are not authorized
29 * to license or distribute it to anyone else except as part of a product or
30 * program developed by the user or with the express written consent of
31 * Sun Microsystems, Inc.
33 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
34 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
35 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
37 * Sun RPC is provided with no support and without any obligation on the
38 * part of Sun Microsystems, Inc. to assist in its use, correction,
39 * modification or enhancement.
41 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
42 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
43 * OR ANY PART THEREOF.
45 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
46 * or profits or other special, indirect and consequential damages, even if
47 * Sun has been advised of the possibility of such damages.
49 * Sun Microsystems, Inc.
51 * Mountain View, California 94043
54 #if defined(LIBC_SCCS) && !defined(lint)
55 /*static char *sccsid = "from: @(#)getrpcent.c 1.14 91/03/11 Copyr 1984 Sun Micro";*/
56 static char *rcsid
= "$Id: getrpcent.c,v 1.2 1999/10/14 21:56:53 wsanchez Exp $";
60 * Copyright (c) 1984 by Sun Microsystems, Inc.
64 #include <sys/types.h>
75 char *rpc_aliases
[MAXALIASES
];
80 static struct rpcent
*interpret();
81 struct hostent
*gethostent();
84 static char RPCDB
[] = "/etc/rpc";
86 static struct rpcdata
*
89 register struct rpcdata
*d
= rpcdata
;
92 d
= (struct rpcdata
*)calloc(1, sizeof (struct rpcdata
));
99 getrpcbynumber(number
)
100 register long number
;
102 register struct rpcdata
*d
= _rpcdata();
103 register struct rpcent
*p
;
108 while (p
= getrpcent()) {
109 if (p
->r_number
== number
)
118 #if defined(__APPLE__)
128 while (rpc
= getrpcent()) {
129 if (strcmp(rpc
->r_name
, name
) == 0)
131 for (rp
= rpc
->r_aliases
; *rp
!= NULL
; rp
++) {
132 if (strcmp(*rp
, name
) == 0)
144 register struct rpcdata
*d
= _rpcdata();
149 d
->rpcf
= fopen(RPCDB
, "r");
158 register struct rpcdata
*d
= _rpcdata();
162 if (d
->rpcf
&& !d
->stayopen
) {
173 register struct rpcdata
*d
= _rpcdata();
177 if (d
->rpcf
== NULL
&& (d
->rpcf
= fopen(RPCDB
, "r")) == NULL
)
179 if (fgets(d
->line
, BUFSIZ
, d
->rpcf
) == NULL
)
181 return (interpret(d
->line
, strlen(d
->line
)));
184 static struct rpcent
*
189 register struct rpcdata
*d
= _rpcdata();
191 register char *cp
, **q
;
195 (void) strncpy(d
->line
, val
, len
);
199 return (getrpcent());
200 cp
= strpbrk(p
, "#\n");
202 return (getrpcent());
204 cp
= strpbrk(p
, " \t");
206 return (getrpcent());
208 /* THIS STUFF IS INTERNET SPECIFIC */
209 d
->rpc
.r_name
= d
->line
;
210 while (*cp
== ' ' || *cp
== '\t')
212 d
->rpc
.r_number
= atoi(cp
);
213 q
= d
->rpc
.r_aliases
= d
->rpc_aliases
;
214 cp
= strpbrk(cp
, " \t");
218 if (*cp
== ' ' || *cp
== '\t') {
222 if (q
< &(d
->rpc_aliases
[MAXALIASES
- 1]))
224 cp
= strpbrk(cp
, " \t");