Deleted Added
full compact
bootptest.c (3229) bootptest.c (13572)
1/*
2 * bootptest.c - Test out a bootp server.
3 *
4 * This simple program was put together from pieces taken from
5 * various places, including the CMU BOOTP client and server.
6 * The packet printing routine is from the Berkeley "tcpdump"
7 * program with some enhancements I added. The print-bootp.c
8 * file was shared with my copy of "tcpdump" and therefore uses

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

35char *usage = "bootptest [-h] server-name [vendor-data-template-file]";
36
37#include <sys/types.h>
38#include <sys/socket.h>
39#include <sys/ioctl.h>
40#include <sys/file.h>
41#include <sys/time.h>
42#include <sys/stat.h>
1/*
2 * bootptest.c - Test out a bootp server.
3 *
4 * This simple program was put together from pieces taken from
5 * various places, including the CMU BOOTP client and server.
6 * The packet printing routine is from the Berkeley "tcpdump"
7 * program with some enhancements I added. The print-bootp.c
8 * file was shared with my copy of "tcpdump" and therefore uses

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

35char *usage = "bootptest [-h] server-name [vendor-data-template-file]";
36
37#include <sys/types.h>
38#include <sys/socket.h>
39#include <sys/ioctl.h>
40#include <sys/file.h>
41#include <sys/time.h>
42#include <sys/stat.h>
43#include <sys/utsname.h>
43
44#include <net/if.h>
45#include <netinet/in.h>
46#include <arpa/inet.h> /* inet_ntoa */
47
44
45#include <net/if.h>
46#include <netinet/in.h>
47#include <arpa/inet.h> /* inet_ntoa */
48
49#ifndef NO_UNISTD
50#include <unistd.h>
51#endif
52
48#include <stdlib.h>
49#include <signal.h>
50#include <stdio.h>
51#include <string.h>
52#include <errno.h>
53#include <ctype.h>
54#include <netdb.h>
55#include <assert.h>
56
57#include "bootp.h"
58#include "bootptest.h"
59#include "getif.h"
53#include <stdlib.h>
54#include <signal.h>
55#include <stdio.h>
56#include <string.h>
57#include <errno.h>
58#include <ctype.h>
59#include <netdb.h>
60#include <assert.h>
61
62#include "bootp.h"
63#include "bootptest.h"
64#include "getif.h"
65#include "getether.h"
66
60#include "patchlevel.h"
61
67#include "patchlevel.h"
68
69static void send_request();
70
62#define LOG_ERR 1
63#define BUFLEN 1024
64#define WAITSECS 1
65#define MAXWAIT 10
66
67int vflag = 1;
68int tflag = 0;
69int thiszone;

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

89struct sockaddr_in sin_from; /* Packet source */
90u_char eaddr[16]; /* Ethernet address */
91
92/*
93 * General
94 */
95
96int debug = 1; /* Debugging flag (level) */
71#define LOG_ERR 1
72#define BUFLEN 1024
73#define WAITSECS 1
74#define MAXWAIT 10
75
76int vflag = 1;
77int tflag = 0;
78int thiszone;

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

