]>
git.saurik.com Git - apple/libinfo.git/blob - lookup.subproj/lu_bootp.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 * Bootp lookup - netinfo only
26 * Copyright (C) 1989 by NeXT, Inc.
28 #include <mach/mach.h>
32 #include <rpc/types.h>
34 #include "_lu_types.h"
36 #include <sys/socket.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
40 #include <netinet/if_ether.h>
43 lu_bootp_getbyether(struct ether_addr
*enaddr
, char **name
,
44 struct in_addr
*ipaddr
, char **bootfile
)
48 static _lu_bootp_ent_ptr bp
;
50 unit lookup_buf
[MAX_INLINE_UNITS
];
54 if (_lookup_link(_lu_port
, "bootp_getbyether", &proc
) != KERN_SUCCESS
)
60 datalen
= MAX_INLINE_UNITS
;
61 if (_lookup_one(_lu_port
, proc
, (unit
*)enaddr
,
62 ((sizeof(*enaddr
) + sizeof(unit
) - 1) / sizeof(unit
)), lookup_buf
,
63 &datalen
) != KERN_SUCCESS
)
68 datalen
*= BYTES_PER_XDR_UNIT
;
69 xdrmem_create(&xdr
, lookup_buf
, datalen
, XDR_DECODE
);
70 xdr_free(xdr__lu_bootp_ent_ptr
, &bp
);
71 if (!xdr__lu_bootp_ent_ptr(&xdr
, &bp
) || (bp
== NULL
))
79 *name
= bp
->bootp_name
;
80 *bootfile
= bp
->bootp_bootfile
;
81 ipaddr
->s_addr
= bp
->bootp_ipaddr
;
86 lu_bootp_getbyip(struct ether_addr
*enaddr
, char **name
,
87 struct in_addr
*ipaddr
, char **bootfile
)
91 static _lu_bootp_ent_ptr bp
;
93 unit lookup_buf
[MAX_INLINE_UNITS
];
97 if (_lookup_link(_lu_port
, "bootp_getbyip", &proc
) != KERN_SUCCESS
)
103 datalen
= MAX_INLINE_UNITS
;
104 if (_lookup_one(_lu_port
, proc
, (unit
*)ipaddr
,
105 ((sizeof(*ipaddr
) + sizeof(unit
) - 1) / sizeof(unit
)), lookup_buf
,
106 &datalen
) != KERN_SUCCESS
)
111 datalen
*= BYTES_PER_XDR_UNIT
;
112 xdrmem_create(&xdr
, lookup_buf
, datalen
, XDR_DECODE
);
113 xdr_free(xdr__lu_bootp_ent_ptr
, &bp
);
114 if (!xdr__lu_bootp_ent_ptr(&xdr
, &bp
) || (bp
== NULL
))
122 *name
= bp
->bootp_name
;
123 *bootfile
= bp
->bootp_bootfile
;
124 bcopy(bp
->bootp_enaddr
, enaddr
, sizeof(*enaddr
));
129 bootp_getbyether(struct ether_addr
*enaddr
, char **name
,
130 struct in_addr
*ipaddr
, char **bootfile
)
133 return (lu_bootp_getbyether(enaddr
, name
, ipaddr
, bootfile
));
138 bootp_getbyip(struct ether_addr
*enaddr
, char **name
,
139 struct in_addr
*ipaddr
, char **bootfile
)
142 return (lu_bootp_getbyip(enaddr
, name
, ipaddr
, bootfile
));