aboutsummaryrefslogtreecommitdiff
path: root/ssh/util.c
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-06-25 22:47:10 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-06-25 22:47:10 +0200
commit4d4cbdaf49f616fea47c543fe2cb74d1d8a1e7ff (patch)
tree7aaee63e8fd4e87640efa5c3a63ffe7926c10fae /ssh/util.c
parent0c7c46894d41dd976e6ee4587c29df1fc62d7459 (diff)
ssh: WIP ssh proxy server
Diffstat (limited to 'ssh/util.c')
-rw-r--r--ssh/util.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/ssh/util.c b/ssh/util.c
new file mode 100644
index 0000000..a8f3c41
--- /dev/null
+++ b/ssh/util.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "util.h"
+
+
+bool parse_host_port(const char *arg, const char **server_host, int *port) {
+ const char *ptr = strchr(arg, ':');
+ if (ptr == NULL) {
+ *server_host = arg;
+ } else {
+ size_t length = ptr - arg;
+ char *host = malloc(length + 1);
+ if (!host) {
+ fprintf(stderr, "Cannot allocate memory!\n");
+ exit(1);
+ }
+ memcpy(host, arg, length);
+ host[length] = '\0';
+ *server_host = host;
+
+ char *endp;
+ *port = strtol(ptr + 1, &endp, 10);
+ if (endp == ptr || *endp != '\0') {
+ return false;
+ }
+ }
+ return true;
+}