98struct sockaddr_in sin_from; /* Packet source */
99u_char eaddr[16]; /* Ethernet address */
100
101/*
102 * General
103 */
104
105int debug = 1; /* Debugging flag (level) */
97char hostname[64];
98char *sndbuf; /* Send packet buffer */
99char *rcvbuf; /* Receive packet buffer */
100
106char *sndbuf; /* Send packet buffer */
107char *rcvbuf; /* Receive packet buffer */
108
109struct utsname my_uname;
110char *hostname;
111
101/*
102 * Vendor magic cookies for CMU and RFC1048
103 */
104
105unsigned char vm_cmu[4] = VM_CMU;
106unsigned char vm_rfc1048[4] = VM_RFC1048;
107short secs; /* How long client has waited */
108
109char *get_errmsg();
110extern void bootp_print();
111
112/*
113 * Initialization such as command-line processing is done, then
114 * the receiver loop is started. Die when interrupted.
115 */
116
112/*
113 * Vendor magic cookies for CMU and RFC1048
114 */
115
116unsigned char vm_cmu[4] = VM_CMU;
117unsigned char vm_rfc1048[4] = VM_RFC1048;
118short secs; /* How long client has waited */
119
120char *get_errmsg();
121extern void bootp_print();
122
123/*
124 * Initialization such as command-line processing is done, then
125 * the receiver loop is started. Die when interrupted.
126 */
127
128void
117main(argc, argv)
118 int argc;
119 char **argv;
120{
121 struct bootp *bp;
122 struct servent *sep;
123 struct hostent *hep;
124
125 char *servername = NULL;
126 char *vendor_file = NULL;
127 char *bp_file = NULL;
128 int32 server_addr; /* inet addr, network order */
129 int s; /* Socket file descriptor */
129main(argc, argv)
130 int argc;
131 char **argv;
132{
133 struct bootp *bp;
134 struct servent *sep;
135 struct hostent *hep;
136
137 char *servername = NULL;
138 char *vendor_file = NULL;
139 char *bp_file = NULL;
140 int32 server_addr; /* inet addr, network order */
141 int s; /* Socket file descriptor */
130 int n, tolen, fromlen, recvcnt;
142 int n, fromlen, recvcnt;
131 int use_hwa = 0;
132 int32 vend_magic;
133 int32 xid;
134
135 progname = strrchr(argv[0], '/');
136 if (progname)
137 progname++;
138 else

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

144 printf("%s: version %s.%d\n", progname, VERSION, PATCHLEVEL);
145
146 /*
147 * Verify that "struct bootp" has the correct official size.
148 * (Catch evil compilers that do struct padding.)
149 */
150 assert(sizeof(struct bootp) == BP_MINPKTSZ);
151
143 int use_hwa = 0;
144 int32 vend_magic;
145 int32 xid;
146
147 progname = strrchr(argv[0], '/');
148 if (progname)
149 progname++;
150 else

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

156 printf("%s: version %s.%d\n", progname, VERSION, PATCHLEVEL);
157
158 /*
159 * Verify that "struct bootp" has the correct official size.
160 * (Catch evil compilers that do struct padding.)
161 */
162 assert(sizeof(struct bootp) == BP_MINPKTSZ);
163
164 if (uname(&my_uname) < 0) {
165 fprintf(stderr, "%s: can't get hostname\n", argv[0]);
166 exit(1);
167 }
168 hostname = my_uname.nodename;
169
152 sndbuf = malloc(BUFLEN);
153 rcvbuf = malloc(BUFLEN);
154 if (!sndbuf || !rcvbuf) {
155 printf("malloc failed\n");
156 exit(1);
157 }
158
159 /* default magic number */

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

297 if (use_hwa) {
298 struct ifreq *ifr;
299
300 ifr = getif(s, &sin_server.sin_addr);
301 if (!ifr) {
302 printf("No interface for %s\n", servername);
303 exit(1);
304 }
170 sndbuf = malloc(BUFLEN);
171 rcvbuf = malloc(BUFLEN);
172 if (!sndbuf || !rcvbuf) {
173 printf("malloc failed\n");
174 exit(1);
175 }
176
177 /* default magic number */

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

315 if (use_hwa) {
316 struct ifreq *ifr;
317
318 ifr = getif(s, &sin_server.sin_addr);
319 if (!ifr) {
320 printf("No interface for %s\n", servername);
321 exit(1);
322 }
305 if (getether(ifr->ifr_name, eaddr)) {
323 if (getether(ifr->ifr_name, (char*)eaddr)) {
306 printf("Can not get ether addr for %s\n", ifr->ifr_name);
307 exit(1);
308 }
309 /* Copy Ethernet address into request packet. */
310 bp->bp_htype = 1;
311 bp->bp_hlen = 6;
312 bcopy(eaddr, bp->bp_chaddr, bp->bp_hlen);
313 } else {
314 /* Fill in the client IP address. */
324 printf("Can not get ether addr for %s\n", ifr->ifr_name);
325 exit(1);
326 }
327 /* Copy Ethernet address into request packet. */
328 bp->bp_htype = 1;
329 bp->bp_hlen = 6;
330 bcopy(eaddr, bp->bp_chaddr, bp->bp_hlen);
331 } else {
332 /* Fill in the client IP address. */
315 gethostname(hostname, sizeof(hostname));
316 hep = gethostbyname(hostname);
317 if (!hep) {
318 printf("Can not get my IP address\n");
319 exit(1);
320 }
321 bcopy(hep->h_addr, &bp->bp_ciaddr, hep->h_length);
322 }
323

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

417 * client might get multiple responses. This code
418 * will now listen for one second after a response.
419 */
420 }
421 fprintf(stderr, "no response from %s\n", servername);
422 exit(1);
423}
424
333 hep = gethostbyname(hostname);
334 if (!hep) {
335 printf("Can not get my IP address\n");
336 exit(1);
337 }
338 bcopy(hep->h_addr, &bp->bp_ciaddr, hep->h_length);
339 }
340

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

434 * client might get multiple responses. This code
435 * will now listen for one second after a response.
436 */
437 }
438 fprintf(stderr, "no response from %s\n", servername);
439 exit(1);
440}
441
442static void
425send_request(s)
426 int s;
427{
428 /* Print the request packet. */
429 printf("Sending to %s", inet_ntoa(sin_server.sin_addr));
430 bootp_print(sndbuf, snaplen, sin_from.sin_port, 0);
431 putchar('\n');
432

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

446 */
447int
448printfn(s, ep)
449 register u_char *s, *ep;
450{
451 register u_char c;
452
453 putchar('"');
443send_request(s)
444 int s;
445{
446 /* Print the request packet. */
447 printf("Sending to %s", inet_ntoa(sin_server.sin_addr));
448 bootp_print(sndbuf, snaplen, sin_from.sin_port, 0);
449 putchar('\n');
450

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

464 */
465int
466printfn(s, ep)
467 register u_char *s, *ep;
468{
469 register u_char c;
470
471 putchar('"');
454 while (c = *s++) {
472 while ((c = *s++) != '\0') {
455 if (s > ep) {
456 putchar('"');
457 return (1);
458 }
459 if (!isascii(c)) {
460 c = toascii(c);
461 putchar('M');
462 putchar('-');

--- 38 unchanged lines hidden ---
473 if (s > ep) {
474 putchar('"');
475 return (1);
476 }
477 if (!isascii(c)) {
478 c = toascii(c);
479 putchar('M');
480 putchar('-');

--- 38 unchanged lines hidden ---