]>
git.saurik.com Git - apple/libinfo.git/blob - lookup.subproj/lu_rpc.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@
26 * Copyright (C) 1989 by NeXT, Inc.
32 #include <mach/mach.h>
35 #include <netinet/in.h>
37 #include "_lu_types.h"
40 #include "lu_overrides.h"
42 static lookup_state r_state
= LOOKUP_CACHE
;
43 static struct rpcent global_r
;
44 static int global_free
= 1;
45 static char *r_data
= NULL
;
46 static unsigned r_datalen
;
47 static int r_nentries
;
48 static int r_start
= 1;
56 if (global_free
== 1) return;
58 free(global_r
.r_name
);
60 aliases
= global_r
.r_aliases
;
63 while (*aliases
!= NULL
) free(*aliases
++);
64 free(global_r
.r_aliases
);
71 convert_r(_lu_rpcent
*lu_r
)
77 global_r
.r_name
= strdup(lu_r
->r_names
.r_names_val
[0]);
79 len
= lu_r
->r_names
.r_names_len
- 1;
80 global_r
.r_aliases
= (char **)malloc((len
+ 1) * sizeof(char *));
82 for (i
= 0; i
< len
; i
++)
84 global_r
.r_aliases
[i
] = strdup(lu_r
->r_names
.r_names_val
[i
+1]);
87 global_r
.r_aliases
[len
] = NULL
;
89 global_r
.r_number
= lu_r
->r_number
;
96 static struct rpcent
*
97 lu_getrpcbynumber(long number
)
102 static int proc
= -1;
103 unit lookup_buf
[MAX_INLINE_UNITS
];
107 if (_lookup_link(_lu_port
, "getrpcbynumber", &proc
) != KERN_SUCCESS
)
113 number
= htonl(number
);
114 datalen
= MAX_INLINE_UNITS
;
115 if (_lookup_one(_lu_port
, proc
, (unit
*)&number
, 1, lookup_buf
, &datalen
)
121 datalen
*= BYTES_PER_XDR_UNIT
;
122 xdrmem_create(&xdr
, lookup_buf
, datalen
, XDR_DECODE
);
124 if (!xdr__lu_rpcent_ptr(&xdr
, &lu_r
) || lu_r
== NULL
)
133 xdr_free(xdr__lu_rpcent_ptr
, &lu_r
);
137 static struct rpcent
*
138 lu_getrpcbyname(const char *name
)
141 char namebuf
[_LU_MAXLUSTRLEN
+ BYTES_PER_XDR_UNIT
];
145 static int proc
= -1;
146 unit lookup_buf
[MAX_INLINE_UNITS
];
150 if (_lookup_link(_lu_port
, "getrpcbyname", &proc
) != KERN_SUCCESS
)
156 xdrmem_create(&outxdr
, namebuf
, sizeof(namebuf
), XDR_ENCODE
);
157 if (!xdr__lu_string(&outxdr
, &name
))
159 xdr_destroy(&outxdr
);
163 datalen
= MAX_INLINE_UNITS
;
164 if (_lookup_one(_lu_port
, proc
, (unit
*)namebuf
,
165 xdr_getpos(&outxdr
) / BYTES_PER_XDR_UNIT
, lookup_buf
, &datalen
)
168 xdr_destroy(&outxdr
);
172 xdr_destroy(&outxdr
);
174 datalen
*= BYTES_PER_XDR_UNIT
;
175 xdrmem_create(&inxdr
, lookup_buf
, datalen
,
178 if (!xdr__lu_rpcent_ptr(&inxdr
, &lu_r
) || (lu_r
== NULL
))
187 xdr_free(xdr__lu_rpcent_ptr
, &lu_r
);
198 vm_deallocate(mach_task_self(), (vm_address_t
)r_data
, r_datalen
);
204 lu_setrpcent(int stayopen
)
211 static struct rpcent
*
214 static int proc
= -1;
223 if (_lookup_link(_lu_port
, "getrpcent", &proc
) != KERN_SUCCESS
)
230 if (_lookup_all(_lu_port
, proc
, NULL
, 0, &r_data
, &r_datalen
)
238 /* NOTDEF because OOL buffers are counted in bytes with untyped IPC */
239 r_datalen
*= BYTES_PER_XDR_UNIT
;
242 xdrmem_create(&r_xdr
, r_data
, r_datalen
,
244 if (!xdr_int(&r_xdr
, &r_nentries
))
259 bzero(&lu_r
, sizeof(lu_r
));
260 if (!xdr__lu_rpcent(&r_xdr
, &lu_r
))
269 xdr_free(xdr__lu_rpcent
, &lu_r
);
274 getrpcbynumber(long number
)
276 LOOKUP1(lu_getrpcbynumber
, _old_getrpcbynumber
, number
, struct rpcent
);
280 getrpcbyname(const char *name
)
282 LOOKUP1(lu_getrpcbyname
, _old_getrpcbyname
, name
, struct rpcent
);
288 GETENT(lu_getrpcent
, _old_getrpcent
, &r_state
, struct rpcent
);
292 setrpcent(int stayopen
)
294 SETSTATE(lu_setrpcent
, _old_setrpcent
, &r_state
, stayopen
);
300 UNSETSTATE(lu_endrpcent
, _old_endrpcent
, &r_state
);