mirror of
				https://github.com/wangyu-/udp2raw.git
				synced 2025-10-31 10:15:33 +08:00 
			
		
		
		
	Merge 9951f8f4c4 into 8ceaf27eda
				
					
				
			This commit is contained in:
		
							
								
								
									
										12
									
								
								Dockerfile
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								Dockerfile
									
									
									
									
									
								
							| @@ -2,10 +2,14 @@ FROM alpine:3.6 as builder | |||||||
|  |  | ||||||
| WORKDIR / | WORKDIR / | ||||||
|  |  | ||||||
| RUN apk add --no-cache git  build-base linux-headers && \ | COPY . udp2raw-tunnel | ||||||
|  git clone https://github.com/wangyu-/udp2raw-tunnel.git  && \ |  | ||||||
|  cd udp2raw-tunnel && \ | RUN apk add --no-cache git build-base linux-headers && cd udp2raw-tunnel && make dynamic | ||||||
|  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 | FROM alpine:3.6 | ||||||
| RUN apk add --no-cache libstdc++ iptables | RUN apk add --no-cache libstdc++ iptables | ||||||
|   | |||||||
							
								
								
									
										57
									
								
								common.cpp
									
									
									
									
									
								
							
							
						
						
									
										57
									
								
								common.cpp
									
									
									
									
									
								
							| @@ -9,26 +9,31 @@ | |||||||
| #include "log.h" | #include "log.h" | ||||||
| #include "misc.h" | #include "misc.h" | ||||||
|  |  | ||||||
|  | #include <assert.h> | ||||||
| #include <random> | #include <random> | ||||||
| #include <cmath> | #include <cmath> | ||||||
|  | #include <string> | ||||||
|  | #include <iostream> | ||||||
|  |  | ||||||
| //static int random_number_fd=-1; | //static int random_number_fd=-1; | ||||||
| int force_socket_buf=0; | int force_socket_buf=0; | ||||||
|  |  | ||||||
| int address_t::from_str(char *str) | int address_t::from_str(std::string str) | ||||||
| { | { | ||||||
| 	clear(); | 	clear(); | ||||||
|  |  | ||||||
| 	char ip_addr_str[100];u32_t port; | 	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; | 	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"); | 		mylog(log_info,"its an ipv6 adress\n"); | ||||||
| 		inner.ipv6.sin6_family=AF_INET6; | 		inner.ipv6.sin6_family=AF_INET6; | ||||||
| 		is_ipv6=1; | 		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"); | 		mylog(log_info,"its an ipv4 adress\n"); | ||||||
| 		inner.ipv4.sin_family=AF_INET; | 		inner.ipv4.sin_family=AF_INET; | ||||||
| @@ -39,6 +44,50 @@ int address_t::from_str(char *str) | |||||||
| 		myexit(-1); | 		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); | 	mylog(log_info,"ip_address is {%s}, port is {%u}\n",ip_addr_str,port); | ||||||
|  |  | ||||||
| 	if(port>65535) | 	if(port>65535) | ||||||
|   | |||||||
							
								
								
									
										5
									
								
								common.h
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								common.h
									
									
									
									
									
								
							| @@ -68,6 +68,8 @@ const int is_udp2raw_mp=0; | |||||||
| #if defined(__MINGW32__) | #if defined(__MINGW32__) | ||||||
| #include <winsock2.h> | #include <winsock2.h> | ||||||
| #include <ws2ipdef.h> | #include <ws2ipdef.h> | ||||||
|  | #include <ws2def.h> | ||||||
|  | #include <ws2tcpip.h> | ||||||
| typedef unsigned char u_int8_t; | typedef unsigned char u_int8_t; | ||||||
| typedef unsigned short u_int16_t; | typedef unsigned short u_int16_t; | ||||||
| typedef unsigned int u_int32_t; | typedef unsigned int u_int32_t; | ||||||
| @@ -78,6 +80,7 @@ typedef int socklen_t; | |||||||
| #include <sys/ioctl.h> | #include <sys/ioctl.h> | ||||||
| #include <arpa/inet.h> | #include <arpa/inet.h> | ||||||
| #include <netinet/in.h> | #include <netinet/in.h> | ||||||
|  | #include <netdb.h> | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -238,7 +241,7 @@ struct address_t  //TODO scope id | |||||||
| 		return 0; | 		return 0; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	int from_str(char * str); | 	int from_str(std::string str); | ||||||
|  |  | ||||||
| 	int from_str_ip_only(char * str); | 	int from_str_ip_only(char * str); | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										8
									
								
								misc.cpp
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								misc.cpp
									
									
									
									
									
								
							| @@ -110,7 +110,7 @@ int process_lower_level_arg()//handle --lower-level option | |||||||
| 	lower_level_manual=1; | 	lower_level_manual=1; | ||||||
| 	if (strchr(optarg, '#') == 0) { | 	if (strchr(optarg, '#') == 0) { | ||||||
| 		mylog(log_fatal, | 		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); | 		myexit(-1); | ||||||
| 	} | 	} | ||||||
| 	lower_level = 1; | 	lower_level = 1; | ||||||
| @@ -359,12 +359,12 @@ void process_arg(int argc, char *argv[])  //process all options | |||||||
| 		} | 		} | ||||||
| 		if(len==1&&argv[i][0]=='-' ) | 		if(len==1&&argv[i][0]=='-' ) | ||||||
| 		{ | 		{ | ||||||
| 			mylog(log_fatal,"invaild option '-' in argv\n"); | 			mylog(log_fatal,"invalid option '-' in argv\n"); | ||||||
| 			myexit(-1); | 			myexit(-1); | ||||||
| 		} | 		} | ||||||
| 		if(len==2&&argv[i][0]=='-'&&argv[i][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); | 			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()) | 	   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); | 			myexit(-1); | ||||||
| 	   } | 	   } | ||||||
| 	   for(j=i+1;j<argc;j++) | 	   for(j=i+1;j<argc;j++) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user