blob: 5cd368e93346c28ccfc1d8cd53670e8d8d95c0e1 [file] [log] [blame]
Ben Lindstromb6434ae2000-12-05 01:15:09 +00001/*
2 * Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>.
3 *
4 * Modification and redistribution in source and binary forms is
5 * permitted provided that due credit is given to the author and the
6 * OpenBSD project (for instance by leaving this copyright notice
7 * intact).
8 */
9
10#include "includes.h"
Ben Lindstromf9452512001-02-15 03:12:08 +000011RCSID("$OpenBSD: ssh-keyscan.c,v 1.16 2001/02/12 22:56:10 deraadt Exp $");
Ben Lindstromb6434ae2000-12-05 01:15:09 +000012
Kevin Steves28a7f262001-02-05 15:43:59 +000013#if defined(HAVE_SYS_QUEUE_H) && !defined(HAVE_BOGUS_SYS_QUEUE_H)
Ben Lindstromb6434ae2000-12-05 01:15:09 +000014#include <sys/queue.h>
Kevin Steves2c65ada2000-12-06 22:25:40 +000015#else
Ben Lindstrom64136352001-02-02 19:03:13 +000016#include "fake-queue.h"
Kevin Steves2c65ada2000-12-06 22:25:40 +000017#endif
Ben Lindstromb6434ae2000-12-05 01:15:09 +000018#include <errno.h>
19
20#include <openssl/bn.h>
Ben Lindstromb6434ae2000-12-05 01:15:09 +000021
22#include "xmalloc.h"
23#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000024#include "ssh1.h"
Ben Lindstromb6434ae2000-12-05 01:15:09 +000025#include "key.h"
26#include "buffer.h"
27#include "bufaux.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000028#include "log.h"
Ben Lindstromb6434ae2000-12-05 01:15:09 +000029
30static int argno = 1; /* Number of argument currently being parsed */
31
32int family = AF_UNSPEC; /* IPv4, IPv6 or both */
33
Ben Lindstromb6434ae2000-12-05 01:15:09 +000034#define MAXMAXFD 256
35
36/* The number of seconds after which to give up on a TCP connection */
37int timeout = 5;
38
39int maxfd;
40#define maxcon (maxfd - 10)
41
Kevin Stevesec84dc12000-12-13 17:45:15 +000042#ifdef HAVE___PROGNAME
43extern char *__progname;
44#else
45char *__progname;
46#endif
Ben Lindstromb6434ae2000-12-05 01:15:09 +000047fd_set read_wait;
48int ncon;
49
50/*
51 * Keep a connection structure for each file descriptor. The state
52 * associated with file descriptor n is held in fdcon[n].
53 */
54typedef struct Connection {
Ben Lindstrom46c16222000-12-22 01:43:59 +000055 u_char c_status; /* State of connection on this file desc. */
Ben Lindstromb6434ae2000-12-05 01:15:09 +000056#define CS_UNUSED 0 /* File descriptor unused */
57#define CS_CON 1 /* Waiting to connect/read greeting */
58#define CS_SIZE 2 /* Waiting to read initial packet size */
59#define CS_KEYS 3 /* Waiting to read public key packet */
60 int c_fd; /* Quick lookup: c->c_fd == c - fdcon */
61 int c_plen; /* Packet length field for ssh packet */
62 int c_len; /* Total bytes which must be read. */
63 int c_off; /* Length of data read so far. */
64 char *c_namebase; /* Address to free for c_name and c_namelist */
65 char *c_name; /* Hostname of connection for errors */
66 char *c_namelist; /* Pointer to other possible addresses */
67 char *c_output_name; /* Hostname of connection for output */
68 char *c_data; /* Data read from this fd */
69 struct timeval c_tv; /* Time at which connection gets aborted */
70 TAILQ_ENTRY(Connection) c_link; /* List of connections in timeout order. */
71} con;
72
73TAILQ_HEAD(conlist, Connection) tq; /* Timeout Queue */
74con *fdcon;
75
76/*
77 * This is just a wrapper around fgets() to make it usable.
78 */
79
80/* Stress-test. Increase this later. */
81#define LINEBUF_SIZE 16
82
83typedef struct {
84 char *buf;
Ben Lindstrom46c16222000-12-22 01:43:59 +000085 u_int size;
Ben Lindstromb6434ae2000-12-05 01:15:09 +000086 int lineno;
87 const char *filename;
88 FILE *stream;
89 void (*errfun) (const char *,...);
90} Linebuf;
91
92static inline Linebuf *
93Linebuf_alloc(const char *filename, void (*errfun) (const char *,...))
94{
95 Linebuf *lb;
96
97 if (!(lb = malloc(sizeof(*lb)))) {
98 if (errfun)
99 (*errfun) ("linebuf (%s): malloc failed\n", lb->filename);
100 return (NULL);
101 }
102 if (filename) {
103 lb->filename = filename;
104 if (!(lb->stream = fopen(filename, "r"))) {
Ben Lindstrombf555ba2001-01-18 02:04:35 +0000105 xfree(lb);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000106 if (errfun)
107 (*errfun) ("%s: %s\n", filename, strerror(errno));
108 return (NULL);
109 }
110 } else {
111 lb->filename = "(stdin)";
112 lb->stream = stdin;
113 }
114
115 if (!(lb->buf = malloc(lb->size = LINEBUF_SIZE))) {
116 if (errfun)
117 (*errfun) ("linebuf (%s): malloc failed\n", lb->filename);
Ben Lindstrombf555ba2001-01-18 02:04:35 +0000118 xfree(lb);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000119 return (NULL);
120 }
121 lb->errfun = errfun;
122 lb->lineno = 0;
123 return (lb);
124}
125
126static inline void
127Linebuf_free(Linebuf * lb)
128{
129 fclose(lb->stream);
Ben Lindstrombf555ba2001-01-18 02:04:35 +0000130 xfree(lb->buf);
131 xfree(lb);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000132}
133
134static inline void
135Linebuf_restart(Linebuf * lb)
136{
137 clearerr(lb->stream);
138 rewind(lb->stream);
139 lb->lineno = 0;
140}
141
142static inline int
143Linebuf_lineno(Linebuf * lb)
144{
145 return (lb->lineno);
146}
147
148static inline char *
Ben Lindstromc791beb2001-02-10 23:18:11 +0000149Linebuf_getline(Linebuf * lb)
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000150{
151 int n = 0;
152
153 lb->lineno++;
154 for (;;) {
155 /* Read a line */
156 if (!fgets(&lb->buf[n], lb->size - n, lb->stream)) {
157 if (ferror(lb->stream) && lb->errfun)
158 (*lb->errfun) ("%s: %s\n", lb->filename, strerror(errno));
159 return (NULL);
160 }
161 n = strlen(lb->buf);
162
163 /* Return it or an error if it fits */
164 if (n > 0 && lb->buf[n - 1] == '\n') {
165 lb->buf[n - 1] = '\0';
166 return (lb->buf);
167 }
168 if (n != lb->size - 1) {
169 if (lb->errfun)
170 (*lb->errfun) ("%s: skipping incomplete last line\n", lb->filename);
171 return (NULL);
172 }
173 /* Double the buffer if we need more space */
174 if (!(lb->buf = realloc(lb->buf, (lb->size *= 2)))) {
175 if (lb->errfun)
176 (*lb->errfun) ("linebuf (%s): realloc failed\n", lb->filename);
177 return (NULL);
178 }
179 }
180}
181
182static int
183fdlim_get(int hard)
184{
Ben Lindstrom5adbad22000-12-27 07:06:21 +0000185#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000186 struct rlimit rlfd;
187 if (getrlimit(RLIMIT_NOFILE, &rlfd) < 0)
188 return (-1);
189 if ((hard ? rlfd.rlim_max : rlfd.rlim_cur) == RLIM_INFINITY)
190 return 10000;
191 else
192 return hard ? rlfd.rlim_max : rlfd.rlim_cur;
Ben Lindstrom2c467a22000-12-27 04:57:41 +0000193#elif defined (HAVE_SYSCONF)
194 return sysconf (_SC_OPEN_MAX);
195#else
196 return 10000;
197#endif
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000198}
199
200static int
201fdlim_set(int lim)
202{
Ben Lindstrom5adbad22000-12-27 07:06:21 +0000203#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000204 struct rlimit rlfd;
Ben Lindstrom2c467a22000-12-27 04:57:41 +0000205#endif
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000206 if (lim <= 0)
207 return (-1);
Ben Lindstrom5adbad22000-12-27 07:06:21 +0000208#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000209 if (getrlimit(RLIMIT_NOFILE, &rlfd) < 0)
210 return (-1);
211 rlfd.rlim_cur = lim;
212 if (setrlimit(RLIMIT_NOFILE, &rlfd) < 0)
213 return (-1);
Ben Lindstrom2c467a22000-12-27 04:57:41 +0000214#elif defined (HAVE_SETDTABLESIZE)
Kevin Steves28a7f262001-02-05 15:43:59 +0000215 setdtablesize(lim);
Ben Lindstrom2c467a22000-12-27 04:57:41 +0000216#endif
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000217 return (0);
218}
219
220/*
221 * This is an strsep function that returns a null field for adjacent
222 * separators. This is the same as the 4.4BSD strsep, but different from the
223 * one in the GNU libc.
224 */
225inline char *
226xstrsep(char **str, const char *delim)
227{
228 char *s, *e;
229
230 if (!**str)
231 return (NULL);
232
233 s = *str;
234 e = s + strcspn(s, delim);
235
236 if (*e != '\0')
237 *e++ = '\0';
238 *str = e;
239
240 return (s);
241}
242
243/*
244 * Get the next non-null token (like GNU strsep). Strsep() will return a
245 * null token for two adjacent separators, so we may have to loop.
246 */
247char *
248strnnsep(char **stringp, char *delim)
249{
250 char *tok;
251
252 do {
253 tok = xstrsep(stringp, delim);
254 } while (tok && *tok == '\0');
255 return (tok);
256}
257
258void
259keyprint(char *host, char *output_name, char *kd, int len)
260{
261 static Key *rsa;
262 static Buffer msg;
263
264 if (rsa == NULL) {
265 buffer_init(&msg);
266 rsa = key_new(KEY_RSA1);
267 }
268 buffer_append(&msg, kd, len);
269 buffer_consume(&msg, 8 - (len & 7)); /* padding */
270 if (buffer_get_char(&msg) != (int) SSH_SMSG_PUBLIC_KEY) {
271 error("%s: invalid packet type", host);
272 buffer_clear(&msg);
273 return;
274 }
275 buffer_consume(&msg, 8); /* cookie */
276
277 /* server key */
278 (void) buffer_get_int(&msg);
279 buffer_get_bignum(&msg, rsa->rsa->e);
280 buffer_get_bignum(&msg, rsa->rsa->n);
281
282 /* host key */
283 (void) buffer_get_int(&msg);
284 buffer_get_bignum(&msg, rsa->rsa->e);
285 buffer_get_bignum(&msg, rsa->rsa->n);
286 buffer_clear(&msg);
287
288 fprintf(stdout, "%s ", output_name ? output_name : host);
289 key_write(rsa, stdout);
290 fputs("\n", stdout);
291}
292
293int
294tcpconnect(char *host)
295{
296 struct addrinfo hints, *ai, *aitop;
297 char strport[NI_MAXSERV];
298 int gaierr, s = -1;
299
Ben Lindstrombf555ba2001-01-18 02:04:35 +0000300 snprintf(strport, sizeof strport, "%d", SSH_DEFAULT_PORT);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000301 memset(&hints, 0, sizeof(hints));
302 hints.ai_family = family;
303 hints.ai_socktype = SOCK_STREAM;
304 if ((gaierr = getaddrinfo(host, strport, &hints, &aitop)) != 0)
305 fatal("getaddrinfo %s: %s", host, gai_strerror(gaierr));
306 for (ai = aitop; ai; ai = ai->ai_next) {
307 s = socket(ai->ai_family, SOCK_STREAM, 0);
308 if (s < 0) {
309 error("socket: %s", strerror(errno));
310 continue;
311 }
Ben Lindstrom48bd7c12001-01-09 00:35:42 +0000312 if (fcntl(s, F_SETFL, O_NONBLOCK) < 0)
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000313 fatal("F_SETFL: %s", strerror(errno));
314 if (connect(s, ai->ai_addr, ai->ai_addrlen) < 0 &&
315 errno != EINPROGRESS)
316 error("connect (`%s'): %s", host, strerror(errno));
317 else
318 break;
319 close(s);
320 s = -1;
321 }
322 freeaddrinfo(aitop);
323 return s;
324}
325
326int
327conalloc(char *iname, char *oname)
328{
329 int s;
330 char *namebase, *name, *namelist;
331
332 namebase = namelist = xstrdup(iname);
333
334 do {
335 name = xstrsep(&namelist, ",");
336 if (!name) {
Ben Lindstrombf555ba2001-01-18 02:04:35 +0000337 xfree(namebase);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000338 return (-1);
339 }
340 } while ((s = tcpconnect(name)) < 0);
341
342 if (s >= maxfd)
Kevin Stevesfa72dda2000-12-15 18:39:12 +0000343 fatal("conalloc: fdno %d too high", s);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000344 if (fdcon[s].c_status)
Kevin Stevesfa72dda2000-12-15 18:39:12 +0000345 fatal("conalloc: attempt to reuse fdno %d", s);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000346
347 fdcon[s].c_fd = s;
348 fdcon[s].c_status = CS_CON;
349 fdcon[s].c_namebase = namebase;
350 fdcon[s].c_name = name;
351 fdcon[s].c_namelist = namelist;
352 fdcon[s].c_output_name = xstrdup(oname);
353 fdcon[s].c_data = (char *) &fdcon[s].c_plen;
354 fdcon[s].c_len = 4;
355 fdcon[s].c_off = 0;
356 gettimeofday(&fdcon[s].c_tv, NULL);
357 fdcon[s].c_tv.tv_sec += timeout;
358 TAILQ_INSERT_TAIL(&tq, &fdcon[s], c_link);
359 FD_SET(s, &read_wait);
360 ncon++;
361 return (s);
362}
363
364void
365confree(int s)
366{
367 close(s);
368 if (s >= maxfd || fdcon[s].c_status == CS_UNUSED)
Kevin Stevesfa72dda2000-12-15 18:39:12 +0000369 fatal("confree: attempt to free bad fdno %d", s);
Ben Lindstrombf555ba2001-01-18 02:04:35 +0000370 xfree(fdcon[s].c_namebase);
371 xfree(fdcon[s].c_output_name);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000372 if (fdcon[s].c_status == CS_KEYS)
Ben Lindstrombf555ba2001-01-18 02:04:35 +0000373 xfree(fdcon[s].c_data);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000374 fdcon[s].c_status = CS_UNUSED;
375 TAILQ_REMOVE(&tq, &fdcon[s], c_link);
376 FD_CLR(s, &read_wait);
377 ncon--;
378}
379
380void
381contouch(int s)
382{
383 TAILQ_REMOVE(&tq, &fdcon[s], c_link);
384 gettimeofday(&fdcon[s].c_tv, NULL);
385 fdcon[s].c_tv.tv_sec += timeout;
386 TAILQ_INSERT_TAIL(&tq, &fdcon[s], c_link);
387}
388
389int
390conrecycle(int s)
391{
392 int ret;
393 con *c = &fdcon[s];
394 char *iname, *oname;
395
396 iname = xstrdup(c->c_namelist);
Ben Lindstrombf555ba2001-01-18 02:04:35 +0000397 oname = xstrdup(c->c_output_name);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000398 confree(s);
399 ret = conalloc(iname, oname);
Ben Lindstrombf555ba2001-01-18 02:04:35 +0000400 xfree(iname);
401 xfree(oname);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000402 return (ret);
403}
404
405void
406congreet(int s)
407{
408 char buf[80];
409 int n;
410 con *c = &fdcon[s];
411
412 n = read(s, buf, sizeof(buf));
413 if (n < 0) {
414 if (errno != ECONNREFUSED)
415 error("read (%s): %s", c->c_name, strerror(errno));
416 conrecycle(s);
417 return;
418 }
419 if (buf[n - 1] != '\n') {
420 error("%s: bad greeting", c->c_name);
421 confree(s);
422 return;
423 }
424 buf[n - 1] = '\0';
425 fprintf(stderr, "# %s %s\n", c->c_name, buf);
426 n = snprintf(buf, sizeof buf, "SSH-1.5-OpenSSH-keyscan\r\n");
427 if (write(s, buf, n) != n) {
428 error("write (%s): %s", c->c_name, strerror(errno));
429 confree(s);
430 return;
431 }
432 c->c_status = CS_SIZE;
433 contouch(s);
434}
435
436void
437conread(int s)
438{
439 int n;
440 con *c = &fdcon[s];
441
442 if (c->c_status == CS_CON) {
443 congreet(s);
444 return;
445 }
446 n = read(s, c->c_data + c->c_off, c->c_len - c->c_off);
447 if (n < 0) {
448 error("read (%s): %s", c->c_name, strerror(errno));
449 confree(s);
450 return;
451 }
452 c->c_off += n;
453
454 if (c->c_off == c->c_len)
455 switch (c->c_status) {
456 case CS_SIZE:
457 c->c_plen = htonl(c->c_plen);
458 c->c_len = c->c_plen + 8 - (c->c_plen & 7);
459 c->c_off = 0;
460 c->c_data = xmalloc(c->c_len);
461 c->c_status = CS_KEYS;
462 break;
463 case CS_KEYS:
464 keyprint(c->c_name, c->c_output_name, c->c_data, c->c_plen);
465 confree(s);
466 return;
467 break;
468 default:
Kevin Stevesfa72dda2000-12-15 18:39:12 +0000469 fatal("conread: invalid status %d", c->c_status);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000470 break;
471 }
472
473 contouch(s);
474}
475
476void
477conloop(void)
478{
479 fd_set r, e;
480 struct timeval seltime, now;
481 int i;
482 con *c;
483
484 gettimeofday(&now, NULL);
485 c = tq.tqh_first;
486
487 if (c &&
488 (c->c_tv.tv_sec > now.tv_sec ||
489 (c->c_tv.tv_sec == now.tv_sec && c->c_tv.tv_usec > now.tv_usec))) {
490 seltime = c->c_tv;
491 seltime.tv_sec -= now.tv_sec;
492 seltime.tv_usec -= now.tv_usec;
Ben Lindstromc791beb2001-02-10 23:18:11 +0000493 if (seltime.tv_usec < 0) {
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000494 seltime.tv_usec += 1000000;
495 seltime.tv_sec--;
496 }
497 } else
498 seltime.tv_sec = seltime.tv_usec = 0;
499
500 r = e = read_wait;
Ben Lindstromf9452512001-02-15 03:12:08 +0000501 while (select(maxfd, &r, NULL, &e, &seltime) == -1 &&
502 (errno == EAGAIN || errno == EINTR))
503 ;
504
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000505 for (i = 0; i < maxfd; i++)
506 if (FD_ISSET(i, &e)) {
507 error("%s: exception!", fdcon[i].c_name);
508 confree(i);
509 } else if (FD_ISSET(i, &r))
510 conread(i);
511
512 c = tq.tqh_first;
513 while (c &&
514 (c->c_tv.tv_sec < now.tv_sec ||
Kevin Stevesef4eea92001-02-05 12:42:17 +0000515 (c->c_tv.tv_sec == now.tv_sec && c->c_tv.tv_usec < now.tv_usec))) {
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000516 int s = c->c_fd;
517 c = c->c_link.tqe_next;
518 conrecycle(s);
519 }
520}
521
522char *
523nexthost(int argc, char **argv)
524{
525 static Linebuf *lb;
526
527 for (;;) {
528 if (!lb) {
529 if (argno >= argc)
530 return (NULL);
531 if (argv[argno][0] != '-')
532 return (argv[argno++]);
533 if (!strcmp(argv[argno], "--")) {
534 if (++argno >= argc)
535 return (NULL);
536 return (argv[argno++]);
537 } else if (!strncmp(argv[argno], "-f", 2)) {
538 char *fname;
539 if (argv[argno][2])
540 fname = &argv[argno++][2];
541 else if (++argno >= argc) {
542 error("missing filename for `-f'");
543 return (NULL);
544 } else
545 fname = argv[argno++];
546 if (!strcmp(fname, "-"))
547 fname = NULL;
Kevin Stevesfc74af42000-12-06 22:47:55 +0000548 lb = Linebuf_alloc(fname, error);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000549 } else
550 error("ignoring invalid/misplaced option `%s'", argv[argno++]);
551 } else {
552 char *line;
Ben Lindstromc791beb2001-02-10 23:18:11 +0000553 line = Linebuf_getline(lb);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000554 if (line)
555 return (line);
556 Linebuf_free(lb);
557 lb = NULL;
558 }
559 }
560}
561
562static void
563usage(void)
564{
Kevin Stevesfa72dda2000-12-15 18:39:12 +0000565 fatal("usage: %s [-t timeout] { [--] host | -f file } ...", __progname);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000566 return;
567}
568
569int
570main(int argc, char **argv)
571{
572 char *host = NULL;
573
Kevin Stevesec84dc12000-12-13 17:45:15 +0000574 __progname = get_progname(argv[0]);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000575 TAILQ_INIT(&tq);
576
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000577 if (argc <= argno)
578 usage();
579
580 if (argv[1][0] == '-' && argv[1][1] == 't') {
581 argno++;
582 if (argv[1][2])
583 timeout = atoi(&argv[1][2]);
584 else {
585 if (argno >= argc)
586 usage();
587 timeout = atoi(argv[argno++]);
588 }
589 if (timeout <= 0)
590 usage();
591 }
592 if (argc <= argno)
593 usage();
594
595 maxfd = fdlim_get(1);
596 if (maxfd < 0)
Kevin Stevesfa72dda2000-12-15 18:39:12 +0000597 fatal("%s: fdlim_get: bad value", __progname);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000598 if (maxfd > MAXMAXFD)
599 maxfd = MAXMAXFD;
600 if (maxcon <= 0)
Kevin Stevesfa72dda2000-12-15 18:39:12 +0000601 fatal("%s: not enough file descriptors", __progname);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000602 if (maxfd > fdlim_get(0))
603 fdlim_set(maxfd);
604 fdcon = xmalloc(maxfd * sizeof(con));
Ben Lindstromc791beb2001-02-10 23:18:11 +0000605 memset(fdcon, 0, maxfd * sizeof(con));
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000606
607 do {
608 while (ncon < maxcon) {
609 char *name;
610
611 host = nexthost(argc, argv);
612 if (host == NULL)
613 break;
614 name = strnnsep(&host, " \t\n");
615 conalloc(name, *host ? host : name);
616 }
617 conloop();
618 } while (host);
619 while (ncon > 0)
620 conloop();
621
622 return (0);
623}