2011-03-18 20:46:25 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/nshlib/nsh_telnetd.c
|
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2011-03-18 20:46:25 +01:00
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-03-18 20:46:25 +01:00
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2012-02-02 17:04:09 +01:00
|
|
|
*
|
2011-03-18 20:46:25 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2017-06-27 02:00:13 +02:00
|
|
|
#include <assert.h>
|
2011-03-18 20:46:25 +01:00
|
|
|
#include <debug.h>
|
|
|
|
|
2022-10-16 13:44:38 +02:00
|
|
|
#include <sys/socket.h>
|
2018-01-09 23:15:16 +01:00
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
#include "nsh.h"
|
2012-02-02 17:04:09 +01:00
|
|
|
#include "nsh_console.h"
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2011-03-18 21:35:31 +01:00
|
|
|
#ifdef CONFIG_NSH_TELNET
|
2011-03-18 20:46:25 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2022-08-05 07:37:28 +02:00
|
|
|
* Public Functions
|
2011-03-18 20:46:25 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-02-02 17:04:09 +01:00
|
|
|
* Name: nsh_telnetmain
|
2011-03-18 20:46:25 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2022-08-05 07:37:28 +02:00
|
|
|
int nsh_telnetmain(int argc, FAR char *argv[])
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
2021-06-17 16:59:42 +02:00
|
|
|
FAR struct console_stdio_s *pstate = nsh_newconsole(true);
|
2018-01-09 23:15:16 +01:00
|
|
|
int ret;
|
2016-01-20 18:18:08 +01:00
|
|
|
|
2017-06-27 02:16:05 +02:00
|
|
|
DEBUGASSERT(pstate != NULL);
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2022-10-16 23:17:41 +02:00
|
|
|
/* Execute the session */
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2022-10-16 23:17:41 +02:00
|
|
|
ret = nsh_session(pstate, NSH_LOGIN_TELNET, argc, argv);
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2022-10-16 23:17:41 +02:00
|
|
|
/* Exit upon return */
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2022-10-16 23:17:41 +02:00
|
|
|
nsh_exit(&pstate->cn_vtbl, ret);
|
|
|
|
return ret;
|
2011-03-18 20:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-02-02 17:04:09 +01:00
|
|
|
* Name: nsh_telnetstart
|
2011-03-18 20:46:25 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2012-02-02 17:04:09 +01:00
|
|
|
* nsh_telnetstart() starts the Telnet daemon that will allow multiple
|
|
|
|
* NSH connections via Telnet. This function returns immediately after
|
|
|
|
* the daemon has been started.
|
2011-03-18 20:46:25 +01:00
|
|
|
*
|
2012-02-02 17:04:09 +01:00
|
|
|
* Input Parameters:
|
2017-06-27 17:14:13 +02:00
|
|
|
* family - Provides the IP family to use by the server. May be either
|
|
|
|
* AF_INET or AF_INET6. This is needed because both both may be
|
|
|
|
* enabled in the configuration.
|
|
|
|
*
|
|
|
|
* All of the other properties of the Telnet daemon are controlled by
|
|
|
|
* NuttX configuration settings.
|
2011-03-18 20:46:25 +01:00
|
|
|
*
|
2012-02-02 17:04:09 +01:00
|
|
|
* Returned Values:
|
2013-01-29 23:11:04 +01:00
|
|
|
* The task ID of the Telnet daemon was successfully started. A negated
|
|
|
|
* errno value will be returned on failure.
|
2014-04-14 00:24:28 +02:00
|
|
|
*
|
2011-03-18 20:46:25 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2022-08-05 07:37:28 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_TELNETSTART
|
2017-06-27 17:14:13 +02:00
|
|
|
int nsh_telnetstart(sa_family_t family)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
2022-10-16 13:44:38 +02:00
|
|
|
FAR struct console_stdio_s *pstate = nsh_newconsole(false);
|
|
|
|
int ret;
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2022-10-16 13:44:38 +02:00
|
|
|
DEBUGASSERT(pstate != NULL);
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2022-10-16 13:44:38 +02:00
|
|
|
/* Start the telnet daemon */
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2022-10-16 13:44:38 +02:00
|
|
|
ninfo("Starting the Telnet daemon\n");
|
2017-06-27 02:00:13 +02:00
|
|
|
|
2020-02-03 10:50:16 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2022-10-16 13:44:38 +02:00
|
|
|
if (family == AF_INET)
|
|
|
|
{
|
|
|
|
char cmdline[] = CONFIG_SYSTEM_TELNETD_PROGNAME " -4 &";
|
|
|
|
ret = nsh_parse(&pstate->cn_vtbl, cmdline);
|
|
|
|
}
|
|
|
|
else
|
2020-02-03 10:50:16 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2022-10-16 13:44:38 +02:00
|
|
|
if (family == AF_INET6)
|
|
|
|
{
|
|
|
|
char cmdline[] = CONFIG_SYSTEM_TELNETD_PROGNAME " -6 &";
|
|
|
|
ret = nsh_parse(&pstate->cn_vtbl, cmdline);
|
2011-03-18 20:46:25 +01:00
|
|
|
}
|
2022-10-16 13:44:38 +02:00
|
|
|
else
|
2022-08-05 07:37:28 +02:00
|
|
|
#endif
|
2022-10-16 13:44:38 +02:00
|
|
|
{
|
|
|
|
char cmdline[] = CONFIG_SYSTEM_TELNETD_PROGNAME " &";
|
|
|
|
ret = nsh_parse(&pstate->cn_vtbl, cmdline);
|
|
|
|
}
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2022-10-16 13:44:38 +02:00
|
|
|
if (ret < 0)
|
2020-02-03 10:50:16 +01:00
|
|
|
{
|
2022-10-16 13:44:38 +02:00
|
|
|
nerr("ERROR: Failed to start the Telnet daemon: %d\n", ret);
|
2020-02-03 10:50:16 +01:00
|
|
|
}
|
2017-06-27 17:14:13 +02:00
|
|
|
|
2022-10-16 13:44:38 +02:00
|
|
|
nsh_release(&pstate->cn_vtbl);
|
|
|
|
return ret;
|
2017-06-27 02:00:13 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-03-18 21:35:31 +01:00
|
|
|
#endif /* CONFIG_NSH_TELNET */
|