Deleted Added
full compact
callbootd.c (22997) callbootd.c (29102)
1/*
2
3This code is not copyright, and is placed in the public domain. Feel free to
4use and modify. Please send modifications and/or suggestions + bug fixes to
5
6 Klas Heggemann <klas@nada.kth.se>
7
1/*
2
3This code is not copyright, and is placed in the public domain. Feel free to
4use and modify. Please send modifications and/or suggestions + bug fixes to
5
6 Klas Heggemann <klas@nada.kth.se>
7
8 $Id$
9*/
10
8*/
9
10#ifndef lint
11static const char rcsid[] =
12 "$Id$";
13#endif /* not lint */
11
12#include "bootparam_prot.h"
13#include <rpc/rpc.h>
14#include <sys/types.h>
15#include <sys/socket.h>
14
15#include "bootparam_prot.h"
16#include <rpc/rpc.h>
17#include <sys/types.h>
18#include <sys/socket.h>
19#include <err.h>
16#include <netdb.h>
17
18
19/* #define bp_address_u bp_address */
20#include <stdio.h>
20#include <netdb.h>
21
22
23/* #define bp_address_u bp_address */
24#include <stdio.h>
25#include <string.h>
21
22int broadcast;
23
24char cln[MAX_MACHINE_NAME+1];
25char dmn[MAX_MACHINE_NAME+1];
26char path[MAX_PATH_LEN+1];
27extern char *inet_ntoa();
26
27int broadcast;
28
29char cln[MAX_MACHINE_NAME+1];
30char dmn[MAX_MACHINE_NAME+1];
31char path[MAX_PATH_LEN+1];
32extern char *inet_ntoa();
33static void usage __P((void));
34int printgetfile __P((bp_getfile_res *));
35int printwhoami __P((bp_whoami_res *));
28
36
37int
29eachres_whoami(resultp, raddr)
30bp_whoami_res *resultp;
31struct sockaddr_in *raddr;
32{
33 struct hostent *he;
34
35 he = gethostbyaddr((char *)&raddr->sin_addr.s_addr,4,AF_INET);
36 printf("%s answered:\n", he ? he->h_name : inet_ntoa(raddr->sin_addr));

--- 11 unchanged lines hidden (view full) ---

48 he = gethostbyaddr((char *)&raddr->sin_addr.s_addr,4,AF_INET);
49 printf("%s answered:\n", he ? he->h_name : inet_ntoa(raddr->sin_addr));
50 printgetfile(resultp);
51 printf("\n");
52 return(0);
53}
54
55
38eachres_whoami(resultp, raddr)
39bp_whoami_res *resultp;
40struct sockaddr_in *raddr;
41{
42 struct hostent *he;
43
44 he = gethostbyaddr((char *)&raddr->sin_addr.s_addr,4,AF_INET);
45 printf("%s answered:\n", he ? he->h_name : inet_ntoa(raddr->sin_addr));

--- 11 unchanged lines hidden (view full) ---

57 he = gethostbyaddr((char *)&raddr->sin_addr.s_addr,4,AF_INET);
58 printf("%s answered:\n", he ? he->h_name : inet_ntoa(raddr->sin_addr));
59 printgetfile(resultp);
60 printf("\n");
61 return(0);
62}
63
64
65int
56main(argc, argv)
57int argc;
58char **argv;
59{
66main(argc, argv)
67int argc;
68char **argv;
69{
60 int stat;
61 char *server;
62
63 bp_whoami_arg whoami_arg;
64 bp_whoami_res *whoami_res, stat_whoami_res;
65 bp_getfile_arg getfile_arg;
66 bp_getfile_res *getfile_res, stat_getfile_res;
67
68
69 long the_inet_addr;
70 CLIENT *clnt;
71 enum clnt_stat clnt_stat;
72
73 stat_whoami_res.client_name = cln;
74 stat_whoami_res.domain_name = dmn;
75
76 stat_getfile_res.server_name = cln;
77 stat_getfile_res.server_path = path;
78
70 char *server;
71
72 bp_whoami_arg whoami_arg;
73 bp_whoami_res *whoami_res, stat_whoami_res;
74 bp_getfile_arg getfile_arg;
75 bp_getfile_res *getfile_res, stat_getfile_res;
76
77
78 long the_inet_addr;
79 CLIENT *clnt;
80 enum clnt_stat clnt_stat;
81
82 stat_whoami_res.client_name = cln;
83 stat_whoami_res.domain_name = dmn;
84
85 stat_getfile_res.server_name = cln;
86 stat_getfile_res.server_path = path;
87
79 if (argc < 3) {
80 fprintf(stderr,
81 "Usage: %s server procnum (IP-addr | host fileid)\n", argv[0]);
82 exit(1);
83 }
88 if (argc < 3)
89 usage();
84
90
85
86 server = argv[1];
87 if ( ! strcmp(server , "all") ) broadcast = 1;
88
89 if ( ! broadcast ) {
90 clnt = clnt_create(server,BOOTPARAMPROG, BOOTPARAMVERS, "udp");
91 }
92
91 server = argv[1];
92 if ( ! strcmp(server , "all") ) broadcast = 1;
93
94 if ( ! broadcast ) {
95 clnt = clnt_create(server,BOOTPARAMPROG, BOOTPARAMVERS, "udp");
96 }
97
93 if ( clnt == NULL ) {
94 fprintf (stderr, "%s: could not contact bootparam server on host %s\n",
95 argv[0], server);
96 exit (1);
97 }
98 if ( clnt == NULL )
99 errx(1, "could not contact bootparam server on host %s", server);
98
99 switch (argc) {
100 case 3:
101 whoami_arg.client_address.address_type = IP_ADDR_TYPE;
102 the_inet_addr = inet_addr(argv[2]);
100
101 switch (argc) {
102 case 3:
103 whoami_arg.client_address.address_type = IP_ADDR_TYPE;
104 the_inet_addr = inet_addr(argv[2]);
103 if ( the_inet_addr == -1) {
104 fprintf(stderr, "bogus addr %s\n", argv[2]);
105 exit(1);
106 }
105 if ( the_inet_addr == -1)
106 errx(2, "bogus addr %s", argv[2]);
107 bcopy(&the_inet_addr,&whoami_arg.client_address.bp_address_u.ip_addr,4);
108
109 if (! broadcast ) {
110 whoami_res = bootparamproc_whoami_1(&whoami_arg, clnt);
111 printf("Whoami returning:\n");
112 if (printwhoami(whoami_res)) {
107 bcopy(&the_inet_addr,&whoami_arg.client_address.bp_address_u.ip_addr,4);
108
109 if (! broadcast ) {
110 whoami_res = bootparamproc_whoami_1(&whoami_arg, clnt);
111 printf("Whoami returning:\n");
112 if (printwhoami(whoami_res)) {
113 fprintf(stderr, "Bad answer returned from server %s\n", server);
114 exit(1);
113 errx(1, "bad answer returned from server %s", server);
115 } else
116 exit(0);
117 } else {
118 clnt_stat=clnt_broadcast(BOOTPARAMPROG, BOOTPARAMVERS,
119 BOOTPARAMPROC_WHOAMI,
120 xdr_bp_whoami_arg, &whoami_arg,
121 xdr_bp_whoami_res, &stat_whoami_res, eachres_whoami);
122 exit(0);
123 }
124
125 case 4:
126
127 getfile_arg.client_name = argv[2];
128 getfile_arg.file_id = argv[3];
129
130 if (! broadcast ) {
131 getfile_res = bootparamproc_getfile_1(&getfile_arg,clnt);
132 printf("getfile returning:\n");
133 if (printgetfile(getfile_res)) {
114 } else
115 exit(0);
116 } else {
117 clnt_stat=clnt_broadcast(BOOTPARAMPROG, BOOTPARAMVERS,
118 BOOTPARAMPROC_WHOAMI,
119 xdr_bp_whoami_arg, &whoami_arg,
120 xdr_bp_whoami_res, &stat_whoami_res, eachres_whoami);
121 exit(0);
122 }
123
124 case 4:
125
126 getfile_arg.client_name = argv[2];
127 getfile_arg.file_id = argv[3];
128
129 if (! broadcast ) {
130 getfile_res = bootparamproc_getfile_1(&getfile_arg,clnt);
131 printf("getfile returning:\n");
132 if (printgetfile(getfile_res)) {
134 fprintf(stderr, "Bad answer returned from server %s\n", server);
135 exit(1);
133 errx(1, "bad answer returned from server %s", server);
136 } else
137 exit(0);
138 } else {
139 clnt_stat=clnt_broadcast(BOOTPARAMPROG, BOOTPARAMVERS,
140 BOOTPARAMPROC_GETFILE,
141 xdr_bp_getfile_arg, &getfile_arg,
142 xdr_bp_getfile_res, &stat_getfile_res,eachres_getfile);
143 exit(0);
144 }
145
146 default:
147
134 } else
135 exit(0);
136 } else {
137 clnt_stat=clnt_broadcast(BOOTPARAMPROG, BOOTPARAMVERS,
138 BOOTPARAMPROC_GETFILE,
139 xdr_bp_getfile_arg, &getfile_arg,
140 xdr_bp_getfile_res, &stat_getfile_res,eachres_getfile);
141 exit(0);
142 }
143
144 default:
145
148 fprintf(stderr,
149 "Usage: %s server procnum (IP-addr | host fileid)\n", argv[0]);
150 exit(1);
146 usage();
151 }
152
153}
154
155
147 }
148
149}
150
151
152static void
153usage()
154{
155 fprintf(stderr,
156 "usage: callbootd server procnum (IP-addr | host fileid)\n");
157 exit(1);
158}
156
159
157int printwhoami(res)
160int
161printwhoami(res)
158bp_whoami_res *res;
159{
160 if ( res) {
161 printf("client_name:\t%s\ndomain_name:\t%s\n",
162 res->client_name, res->domain_name);
163 printf("router:\t%d.%d.%d.%d\n",
164 255 & res->router_address.bp_address_u.ip_addr.net,
165 255 & res->router_address.bp_address_u.ip_addr.host,
166 255 & res->router_address.bp_address_u.ip_addr.lh,
167 255 & res->router_address.bp_address_u.ip_addr.impno);
168 return(0);
169 } else {
162bp_whoami_res *res;
163{
164 if ( res) {
165 printf("client_name:\t%s\ndomain_name:\t%s\n",
166 res->client_name, res->domain_name);
167 printf("router:\t%d.%d.%d.%d\n",
168 255 & res->router_address.bp_address_u.ip_addr.net,
169 255 & res->router_address.bp_address_u.ip_addr.host,
170 255 & res->router_address.bp_address_u.ip_addr.lh,
171 255 & res->router_address.bp_address_u.ip_addr.impno);
172 return(0);
173 } else {
170 fprintf(stderr,"Null answer!!!\n");
174 warnx("null answer!!!");
171 return(1);
172 }
173 }
174
175
176
177
178int
179printgetfile(res)
180bp_getfile_res *res;
181{
182 if (res) {
183 printf("server_name:\t%s\nserver_address:\t%s\npath:\t%s\n",
184 res->server_name,
185 inet_ntoa(res->server_address.bp_address_u.ip_addr),
186 res->server_path);
187 return(0);
188 } else {
175 return(1);
176 }
177 }
178
179
180
181
182int
183printgetfile(res)
184bp_getfile_res *res;
185{
186 if (res) {
187 printf("server_name:\t%s\nserver_address:\t%s\npath:\t%s\n",
188 res->server_name,
189 inet_ntoa(res->server_address.bp_address_u.ip_addr),
190 res->server_path);
191 return(0);
192 } else {
189 fprintf(stderr,"Null answer!!!\n");
193 warnx("null answer!!!");
190 return(1);
191 }
192 }
194 return(1);
195 }
196 }