[rtems commit] telnetd: Add server port to configuration

Sebastian Huber sebh at rtems.org
Thu Oct 11 07:12:01 UTC 2018


Module:    rtems
Branch:    master
Commit:    26b58b7e4af27b632a3765249ba8f8a9b024fa08
Changeset: http://git.rtems.org/rtems/commit/?id=26b58b7e4af27b632a3765249ba8f8a9b024fa08

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Oct 10 13:12:50 2018 +0200

telnetd: Add server port to configuration

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 e662874..1f8e1c5 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 147e18f..b8adec2 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 31439da..3202f3e 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 ***



More information about the vc mailing list