system/telnet: Fix the style warning

and remove the unused code

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-10-19 00:46:17 +08:00 committed by Masayuki Ishikawa
parent 58c3dbac95
commit 12863fbd52
5 changed files with 30 additions and 36 deletions

View File

@ -53,16 +53,6 @@
#include "nxterm_internal.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* The NSH telnet console requires networking support (and TCP/IP) */
#ifndef CONFIG_NET
# undef CONFIG_NSH_TELNET
#endif
/****************************************************************************
* Public Data
****************************************************************************/

View File

@ -76,7 +76,7 @@ static void telnetd_parse(FAR char *line, int len);
* Private Data
****************************************************************************/
static struct ptentry_s g_parsetab[] =
static const struct ptentry_s g_parsetab[] =
{
{"help", telnetd_help},
{"exit", telnetd_quit},
@ -127,7 +127,7 @@ static void telnetd_quit(int argc, char **argv)
static void telnetd_parse(FAR char *line, int len)
{
struct ptentry_s *entry;
FAR const struct ptentry_s *entry;
FAR char *cmd;
FAR char *saveptr;
@ -140,7 +140,8 @@ static void telnetd_parse(FAR char *line, int len)
for (entry = g_parsetab; entry->commandstr != NULL; entry++)
{
if (strncmp(entry->commandstr, cmd, strlen(entry->commandstr)) == 0)
if (strncmp(entry->commandstr, cmd,
strlen(entry->commandstr)) == 0)
{
break;
}
@ -161,7 +162,7 @@ int telnetd_session(int argc, char *argv[])
printf("uIP command shell -- NuttX style\n");
printf("Type '?' and return for help\n");
for (;;)
for (; ; )
{
printf(SHELL_PROMPT);
fflush(stdout);
@ -188,7 +189,7 @@ static void telnetd_netinit(void)
uint8_t mac[IFHWADDRLEN];
#endif
/* Many embedded network interfaces must have a software assigned MAC */
/* Many embedded network interfaces must have a software assigned MAC */
#ifdef CONFIG_EXAMPLES_TELNETD_NOMAC
mac[0] = 0x00;

View File

@ -56,9 +56,7 @@
#endif
#ifndef CONFIG_FILE_STREAM
# undef CONFIG_NSH_TELNET
# undef CONFIG_NSH_FILE_APPS
# undef CONFIG_NSH_TELNET
# undef CONFIG_NSH_CMDPARMS
#endif

View File

@ -33,16 +33,6 @@
#include "nshlib/nshlib.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* The NSH telnet console requires networking support (and TCP/IP) */
#ifndef CONFIG_NET
# undef CONFIG_NSH_TELNET
#endif
/****************************************************************************
* Public Functions
****************************************************************************/

View File

@ -115,13 +115,17 @@ static const struct telnet_telopt_s g_telopts[] =
static void send_local_input(char *buffer, int size)
{
static char crlf[] = { '\r', '\n' };
static char crlf[] =
{
'\r', '\n'
};
int i;
for (i = 0; i != size; ++i)
{
/* If we got a CR or LF, replace with CRLF NOTE that usually you'd get a
* CR in UNIX, but in raw mode we get LF instead (not sure why).
/* If we got a CR or LF, replace with CRLF NOTE that usually you'd get
* a CR in UNIX, but in raw mode we get LF instead (not sure why).
*/
if (buffer[i] == '\r' || buffer[i] == '\n')
@ -165,6 +169,7 @@ static void telnet_ev_send(int sock, const char *buffer, size_t size)
{
fprintf(stderr, "send() unexpectedly returned 0\n");
}
telnet_free(g_telnet);
exit(1);
}
@ -199,6 +204,7 @@ static void _event_handler(struct telnet_s *telnet,
/* Request to enable remote feature (or receipt) */
case TELNET_EV_WILL:
/* We'll agree to turn off our echo if server wants us to stop */
if (ev->neg.telopt == TELNET_TELOPT_ECHO)
@ -230,6 +236,7 @@ static void _event_handler(struct telnet_s *telnet,
/* Respond to TTYPE commands */
case TELNET_EV_TTYPE:
/* Respond with our terminal type, if requested */
if (ev->ttype.cmd == TELNET_TTYPE_SEND)
@ -251,6 +258,7 @@ static void _event_handler(struct telnet_s *telnet,
exit(1);
default:
/* Ignore */
break;
@ -262,10 +270,13 @@ static void show_usage(const char *progname, int exitcode)
fprintf(stderr, "Usage:\n");
fprintf(stderr, "\t%s <server-IP-addr> [<port>]\n", progname);
fprintf(stderr, "Where:\n");
fprintf(stderr, "\t<server-IP-addr> is the address of the Telnet server. Either\n");
fprintf(stderr,
"\t<server-IP-addr> 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<port> is the (optional) listening port of the Telnet server.\n");
fprintf(stderr,
"\t\tIPv6 form: xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx\n");
fprintf(stderr,
"\t<port> is the (optional) listening port of the Telnet server.\n");
fprintf(stderr, "\t\tDefault: %u\n", DEFAULT_PORT);
exit(exitcode);
}
@ -286,7 +297,9 @@ int main(int argc, FAR char *argv[])
#ifdef CONFIG_NET_IPv4
struct sockaddr_in ipv4;
#endif
} server;
}
server;
union
{
#ifdef CONFIG_NET_IPv6
@ -295,7 +308,9 @@ int main(int argc, FAR char *argv[])
#ifdef CONFIG_NET_IPv4
struct sockaddr_in ipv4;
#endif
} local;
}
local;
struct pollfd pfd[2];
sa_family_t family;
uint16_t addrlen;
@ -364,7 +379,7 @@ int main(int argc, FAR char *argv[])
/* Create server socket */
sock = socket(family, SOCK_STREAM, 0);
if (sock < 0)
if (sock < 0)
{
fprintf(stderr, "socket() failed: %d\n", errno);
return 1;