summaryrefslogtreecommitdiff
path: root/usr.sbin/rpc.bootparamd
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2002-09-11 18:19:42 +0000
committerchristos <christos@NetBSD.org>2002-09-11 18:19:42 +0000
commitd0deebbba7294c016fdc8bf6b4409840b81e73df (patch)
tree7243cc2f38a7bae0c04710d158bf96b44741aa09 /usr.sbin/rpc.bootparamd
parentd603bed369f0b872dfa67cee018171c019641ce1 (diff)
Add a simple test to see if the whoami functionality works.
Diffstat (limited to 'usr.sbin/rpc.bootparamd')
-rw-r--r--usr.sbin/rpc.bootparamd/Makefile5
-rw-r--r--usr.sbin/rpc.bootparamd/test.c117
2 files changed, 121 insertions, 1 deletions
diff --git a/usr.sbin/rpc.bootparamd/Makefile b/usr.sbin/rpc.bootparamd/Makefile
index 6fe6381a145..b9755ba9374 100644
--- a/usr.sbin/rpc.bootparamd/Makefile
+++ b/usr.sbin/rpc.bootparamd/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.21 2002/03/22 18:10:25 thorpej Exp $
+# $NetBSD: Makefile,v 1.22 2002/09/11 18:19:42 christos Exp $
.include <bsd.own.mk>
@@ -28,3 +28,6 @@ bootparam_prot.h: ${DESTDIR}/usr/include/rpcsvc/bootparam_prot.h
bootparam_prot_svc.c: bootparam_prot.x bootparam_prot.h
${RPCGEN} -C -L -m -o ${.TARGET} bootparam_prot.x
+
+test: test.c
+ cc -o test ${.ALLSRC} -lrpcsvc
diff --git a/usr.sbin/rpc.bootparamd/test.c b/usr.sbin/rpc.bootparamd/test.c
new file mode 100644
index 00000000000..10871af81d4
--- /dev/null
+++ b/usr.sbin/rpc.bootparamd/test.c
@@ -0,0 +1,117 @@
+/* $NetBSD: test.c,v 1.1 2002/09/11 18:19:42 christos Exp $ */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: test.c,v 1.1 2002/09/11 18:19:42 christos Exp $");
+#endif
+
+#include <stdio.h>
+#include <netdb.h>
+#include <string.h>
+#include <err.h>
+
+#include <rpc/rpc.h>
+#include <rpcsvc/bootparam_prot.h>
+
+/* Default timeout can be changed using clnt_control() */
+static struct timeval TIMEOUT = {25, 0};
+
+int main(int, char *[]);
+
+bp_whoami_res *
+bootparamproc_whoami_1(argp, clnt)
+ bp_whoami_arg *argp;
+ CLIENT *clnt;
+{
+ static bp_whoami_res res;
+ enum clnt_stat st;
+
+
+ (void)memset(&res, 0, sizeof(res));
+ if ((st = clnt_call(clnt, BOOTPARAMPROC_WHOAMI, xdr_bp_whoami_arg, argp,
+ xdr_bp_whoami_res, &res, TIMEOUT)) != RPC_SUCCESS) {
+ warnx("clnt_call returned %s", clnt_sperrno(st));
+ return NULL;
+ }
+ return &res;
+}
+
+
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ CLIENT *cli;
+ bp_whoami_res *out;
+ bp_whoami_arg bp;
+ struct hostent *hp;
+ uint32_t addr;
+
+ if (argc < 2) {
+ warnx("Usage: test <hostname>");
+ errx(1, "Always talks to bootparamd at localhost");
+ }
+ if ((hp = gethostbyname(argv[1])) == NULL)
+ errx(1, "Cannot resolve `%s'", argv[1]);
+
+ printf("Creating client for localhost\n");
+ cli = clnt_create("localhost", BOOTPARAMPROG, BOOTPARAMVERS, "udp");
+ if (!cli)
+ errx(1, "Failed to create client");
+ memcpy(&addr, hp->h_addr_list[0], sizeof(addr));
+ addr = htonl(addr);
+ bp.client_address.address_type = IP_ADDR_TYPE;
+ bp.client_address.bp_address_u.ip_addr.net = (addr >> 24) & 0xff;
+ bp.client_address.bp_address_u.ip_addr.host = (addr >> 16) & 0xff;
+ bp.client_address.bp_address_u.ip_addr.lh = (addr >> 8) & 0xff;
+ bp.client_address.bp_address_u.ip_addr.impno = (addr >> 0) & 0xff;
+
+ if ((out = bootparamproc_whoami_1(&bp, cli)) != NULL) {
+ printf("Success [host=%s, domain=%s, gw=%d.%d.%d.%d]\n",
+ out->client_name, out->domain_name,
+ out->router_address.bp_address_u.ip_addr.net & 0xff,
+ out->router_address.bp_address_u.ip_addr.host & 0xff,
+ out->router_address.bp_address_u.ip_addr.lh & 0xff,
+ out->router_address.bp_address_u.ip_addr.impno & 0xff);
+ } else
+ printf("Fail\n");
+
+ return 0;
+}