Lines 57-62
Link Here
|
57 |
#include <unistd.h> |
57 |
#include <unistd.h> |
58 |
|
58 |
|
59 |
#define HOST_WIDTH 15 |
59 |
#define HOST_WIDTH 15 |
|
|
60 |
#define MAXBUF 512 |
60 |
|
61 |
|
61 |
struct host_list { |
62 |
struct host_list { |
62 |
struct host_list *next; |
63 |
struct host_list *next; |
Lines 107-113
Link Here
|
107 |
|
108 |
|
108 |
hp = gethostbyaddr((char *)&raddrp->sin_addr.s_addr, |
109 |
hp = gethostbyaddr((char *)&raddrp->sin_addr.s_addr, |
109 |
sizeof(struct in_addr), AF_INET); |
110 |
sizeof(struct in_addr), AF_INET); |
110 |
if (hp) |
111 |
if (hp == NULL) |
111 |
host = hp->h_name; |
112 |
host = hp->h_name; |
112 |
else |
113 |
else |
113 |
host = inet_ntoa(raddrp->sin_addr); |
114 |
host = inet_ntoa(raddrp->sin_addr); |
Lines 220-240
Link Here
|
220 |
int |
221 |
int |
221 |
main(int argc, char *argv[]) |
222 |
main(int argc, char *argv[]) |
222 |
{ |
223 |
{ |
223 |
int ch; |
224 |
int ch, f_flag = 0, i = 0; |
224 |
|
225 |
FILE *fd; |
225 |
while ((ch = getopt(argc, argv, "?")) != -1) |
226 |
char file_buf[MAXBUF], *host; |
226 |
switch (ch) { |
227 |
|
227 |
default: |
228 |
while ((ch = getopt(argc, argv, "f:")) != -1) |
228 |
usage(); |
229 |
switch (ch) { |
229 |
/*NOTREACHED*/ |
230 |
case 'f': |
230 |
} |
231 |
f_flag = 1; |
231 |
|
232 |
break; |
232 |
setlinebuf(stdout); |
233 |
default: |
233 |
if (argc == optind) |
234 |
usage(); |
234 |
allhosts(); |
235 |
/* NOTREACHED */ |
235 |
else { |
236 |
} |
236 |
for (; optind < argc; optind++) |
237 |
|
237 |
(void) onehost(argv[optind]); |
238 |
if (!f_flag) { |
238 |
} |
239 |
setlinebuf(stdout); |
239 |
exit(0); |
240 |
if (argc == optind) { |
|
|
241 |
allhosts(); |
242 |
} else { |
243 |
for (; optind < argc; optind++) |
244 |
onehost(argv[optind]); |
245 |
} |
246 |
} else { |
247 |
if ((fd = fopen(optarg, "r")) == NULL) |
248 |
err(1, "%s", optarg); |
249 |
|
250 |
while (!feof(fd)) { |
251 |
if (fgets(file_buf, sizeof(file_buf), fd) != NULL) { |
252 |
if ((host = malloc(sizeof(file_buf))) == NULL) |
253 |
err(1, NULL); |
254 |
bzero(host, sizeof(file_buf)); |
255 |
if (!ferror(fd)) { |
256 |
for (i = 0; i < (int)sizeof(file_buf); i++) { |
257 |
if (file_buf[i] == '#' || file_buf[i] == '\n' || file_buf[i] == ' ') |
258 |
break; |
259 |
|
260 |
host[i] = file_buf[i]; |
261 |
} |
262 |
onehost(host); |
263 |
} else { |
264 |
err(1, NULL); |
265 |
} |
266 |
free(host); |
267 |
} |
268 |
} |
269 |
fclose(fd); |
270 |
} |
271 |
return 0; |
240 |
} |
272 |
} |