summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bootparamd/callbootd
diff options
context:
space:
mode:
authorwpaul <wpaul@FreeBSD.org>1995-02-26 23:40:53 +0000
committerwpaul <wpaul@FreeBSD.org>1995-02-26 23:40:53 +0000
commit3d7a6e262b86c7c803cf9ce87bbc84ae2b8bef84 (patch)
tree3012a19322d01a3afd16fd186df2dc911e97a2ef /usr.sbin/bootparamd/callbootd
downloadFreeBSD-src-3d7a6e262b86c7c803cf9ce87bbc84ae2b8bef84.zip
FreeBSD-src-3d7a6e262b86c7c803cf9ce87bbc84ae2b8bef84.tar.gz
Obtained from: The Xkernel source distribution
I hope I'm doing this right. This is an initial version of bootparamd for FreeBSD based on a public domain rpc.bootparamd implementation by a gentleman named Klas Heggemann. This program has apparently been around for a while. The README explicitly lists the code as public domain, so I guess it's safe to use. This program is needed for booting diskless SunOS and Solaris machines. rarpd is also required, but that's in the works too. I have made two changes to this code: - Implemented NIS lookups. If /etc/bootparams contains a '+' then the bootparams map is consulted. - Allow 0.0.0.0 as a user-specified router address. The SunOS rpc.bootparamd returns this value in many cases.
Diffstat (limited to 'usr.sbin/bootparamd/callbootd')
-rw-r--r--usr.sbin/bootparamd/callbootd/Makefile28
-rw-r--r--usr.sbin/bootparamd/callbootd/callbootd.c187
2 files changed, 215 insertions, 0 deletions
diff --git a/usr.sbin/bootparamd/callbootd/Makefile b/usr.sbin/bootparamd/callbootd/Makefile
new file mode 100644
index 0000000..9be4af3
--- /dev/null
+++ b/usr.sbin/bootparamd/callbootd/Makefile
@@ -0,0 +1,28 @@
+# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
+# $Id: Makefile,v 1.1 1994/08/08 01:03:57 wollman Exp $
+
+PROG= callbootd
+SRCS= bootparam_prot_xdr.c bootparam_prot_clnt.c callbootd.c
+NOMAN=
+CLEANFILES= bootparam_prot_clnt.c bootparam_prot_xdr.c \
+ bootparam_prot.h bootparam_prot.x
+
+bootparam_prot_clnt.c: bootparam_prot.h
+ rm -f ${.CURDIR}/bootparam_prot.x
+ cp /usr/include/rpcsvc/bootparam_prot.x ${.CURDIR}
+ rpcgen -l -o ${.CURDIR}/bootparam_prot_clnt.c \
+ ${.CURDIR}/bootparam_prot.x
+
+bootparam_prot_xdr.c: bootparam_prot.h
+ rm -f ${.CURDIR}/bootparam_prot.x
+ cp /usr/include/rpcsvc/bootparam_prot.x ${.CURDIR}
+ rpcgen -c -o ${.CURDIR}/bootparam_prot_xdr.c \
+ ${.CURDIR}/bootparam_prot.x
+
+bootparam_prot.h:
+ rm -f ${.CURDIR}/bootparam_prot.x
+ cp /usr/include/rpcsvc/bootparam_prot.x ${.CURDIR}
+ rpcgen -h -o ${.CURDIR}/bootparam_prot.h \
+ ${.CURDIR}/bootparam_prot.x
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/bootparamd/callbootd/callbootd.c b/usr.sbin/bootparamd/callbootd/callbootd.c
new file mode 100644
index 0000000..22dbd5a
--- /dev/null
+++ b/usr.sbin/bootparamd/callbootd/callbootd.c
@@ -0,0 +1,187 @@
+/*
+
+This code is not copyright, and is placed in the public domain. Feel free to
+use and modify. Please send modifications and/or suggestions + bug fixes to
+
+ Klas Heggemann <klas@nada.kth.se>
+
+ $Id$
+*/
+
+
+#include "bootparam_prot.h"
+#include <rpc/rpc.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+
+/* #define bp_address_u bp_address */
+#include <stdio.h>
+
+int broadcast;
+
+char cln[MAX_MACHINE_NAME+1];
+char dmn[MAX_MACHINE_NAME+1];
+char path[MAX_PATH_LEN+1];
+extern char *inet_ntoa();
+
+eachres_whoami(resultp, raddr)
+bp_whoami_res *resultp;
+struct sockaddr_in *raddr;
+{
+ struct hostent *he;
+
+ he = gethostbyaddr((char *)&raddr->sin_addr.s_addr,4,AF_INET);
+ printf("%s answered:\n", he ? he->h_name : inet_ntoa(raddr->sin_addr));
+ printwhoami(resultp);
+ printf("\n");
+ return(0);
+}
+
+eachres_getfile(resultp, raddr)
+bp_getfile_res *resultp;
+struct sockaddr_in *raddr;
+{
+ struct hostent *he;
+
+ he = gethostbyaddr((char *)&raddr->sin_addr.s_addr,4,AF_INET);
+ printf("%s answered:\n", he ? he->h_name : inet_ntoa(raddr->sin_addr));
+ printgetfile(resultp);
+ printf("\n");
+ return(0);
+}
+
+
+main(argc, argv)
+int argc;
+char **argv;
+{
+ int stat;
+ char *server;
+
+ bp_whoami_arg whoami_arg;
+ bp_whoami_res *whoami_res, stat_whoami_res;
+ bp_getfile_arg getfile_arg;
+ bp_getfile_res *getfile_res, stat_getfile_res;
+
+
+ long the_inet_addr;
+ CLIENT *clnt;
+ enum clnt_stat clnt_stat;
+
+ stat_whoami_res.client_name = cln;
+ stat_whoami_res.domain_name = dmn;
+
+ stat_getfile_res.server_name = cln;
+ stat_getfile_res.server_path = path;
+
+ if (argc < 3) {
+ fprintf(stderr,
+ "Usage: %s server procnum (IP-addr | host fileid)\n", argv[0]);
+ exit(1);
+ }
+
+
+ server = argv[1];
+ if ( ! strcmp(server , "all") ) broadcast = 1;
+
+ if ( ! broadcast ) {
+ clnt = clnt_create(server,BOOTPARAMPROG, BOOTPARAMVERS, "udp");
+ }
+
+
+ switch (argc) {
+ case 3:
+ whoami_arg.client_address.address_type = IP_ADDR_TYPE;
+ the_inet_addr = inet_addr(argv[2]);
+ if ( the_inet_addr == -1) {
+ fprintf(stderr, "bogus addr %s\n", argv[2]);
+ exit(1);
+ }
+ bcopy(&the_inet_addr,&whoami_arg.client_address.bp_address_u.ip_addr,4);
+
+ if (! broadcast ) {
+ whoami_res = bootparamproc_whoami_1(&whoami_arg, clnt);
+ printf("Whoami returning:\n");
+ if (printwhoami(whoami_res)) {
+ fprintf(stderr, "Bad answer returned from server %s\n", server);
+ exit(1);
+ } else
+ exit(0);
+ } else {
+ clnt_stat=clnt_broadcast(BOOTPARAMPROG, BOOTPARAMVERS,
+ BOOTPARAMPROC_WHOAMI,
+ xdr_bp_whoami_arg, &whoami_arg,
+ xdr_bp_whoami_res, &stat_whoami_res, eachres_whoami);
+ exit(0);
+ }
+
+ case 4:
+
+ getfile_arg.client_name = argv[2];
+ getfile_arg.file_id = argv[3];
+
+ if (! broadcast ) {
+ getfile_res = bootparamproc_getfile_1(&getfile_arg,clnt);
+ printf("getfile returning:\n");
+ if (printgetfile(getfile_res)) {
+ fprintf(stderr, "Bad answer returned from server %s\n", server);
+ exit(1);
+ } else
+ exit(0);
+ } else {
+ clnt_stat=clnt_broadcast(BOOTPARAMPROG, BOOTPARAMVERS,
+ BOOTPARAMPROC_GETFILE,
+ xdr_bp_getfile_arg, &getfile_arg,
+ xdr_bp_getfile_res, &stat_getfile_res,eachres_getfile);
+ exit(0);
+ }
+
+ default:
+
+ fprintf(stderr,
+ "Usage: %s server procnum (IP-addr | host fileid)\n", argv[0]);
+ exit(1);
+ }
+
+}
+
+
+
+int printwhoami(res)
+bp_whoami_res *res;
+{
+ if ( res) {
+ printf("client_name:\t%s\ndomain_name:\t%s\n",
+ res->client_name, res->domain_name);
+ printf("router:\t%d.%d.%d.%d\n",
+ 255 & res->router_address.bp_address_u.ip_addr.net,
+ 255 & res->router_address.bp_address_u.ip_addr.host,
+ 255 & res->router_address.bp_address_u.ip_addr.lh,
+ 255 & res->router_address.bp_address_u.ip_addr.impno);
+ return(0);
+ } else {
+ fprintf(stderr,"Null answer!!!\n");
+ return(1);
+ }
+ }
+
+
+
+
+int
+printgetfile(res)
+bp_getfile_res *res;
+{
+ if (res) {
+ printf("server_name:\t%s\nserver_address:\t%s\npath:\t%s\n",
+ res->server_name,
+ inet_ntoa(res->server_address.bp_address_u.ip_addr),
+ res->server_path);
+ return(0);
+ } else {
+ fprintf(stderr,"Null answer!!!\n");
+ return(1);
+ }
+ }
OpenPOWER on IntegriCloud