From 98204bad94448c12fda8f5022a532cb8524d541d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 27 Jun 2017 07:46:16 -0600 Subject: [PATCH] system/telnet: POLL must not be disabled in configuration. Telnet client port argument is no optional. --- nshlib/nsh_telnetd.c | 2 +- system/telnet/Kconfig | 4 +-- system/telnet/telnet_chatd.c | 10 +++++++- system/telnet/telnet_client.c | 48 +++++++++++++++++++++++++++++------ 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/nshlib/nsh_telnetd.c b/nshlib/nsh_telnetd.c index 18722d8db..2f290a204 100644 --- a/nshlib/nsh_telnetd.c +++ b/nshlib/nsh_telnetd.c @@ -229,7 +229,7 @@ int nsh_telnetstart(void) if (ret < 0) { _err("ERROR: Failed to tart the Telnet daemon: %d\n", ret); - state = TELNETD_NOTRUNNING; + state = TELNETD_NOTRUNNING; } else { diff --git a/system/telnet/Kconfig b/system/telnet/Kconfig index 51cb9f72e..7cc99de39 100644 --- a/system/telnet/Kconfig +++ b/system/telnet/Kconfig @@ -6,7 +6,7 @@ menuconfig SYSTEM_TELNET_CHATD bool "Telnet chat deamon" default n - depends on NET && NET_TCP + depends on NET && NET_TCP && !DISABLE_POLL select NETUTILS_TELNETC ---help--- Enable the Telnet Chat daemon. @@ -34,7 +34,7 @@ endif # SYSTEM_TELNET_CHATD menuconfig SYSTEM_TELNET_CLIENT bool "Telnet client" default n - depends on NET && NET_TCP + depends on NET && NET_TCP && !DISABLE_POLL select NETUTILS_TELNETC select SYSTEM_READLINE ---help--- diff --git a/system/telnet/telnet_chatd.c b/system/telnet/telnet_chatd.c index e7a560b87..423724a79 100644 --- a/system/telnet/telnet_chatd.c +++ b/system/telnet/telnet_chatd.c @@ -317,7 +317,15 @@ static void _event_handler(struct telnet_s *telnet, } } -int main(int argc, char **argv) +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int chatd_main(int argc, char *argv[]) +#endif { char buffer[512]; short listen_port; diff --git a/system/telnet/telnet_client.c b/system/telnet/telnet_client.c index 3e469fc25..41f41791b 100644 --- a/system/telnet/telnet_client.c +++ b/system/telnet/telnet_client.c @@ -74,6 +74,16 @@ #include "system/readline.h" #include "netutils/telnetc.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_NSH_TELNETD_PORT +# define DEFAULT_PORT CONFIG_NSH_TELNETD_PORT +#else +# define DEFAULT_PORT 23 +#endif + /**************************************************************************** * Private Data ****************************************************************************/ @@ -246,11 +256,26 @@ static void _event_handler(struct telnet_s *telnet, static void show_usage(const char *progname, int exitcode) { - fprintf(stderr, "Usage:\n %s \n", progname); + fprintf(stderr, "Usage:\n"); + fprintf(stderr, "\t%s []\n", progname); + fprintf(stderr, "Where:\n"); + fprintf(stderr, "\t is the address of the Telnet server. Either\n"); + fprintf(stderr, "\t\tIPv4 form: ddd.ddd.ddd.ddd\n"); + fprintf(stderr, "\t\tIPv6 form: xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx\n"); + fprintf(stderr, "\t is the (optional) listening port of the Telnet server.\n"); + fprintf(stderr, "\t\tDefault: %u\n", DEFAULT_PORT); exit(exitcode) ; } -int main(int argc, char **argv) +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int telnet_main(int argc, char *argv[]) +#endif { char buffer[512]; union @@ -281,19 +306,26 @@ int main(int argc, char **argv) /* Check usage */ - if (argc != 3) + if (argc < 2 || argc > 3) { fprintf(stderr, "Invalid number of arguments\n"); show_usage(argv[0], 1); } - /* Convert the port number to binary */ + /* Convert the port number to binary if provided */ - portno = atoi(argv[2]); - if (portno < 0 || portno > UINT16_MAX) + if (argc == 3) { - fprintf(stderr, "Invalid port number\n"); - show_usage(argv[0], 1); + portno = atoi(argv[2]); + if (portno < 0 || portno > UINT16_MAX) + { + fprintf(stderr, "Invalid port number\n"); + show_usage(argv[0], 1); + } + } + else + { + portno = DEFAULT_PORT; } /* Convert the argument into a binary address */