Skip to content

Commit 8641b10

Browse files
committed
Fix defaulting the options.
1 parent b036bde commit 8641b10

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

apps/telnet.c

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,11 @@ static void telnet_client (int host, int sock,
385385
}
386386
}
387387

388-
static void telnet_server (int sock, void (*process) (unsigned char, int, int),
388+
static void telnet_server (int host, int sock,
389+
void (*process) (unsigned char, int, int),
389390
const unsigned char *options)
390391
{
391-
int host, connection, size;
392+
int connection, size;
392393
int reader_fd, writer_fd;
393394
char *banner;
394395

@@ -471,10 +472,14 @@ static void usage (const char *argv0, int code)
471472

472473
int main (int argc, char **argv)
473474
{
475+
void (*telnet) (int, int,
476+
void (*) (unsigned char, int, int),
477+
const unsigned char *) = NULL;
474478
void (*process) (unsigned char, int, int) = NULL;
475479
const unsigned char *client_options;
476480
const unsigned char *server_options;
477-
int opt, client = 1, server = 0;
481+
const unsigned char *options;
482+
int opt;
478483
int host = -1;
479484
int sock = -1;
480485

@@ -488,8 +493,9 @@ int main (int argc, char **argv)
488493
server_options = bin_options;
489494
break;
490495
case 'c':
491-
client = 1;
492-
server = 0;
496+
if (telnet != NULL)
497+
usage (argv[0], 1);
498+
telnet = telnet_client;
493499
break;
494500
case 'n':
495501
if (process != NULL)
@@ -513,25 +519,32 @@ int main (int argc, char **argv)
513519
sock = atoi (optarg);
514520
break;
515521
case 's':
516-
client = 0;
517-
server = 1;
522+
if (telnet != NULL)
523+
usage (argv[0], 1);
524+
telnet = telnet_server;
518525
break;
519526
default:
520527
usage (argv[0], 1);
521528
}
522529
}
523530

524-
if (client)
531+
if (telnet == telnet_client)
525532
host = atoi (argv[optind++]);
526533

527-
if (argc != optind || (client && server))
534+
if (argc != optind)
528535
usage(argv[0], 1);
529536

537+
/* These are the defaults. */
530538
if (sock == -1)
531539
sock = NEW_TELNET;
532-
533540
if (process == NULL)
534541
process = process_new;
542+
if (telnet == NULL)
543+
telnet = telnet_client;
544+
if (client_options == NULL)
545+
client_options = new_client_options;
546+
if (server_options == NULL)
547+
server_options = new_server_options;
535548

536549
if (ncp_init (NULL) == -1) {
537550
fprintf (stderr, "NCP initialization error: %s.\n", strerror (errno));
@@ -540,10 +553,11 @@ int main (int argc, char **argv)
540553
exit (1);
541554
}
542555

543-
if (client)
544-
telnet_client (host, sock, process, client_options);
545-
else if (server)
546-
telnet_server (sock, process, server_options);
556+
if (telnet == telnet_client)
557+
options = client_options;
558+
else
559+
options = server_options;
560+
telnet (host, sock, process, options);
547561

548562
return 0;
549563
}

0 commit comments

Comments
 (0)