1 /* $NetBSD: test.c,v 1.2 2004/01/05 23:23:38 jmmv Exp $ */
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
34 __RCSID("$NetBSD: test.c,v 1.2 2004/01/05 23:23:38 jmmv Exp $");
43 #include <rpcsvc/bootparam_prot.h>
45 /* Default timeout can be changed using clnt_control() */
46 static struct timeval TIMEOUT
= {25, 0};
48 int main(int, char *[]);
51 bootparamproc_whoami_1(argp
, clnt
)
55 static bp_whoami_res res
;
59 (void)memset(&res
, 0, sizeof(res
));
60 if ((st
= clnt_call(clnt
, BOOTPARAMPROC_WHOAMI
, xdr_bp_whoami_arg
, argp
,
61 xdr_bp_whoami_res
, &res
, TIMEOUT
)) != RPC_SUCCESS
) {
62 warnx("clnt_call returned %s", clnt_sperrno(st
));
81 warnx("usage: test <hostname>");
82 errx(1, "Always talks to bootparamd at localhost");
84 if ((hp
= gethostbyname(argv
[1])) == NULL
)
85 errx(1, "Cannot resolve `%s'", argv
[1]);
87 printf("Creating client for localhost\n");
88 cli
= clnt_create("localhost", BOOTPARAMPROG
, BOOTPARAMVERS
, "udp");
90 errx(1, "Failed to create client");
91 memcpy(&addr
, hp
->h_addr_list
[0], sizeof(addr
));
93 bp
.client_address
.address_type
= IP_ADDR_TYPE
;
94 bp
.client_address
.bp_address_u
.ip_addr
.net
= (addr
>> 24) & 0xff;
95 bp
.client_address
.bp_address_u
.ip_addr
.host
= (addr
>> 16) & 0xff;
96 bp
.client_address
.bp_address_u
.ip_addr
.lh
= (addr
>> 8) & 0xff;
97 bp
.client_address
.bp_address_u
.ip_addr
.impno
= (addr
>> 0) & 0xff;
99 if ((out
= bootparamproc_whoami_1(&bp
, cli
)) != NULL
) {
100 printf("Success [host=%s, domain=%s, gw=%d.%d.%d.%d]\n",
101 out
->client_name
, out
->domain_name
,
102 out
->router_address
.bp_address_u
.ip_addr
.net
& 0xff,
103 out
->router_address
.bp_address_u
.ip_addr
.host
& 0xff,
104 out
->router_address
.bp_address_u
.ip_addr
.lh
& 0xff,
105 out
->router_address
.bp_address_u
.ip_addr
.impno
& 0xff);