freebsd-skq/usr.sbin/bootparamd/callbootd/callbootd.c

199 lines
4.3 KiB
C
Raw Normal View History

/*
1995-05-30 03:57:47 +00:00
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>
*/
#ifndef lint
static const char rcsid[] =
1999-08-28 01:35:59 +00:00
"$FreeBSD$";
#endif /* not lint */
#include "bootparam_prot.h"
#include <rpc/rpc.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <err.h>
#include <netdb.h>
/* #define bp_address_u bp_address */
#include <stdio.h>
#include <string.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();
static void usage __P((void));
int printgetfile __P((bp_getfile_res *));
int printwhoami __P((bp_whoami_res *));
int
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);
}
int
main(argc, argv)
int argc;
char **argv;
{
char *server;
1995-05-30 03:57:47 +00:00
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;
1995-05-30 03:57:47 +00:00
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;
1995-05-30 03:57:47 +00:00
if (argc < 3)
usage();
server = argv[1];
if ( ! strcmp(server , "all") ) broadcast = 1;
1995-05-30 03:57:47 +00:00
if ( ! broadcast ) {
clnt = clnt_create(server,BOOTPARAMPROG, BOOTPARAMVERS, "udp");
1995-05-30 03:57:47 +00:00
}
if ( clnt == NULL )
errx(1, "could not contact bootparam server on host %s", server);
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)
errx(2, "bogus addr %s", argv[2]);
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)) {
errx(1, "bad answer returned from server %s", server);
} else
exit(0);
} else {
1995-05-30 03:57:47 +00:00
clnt_stat=clnt_broadcast(BOOTPARAMPROG, BOOTPARAMVERS,
BOOTPARAMPROC_WHOAMI,
1995-05-30 03:57:47 +00:00
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];
1995-05-30 03:57:47 +00:00
if (! broadcast ) {
getfile_res = bootparamproc_getfile_1(&getfile_arg,clnt);
printf("getfile returning:\n");
if (printgetfile(getfile_res)) {
errx(1, "bad answer returned from server %s", server);
} else
1995-05-30 03:57:47 +00:00
exit(0);
} else {
1995-05-30 03:57:47 +00:00
clnt_stat=clnt_broadcast(BOOTPARAMPROG, BOOTPARAMVERS,
BOOTPARAMPROC_GETFILE,
1995-05-30 03:57:47 +00:00
xdr_bp_getfile_arg, &getfile_arg,
xdr_bp_getfile_res, &stat_getfile_res,eachres_getfile);
exit(0);
}
1995-05-30 03:57:47 +00:00
default:
1995-05-30 03:57:47 +00:00
usage();
}
1995-05-30 03:57:47 +00:00
}
static void
usage()
{
fprintf(stderr,
"usage: callbootd server procnum (IP-addr | host fileid)\n");
exit(1);
}
1995-05-30 03:57:47 +00:00
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 {
warnx("null answer!!!");
return(1);
}
}
1995-05-30 03:57:47 +00:00
int
printgetfile(res)
bp_getfile_res *res;
{
if (res) {
printf("server_name:\t%s\nserver_address:\t%s\npath:\t%s\n",
1995-05-30 03:57:47 +00:00
res->server_name,
inet_ntoa(*(struct in_addr *)&res->server_address.bp_address_u.ip_addr),
res->server_path);
return(0);
} else {
warnx("null answer!!!");
return(1);
}
}