[PATCH 6/6] telnetd: Add server port to configuration

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Oct 10 12:12:33 UTC 2018


Close #3543.
---
 cpukit/include/rtems/telnetd.h              |  9 ++++++++-
 cpukit/telnetd/telnetd.c                    | 13 ++++++++++---
 testsuites/libtests/telnetd01/telnetd01.scn |  2 +-
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/cpukit/include/rtems/telnetd.h b/cpukit/include/rtems/telnetd.h
index e662874a81..1f8e1c55c3 100644
--- a/cpukit/include/rtems/telnetd.h
+++ b/cpukit/include/rtems/telnetd.h
@@ -92,6 +92,13 @@ typedef struct {
    * Use 0 for the default value.
    */
   uint16_t client_maximum;
+
+  /**
+   * @brief Server port number in host byte order.
+   *
+   * Use 0 for the default value.
+   */
+  uint16_t port;
 } rtems_telnetd_config_table;
 
 /**
@@ -100,7 +107,7 @@ typedef struct {
  * @retval RTEMS_SUCCESSFUL Successful operation.
  * @retval RTEMS_INVALID_ADDRESS The command function in the configuration is
  *   @c NULL.
- * @retval RTEMS_RESOURCE_IN_USE The Telnet server was already started.
+ * @retval RTEMS_RESOURCE_IN_USE The server port is already in use.
  * @retval RTEMS_NOT_IMPLEMENTED The keep stdio configuration option is true.
  * @retval RTEMS_UNSATISFIED Not enough resources to start the Telnet server or
  *   task priority in configuration is invalid.
diff --git a/cpukit/telnetd/telnetd.c b/cpukit/telnetd/telnetd.c
index 9f2dc25c93..4f4edff71b 100644
--- a/cpukit/telnetd/telnetd.c
+++ b/cpukit/telnetd/telnetd.c
@@ -44,6 +44,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <inttypes.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -51,7 +52,6 @@
 #include <syslog.h>
 
 #include <rtems.h>
-#include <rtems/error.h>
 #include <rtems/pty.h>
 #include <rtems/shell.h>
 #include <rtems/telnetd.h>
@@ -295,7 +295,7 @@ static rtems_status_code telnetd_create_server_socket(telnetd_context *ctx)
 
   memset(&srv, 0, sizeof(srv));
   srv.sin.sin_family = AF_INET;
-  srv.sin.sin_port = htons(23);
+  srv.sin.sin_port = htons(ctx->config.port);
   address_len = sizeof(srv.sin);
 
   if (bind(ctx->server_socket, &srv.sa, address_len) != 0) {
@@ -415,6 +415,10 @@ rtems_status_code rtems_telnetd_start(const rtems_telnetd_config_table* config)
     ctx->config.stack_size = (size_t)32 * 1024;
   }
 
+  if (ctx->config.port == 0) {
+    ctx->config.port = 23;
+  }
+
   sc = telnetd_create_server_socket(ctx);
   if (sc != RTEMS_SUCCESSFUL) {
     telnetd_destroy_context(ctx);
@@ -447,6 +451,9 @@ rtems_status_code rtems_telnetd_start(const rtems_telnetd_config_table* config)
     (rtems_task_argument) ctx
   );
 
-  syslog(LOG_DAEMON | LOG_INFO, "telnetd: started successfully");
+  syslog(
+    LOG_DAEMON | LOG_INFO,
+    "telnetd: started successfully on port %" PRIu16, ctx->config.port
+  );
   return RTEMS_SUCCESSFUL;
 }
diff --git a/testsuites/libtests/telnetd01/telnetd01.scn b/testsuites/libtests/telnetd01/telnetd01.scn
index 31439da5a0..3202f3e094 100644
--- a/testsuites/libtests/telnetd01/telnetd01.scn
+++ b/testsuites/libtests/telnetd01/telnetd01.scn
@@ -5,7 +5,7 @@
 *** TEST TOOLS: 7.3.0 20180125 (RTEMS 5, RSB 9670d7541e0621915e521fe76e7bb33de8cee661, Newlib d13c84eb07e35984bf7a974cd786a6cdac29e6b9)
 syslog: telnetd: configuration with invalid command
 syslog: telnetd: cannot create session task
-syslog: telnetd: started successfully
+syslog: telnetd: started successfully on port 23
 syslog: telnetd: cannot bind server socket
 
 *** END OF TEST TELNETD 1 ***
-- 
2.16.4




More information about the devel mailing list