mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 14:29:34 +08:00
Trial on using remote_host instead of ip
This commit is contained in:
parent
f34f903317
commit
c6cd29dd6f
@ -99,7 +99,7 @@ repository: https://github.com/wangyu-/udp2raw-tunnel
|
||||
|
||||
usage:
|
||||
run as client : ./this_program -c -l local_listen_ip:local_port -r server_ip:server_port [options]
|
||||
run as server : ./this_program -s -l server_listen_ip:server_port -r remote_ip:remote_port [options]
|
||||
run as server : ./this_program -s -l server_listen_ip:server_port -r remote_host:remote_port [options]
|
||||
|
||||
common options,these options must be same on both side:
|
||||
--raw-mode <string> avaliable values:faketcp(default),udp,icmp
|
||||
|
1
common.h
1
common.h
@ -24,6 +24,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h> //for exit(0);
|
||||
#include <errno.h> //For errno - the error number
|
||||
#include <netdb.h> // for gethostbyname()
|
||||
#include <netinet/tcp.h> //Provides declarations for tcp header
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/ip.h> //Provides declarations for ip header
|
||||
|
@ -103,7 +103,7 @@ repository: https://github.com/wangyu-/udp2raw-tunnel
|
||||
|
||||
usage:
|
||||
run as client : ./this_program -c -l local_listen_ip:local_port -r server_ip:server_port [options]
|
||||
run as server : ./this_program -s -l server_listen_ip:server_port -r remote_ip:remote_port [options]
|
||||
run as server : ./this_program -s -l server_listen_ip:server_port -r remote_host:remote_port [options]
|
||||
|
||||
common options,these options must be same on both side:
|
||||
--raw-mode <string> avaliable values:faketcp(default),udp,icmp
|
||||
|
11
main.cpp
11
main.cpp
@ -1023,7 +1023,7 @@ int client_event_loop()
|
||||
string hw_string;
|
||||
if(find_lower_level_info(remote_ip_uint32,dest_ip,if_name_string,hw_string)!=0)
|
||||
{
|
||||
mylog(log_fatal,"auto detect lower-level info failed for %s,specific it manually\n",remote_ip);
|
||||
mylog(log_fatal,"auto detect lower-level info failed for %s,specific it manually\n",remote_host);
|
||||
myexit(-1);
|
||||
}
|
||||
mylog(log_info,"we are running at lower-level (auto) mode,%s %s %s\n",my_ntoa(dest_ip),if_name_string.c_str(),hw_string.c_str());
|
||||
@ -1611,8 +1611,15 @@ int main(int argc, char *argv[])
|
||||
mylog(log_error,"root check failed,make sure you run this program with root,we can try to continue,but it will likely fail\n");
|
||||
}
|
||||
|
||||
|
||||
struct hostent *he;
|
||||
if ( (he = gethostbyname(remote_host) ) == NULL ) {
|
||||
mylog(log_error,"Unable to resolve hostname: %s\n",remote_host);
|
||||
exit(1); /* error */
|
||||
}
|
||||
remote_ip_uint32=inet_addr(he->h_addr_list[0]);
|
||||
|
||||
local_ip_uint32=inet_addr(local_ip);
|
||||
remote_ip_uint32=inet_addr(remote_ip);
|
||||
source_ip_uint32=inet_addr(source_ip);
|
||||
|
||||
|
||||
|
16
misc.cpp
16
misc.cpp
@ -12,9 +12,9 @@
|
||||
#include "connection.h"
|
||||
|
||||
|
||||
char local_ip[100]="0.0.0.0", remote_ip[100]="255.255.255.255",source_ip[100]="0.0.0.0";//local_ip is for -l option,remote_ip for -r option,source for --source-ip
|
||||
char local_ip[100]="0.0.0.0", remote_host[100]="255.255.255.255",source_ip[100]="0.0.0.0";//local_ip is for -l option,remote_host for -r option,source for --source-ip
|
||||
u32_t local_ip_uint32,remote_ip_uint32,source_ip_uint32;//convert from last line.
|
||||
int local_port = -1, remote_port=-1,source_port=0;//similiar to local_ip remote_ip,buf for port.source_port=0 indicates --source-port is not enabled
|
||||
int local_port = -1, remote_port=-1,source_port=0;//similiar to local_ip remote_host,buf for port.source_port=0 indicates --source-port is not enabled
|
||||
|
||||
int force_source_ip=0; //if --source-ip is enabled
|
||||
|
||||
@ -100,7 +100,7 @@ void print_help()
|
||||
printf("\n");
|
||||
printf("usage:\n");
|
||||
printf(" run as client : ./this_program -c -l local_listen_ip:local_port -r server_ip:server_port [options]\n");
|
||||
printf(" run as server : ./this_program -s -l server_listen_ip:server_port -r remote_ip:remote_port [options]\n");
|
||||
printf(" run as server : ./this_program -s -l server_listen_ip:server_port -r remote_host:remote_port [options]\n");
|
||||
printf("\n");
|
||||
printf("common options,these options must be same on both side:\n");
|
||||
printf(" --raw-mode <string> avaliable values:faketcp(default),udp,icmp\n");
|
||||
@ -363,7 +363,7 @@ void process_arg(int argc, char *argv[]) //process all options
|
||||
case 'r':
|
||||
no_r = 0;
|
||||
if (strchr(optarg, ':') != 0) {
|
||||
sscanf(optarg, "%[^:]:%d", remote_ip, &remote_port);
|
||||
sscanf(optarg, "%[^:]:%d", remote_host, &remote_port);
|
||||
if(remote_port==22)
|
||||
{
|
||||
mylog(log_fatal,"port 22 not allowed\n");
|
||||
@ -623,7 +623,7 @@ void process_arg(int argc, char *argv[]) //process all options
|
||||
|
||||
log_bare(log_info,"local_ip=%s ",local_ip);
|
||||
log_bare(log_info,"local_port=%d ",local_port);
|
||||
log_bare(log_info,"remote_ip=%s ",remote_ip);
|
||||
log_bare(log_info,"remote_host=%s ",remote_host);
|
||||
log_bare(log_info,"remote_port=%d ",remote_port);
|
||||
log_bare(log_info,"source_ip=%s ",source_ip);
|
||||
log_bare(log_info,"source_port=%d ",source_port);
|
||||
@ -766,15 +766,15 @@ void iptables_rule() // handles -a -g --gen-add --keep-rule
|
||||
{
|
||||
if(raw_mode==mode_faketcp)
|
||||
{
|
||||
sprintf(tmp_pattern,"-s %s/32 -p tcp -m tcp --sport %d",remote_ip,remote_port);
|
||||
sprintf(tmp_pattern,"-s %s/32 -p tcp -m tcp --sport %d",remote_host,remote_port);
|
||||
}
|
||||
if(raw_mode==mode_udp)
|
||||
{
|
||||
sprintf(tmp_pattern,"-s %s/32 -p udp -m udp --sport %d",remote_ip,remote_port);
|
||||
sprintf(tmp_pattern,"-s %s/32 -p udp -m udp --sport %d",remote_host,remote_port);
|
||||
}
|
||||
if(raw_mode==mode_icmp)
|
||||
{
|
||||
sprintf(tmp_pattern,"-s %s/32 -p icmp",remote_ip);
|
||||
sprintf(tmp_pattern,"-s %s/32 -p icmp",remote_host);
|
||||
}
|
||||
pattern=tmp_pattern;
|
||||
}
|
||||
|
4
misc.h
4
misc.h
@ -63,9 +63,9 @@ union current_state_t
|
||||
client_current_state_t client_current_state;
|
||||
};
|
||||
|
||||
extern char local_ip[100], remote_ip[100],source_ip[100];//local_ip is for -l option,remote_ip for -r option,source for --source-ip
|
||||
extern char local_ip[100], remote_host[100],source_ip[100];//local_ip is for -l option,remote_host for -r option,source for --source-ip
|
||||
extern u32_t local_ip_uint32,remote_ip_uint32,source_ip_uint32;//convert from last line.
|
||||
extern int local_port , remote_port,source_port;//similiar to local_ip remote_ip,buf for port.source_port=0 indicates --source-port is not enabled
|
||||
extern int local_port , remote_port,source_port;//similiar to local_ip remote_host,buf for port.source_port=0 indicates --source-port is not enabled
|
||||
|
||||
extern int force_source_ip; //if --source-ip is enabled
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user