]>
git.saurik.com Git - apple/libinfo.git/blob - rpc.subproj/getrpcent.c
c38a099d6ef8a33c1c93b2c7fdc9025673c2963e
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
27 * unrestricted use provided that this legend is included on all tape
28 * media and as a part of the software program in whole or part. Users
29 * may copy or modify Sun RPC without charge, but are not authorized
30 * to license or distribute it to anyone else except as part of a product or
31 * program developed by the user or with the express written consent of
32 * Sun Microsystems, Inc.
34 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
35 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
36 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
38 * Sun RPC is provided with no support and without any obligation on the
39 * part of Sun Microsystems, Inc. to assist in its use, correction,
40 * modification or enhancement.
42 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
43 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
44 * OR ANY PART THEREOF.
46 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
47 * or profits or other special, indirect and consequential damages, even if
48 * Sun has been advised of the possibility of such damages.
50 * Sun Microsystems, Inc.
52 * Mountain View, California 94043
55 #if defined(LIBC_SCCS) && !defined(lint)
56 /*static char *sccsid = "from: @(#)getrpcent.c 1.14 91/03/11 Copyr 1984 Sun Micro";*/
57 static char *rcsid
= "$Id: getrpcent.c,v 1.3 2002/02/19 20:36:23 epeyton Exp $";
61 * Copyright (c) 1984 by Sun Microsystems, Inc.
66 #include <sys/types.h>
77 char *rpc_aliases
[MAXALIASES
];
82 static struct rpcent
*interpret();
83 struct hostent
*gethostent();
86 static char RPCDB
[] = "/etc/rpc";
88 static struct rpcdata
*
91 register struct rpcdata
*d
= rpcdata
;
94 d
= (struct rpcdata
*)calloc(1, sizeof (struct rpcdata
));
101 getrpcbynumber(number
)
102 register long number
;
104 register struct rpcdata
*d
= _rpcdata();
105 register struct rpcent
*p
;
110 while ((p
= getrpcent())) {
111 if (p
->r_number
== number
)
120 #if defined(__APPLE__)
130 while ((rpc
= getrpcent())) {
131 if (strcmp(rpc
->r_name
, name
) == 0)
133 for (rp
= rpc
->r_aliases
; *rp
!= NULL
; rp
++) {
134 if (strcmp(*rp
, name
) == 0)
146 register struct rpcdata
*d
= _rpcdata();
151 d
->rpcf
= fopen(RPCDB
, "r");
160 register struct rpcdata
*d
= _rpcdata();
164 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");