From e1c9521f37587d8f9d194d8e98da0f7e4da8b4f3 Mon Sep 17 00:00:00 2001 From: Jerry Date: Mon, 15 Feb 2021 14:36:29 +0000 Subject: [PATCH 1/3] build from current sources --- Dockerfile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 57db420c..fd9a0f78 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,10 +2,14 @@ FROM alpine:3.6 as builder WORKDIR / -RUN apk add --no-cache git build-base linux-headers && \ - git clone https://github.com/wangyu-/udp2raw-tunnel.git && \ - cd udp2raw-tunnel && \ - make dynamic +COPY . udp2raw-tunnel + +RUN apk add --no-cache git build-base linux-headers && cd udp2raw-tunnel && make dynamic + +#RUN apk add --no-cache git build-base linux-headers && \ +# git clone https://github.com/wangyu-/udp2raw-tunnel.git && \ +# cd udp2raw-tunnel && \ +# make dynamic FROM alpine:3.6 RUN apk add --no-cache libstdc++ iptables From 11b6da57f1fa07326f38dd5e95d0b40076bdfa47 Mon Sep 17 00:00:00 2001 From: Jerry Date: Mon, 15 Feb 2021 14:42:58 +0000 Subject: [PATCH 2/3] fix spelling mistakes --- misc.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/misc.cpp b/misc.cpp index 10656ed3..2c66eadd 100644 --- a/misc.cpp +++ b/misc.cpp @@ -110,7 +110,7 @@ int process_lower_level_arg()//handle --lower-level option lower_level_manual=1; if (strchr(optarg, '#') == 0) { mylog(log_fatal, - "lower-level parameter invaild,check help page for format\n"); + "lower-level parameter invalid,check help page for format\n"); myexit(-1); } lower_level = 1; @@ -359,12 +359,12 @@ void process_arg(int argc, char *argv[]) //process all options } if(len==1&&argv[i][0]=='-' ) { - mylog(log_fatal,"invaild option '-' in argv\n"); + mylog(log_fatal,"invalid option '-' in argv\n"); myexit(-1); } if(len==2&&argv[i][0]=='-'&&argv[i][1]=='-' ) { - mylog(log_fatal,"invaild option '--' in argv\n"); + mylog(log_fatal,"invalid option '--' in argv\n"); myexit(-1); } } @@ -386,7 +386,7 @@ void process_arg(int argc, char *argv[]) //process all options if(all_options.find(a.c_str())==all_options.end()) { - mylog(log_fatal,"invaild option %s\n",a.c_str()); + mylog(log_fatal,"invalid option %s\n",a.c_str()); myexit(-1); } for(j=i+1;j Date: Mon, 15 Feb 2021 18:37:52 +0000 Subject: [PATCH 3/3] support resolve hostname with getaddrinfo when parsing --- common.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++---- common.h | 5 ++++- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/common.cpp b/common.cpp index 23aad31d..8ef6e921 100644 --- a/common.cpp +++ b/common.cpp @@ -9,26 +9,31 @@ #include "log.h" #include "misc.h" +#include #include #include +#include +#include //static int random_number_fd=-1; int force_socket_buf=0; -int address_t::from_str(char *str) +int address_t::from_str(std::string str) { clear(); char ip_addr_str[100];u32_t port; - mylog(log_info,"parsing address: %s\n",str); + mylog(log_info,"parsing address: %s\n",str.c_str()); int is_ipv6=0; - if(sscanf(str, "[%[^]]]:%u", ip_addr_str,&port)==2) + +#if 0 + if(sscanf(str.c_str(), "[%[^]]]:%u", ip_addr_str,&port)==2) { mylog(log_info,"its an ipv6 adress\n"); inner.ipv6.sin6_family=AF_INET6; is_ipv6=1; } - else if(sscanf(str, "%[^:]:%u", ip_addr_str,&port)==2) + else if(sscanf(str.c_str(), "%[^:]:%u", ip_addr_str,&port)==2) { mylog(log_info,"its an ipv4 adress\n"); inner.ipv4.sin_family=AF_INET; @@ -39,6 +44,50 @@ int address_t::from_str(char *str) myexit(-1); } +#else + auto found_colon = str.rfind(":"); + if (found_colon == std::string::npos) { + mylog(log_error, "failed to parse\n"); + myexit(-1); + } + std::string hostname = str.substr(0, found_colon); + std::string portstr = str.substr(found_colon+1); + if (hostname.empty() || portstr.empty()) { + mylog(log_error, "failed to parse\n"); + myexit(-1); + } + assert(sscanf(portstr.c_str(), "%u", &port) == 1); + mylog(log_info, "check hostname: %s\n", hostname.c_str()); + struct addrinfo *addr_ret = nullptr; + int h_ret = getaddrinfo(hostname.c_str(), NULL, NULL, &addr_ret); // TODO fill hint + if (h_ret != 0) { + mylog(log_error, "getaddrinfo failed: %d\n", h_ret); + myexit(-1); + } + if (addr_ret == nullptr) { + mylog(log_error, "cannot resolve hostname\n"); + myexit(-1); + } + // just use the first host info + auto rp = addr_ret; + // TODO Maybe I can just assign getaddrinfo results to inner... + switch (rp->ai_family) { + case AF_INET: + inner.ipv4.sin_family=AF_INET; + strcpy(ip_addr_str, inet_ntoa(((struct sockaddr_in*)(rp->ai_addr))->sin_addr)); + break; + case AF_INET6: + inner.ipv6.sin6_family=AF_INET6; + is_ipv6=1; + inet_ntop(AF_INET6, &(((struct sockaddr_in6*)(rp->ai_addr))->sin6_addr), ip_addr_str, INET6_ADDRSTRLEN); + break; + default: + mylog(log_error,"failed to parse\n"); + myexit(-1); + } + +#endif + mylog(log_info,"ip_address is {%s}, port is {%u}\n",ip_addr_str,port); if(port>65535) diff --git a/common.h b/common.h index d01e5cae..e9b8f177 100644 --- a/common.h +++ b/common.h @@ -68,6 +68,8 @@ const int is_udp2raw_mp=0; #if defined(__MINGW32__) #include #include +#include +#include typedef unsigned char u_int8_t; typedef unsigned short u_int16_t; typedef unsigned int u_int32_t; @@ -78,6 +80,7 @@ typedef int socklen_t; #include #include #include +#include #endif @@ -238,7 +241,7 @@ struct address_t //TODO scope id return 0; } - int from_str(char * str); + int from_str(std::string str); int from_str_ip_only(char * str);