mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-31 20:29:36 +08:00
fixed bug of last few commit, and fixed a bug of bind error
This commit is contained in:
parent
1afe8d7317
commit
1bdb6a5720
5
common.h
5
common.h
@ -80,10 +80,7 @@ struct ip_port_t
|
||||
char * to_s();
|
||||
};
|
||||
|
||||
struct fd_info_t
|
||||
{
|
||||
ip_port_t ip_port;
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef u64_t fd64_t;
|
||||
|
@ -95,7 +95,7 @@ struct conn_info_t //stores info for a raw connection.for client ,there is o
|
||||
uint8_t oppsite_roller;
|
||||
u64_t last_oppsite_roller_time;
|
||||
|
||||
ip_port_t ip_port;
|
||||
// ip_port_t ip_port;
|
||||
|
||||
/*
|
||||
const uint32_t &ip=raw_info.recv_info.src_ip;
|
||||
|
20
main.cpp
20
main.cpp
@ -27,8 +27,6 @@ int client_on_timer(conn_info_t &conn_info) //for client. called when a timer is
|
||||
mylog(log_trace,"<client_on_timer,send_info.ts_ack= %u>\n",send_info.ts_ack);
|
||||
|
||||
|
||||
|
||||
|
||||
if(conn_info.state.client_current_state==client_idle)
|
||||
{
|
||||
fail_time_counter++;
|
||||
@ -603,8 +601,8 @@ int server_on_raw_recv_multi() //called when server received an raw packet
|
||||
conn_info_t &conn_info=conn_manager.find_insert(ip,port);
|
||||
conn_info.raw_info=tmp_raw_info;
|
||||
|
||||
conn_info.ip_port.ip=ip;
|
||||
conn_info.ip_port.port=port;
|
||||
//conn_info.ip_port.ip=ip;
|
||||
//conn_info.ip_port.port=port;
|
||||
|
||||
packet_info_t &send_info=conn_info.raw_info.send_info;
|
||||
packet_info_t &recv_info=conn_info.raw_info.recv_info;
|
||||
@ -826,7 +824,7 @@ int server_on_raw_recv_ready(conn_info_t &conn_info,char * ip_port,char type,cha
|
||||
struct epoll_event ev;
|
||||
|
||||
fd64_t new_udp_fd64 = fd_manager.create(new_udp_fd);
|
||||
fd_manager.get_info(new_udp_fd64).ip_port=conn_info.ip_port;
|
||||
fd_manager.get_info(new_udp_fd64).p_conn_info=&conn_info;
|
||||
|
||||
mylog(log_trace, "[%s]u64: %lld\n",ip_port, new_udp_fd64);
|
||||
ev.events = EPOLLIN;
|
||||
@ -928,7 +926,7 @@ int server_on_raw_recv_pre_ready(conn_info_t &conn_info,char * ip_port,u32_t tmp
|
||||
int new_timer_fd;
|
||||
set_timer_server(epollfd, new_timer_fd,conn_info.timer_fd64);
|
||||
|
||||
fd_manager.get_info(conn_info.timer_fd64).ip_port=conn_info.ip_port;
|
||||
fd_manager.get_info(conn_info.timer_fd64).p_conn_info=&conn_info;
|
||||
//assert(conn_manager.timer_fd_mp.find(new_timer_fd)==conn_manager.timer_fd_mp.end());
|
||||
//conn_manager.timer_fd_mp[new_timer_fd] = &conn_info;//pack_u64(ip,port);
|
||||
|
||||
@ -1492,13 +1490,13 @@ int server_event_loop()
|
||||
|
||||
assert(fd_manager.exist_info(fd64));
|
||||
|
||||
ip_port_t ip_port=fd_manager.get_info(fd64).ip_port;
|
||||
u32_t ip=ip_port.ip;
|
||||
u32_t port=ip_port.port;
|
||||
conn_info_t* p_conn_info=fd_manager.get_info(fd64).p_conn_info;
|
||||
u32_t ip=p_conn_info->raw_info.send_info.dst_ip;
|
||||
u32_t port=p_conn_info->raw_info.send_info.dst_port;
|
||||
|
||||
assert(conn_manager.exist(ip,port));
|
||||
//assert(conn_manager.exist(ip,port));
|
||||
|
||||
conn_info_t* p_conn_info=conn_manager.find_insert_p(ip,port);
|
||||
///conn_info_t* p_conn_info=conn_manager.find_insert_p(ip,port);
|
||||
|
||||
|
||||
if(fd64==p_conn_info->timer_fd64)//////////timer_fd64
|
||||
|
16
network.cpp
16
network.cpp
@ -1820,17 +1820,17 @@ int get_src_adress(u32_t &ip,u32_t remote_ip_uint32,int remote_port) //a trick
|
||||
return 0;
|
||||
}
|
||||
|
||||
int try_to_list_and_bind(int bind_fd,u32_t local_ip_uint32,int port) //try to bind to a port,may fail.
|
||||
int try_to_list_and_bind(int &fd,u32_t local_ip_uint32,int port) //try to bind to a port,may fail.
|
||||
{
|
||||
int old_bind_fd=bind_fd;
|
||||
int old_bind_fd=fd;
|
||||
|
||||
if(raw_mode==mode_faketcp)
|
||||
{
|
||||
bind_fd=socket(AF_INET,SOCK_STREAM,0);
|
||||
fd=socket(AF_INET,SOCK_STREAM,0);
|
||||
}
|
||||
else if(raw_mode==mode_udp||raw_mode==mode_icmp)
|
||||
{
|
||||
bind_fd=socket(AF_INET,SOCK_DGRAM,0);
|
||||
fd=socket(AF_INET,SOCK_DGRAM,0);
|
||||
}
|
||||
if(old_bind_fd!=-1)
|
||||
{
|
||||
@ -1844,7 +1844,7 @@ int try_to_list_and_bind(int bind_fd,u32_t local_ip_uint32,int port) //try to b
|
||||
temp_bind_addr.sin_port = htons(port);
|
||||
temp_bind_addr.sin_addr.s_addr = local_ip_uint32;
|
||||
|
||||
if (bind(bind_fd, (struct sockaddr*)&temp_bind_addr, sizeof(temp_bind_addr)) !=0)
|
||||
if (bind(fd, (struct sockaddr*)&temp_bind_addr, sizeof(temp_bind_addr)) !=0)
|
||||
{
|
||||
mylog(log_debug,"bind fail\n");
|
||||
return -1;
|
||||
@ -1852,19 +1852,19 @@ int try_to_list_and_bind(int bind_fd,u32_t local_ip_uint32,int port) //try to b
|
||||
if(raw_mode==mode_faketcp)
|
||||
{
|
||||
|
||||
if (listen(bind_fd, SOMAXCONN) != 0) {
|
||||
if (listen(fd, SOMAXCONN) != 0) {
|
||||
mylog(log_warn,"listen fail\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int client_bind_to_a_new_port(int bind_fd,u32_t local_ip_uint32)//find a free port and bind to it.
|
||||
int client_bind_to_a_new_port(int &fd,u32_t local_ip_uint32)//find a free port and bind to it.
|
||||
{
|
||||
int raw_send_port=10000+get_true_random_number()%(65535-10000);
|
||||
for(int i=0;i<1000;i++)//try 1000 times at max,this should be enough
|
||||
{
|
||||
if (try_to_list_and_bind(bind_fd,local_ip_uint32,raw_send_port)==0)
|
||||
if (try_to_list_and_bind(fd,local_ip_uint32,raw_send_port)==0)
|
||||
{
|
||||
return raw_send_port;
|
||||
}
|
||||
|
@ -99,9 +99,9 @@ int find_lower_level_info(u32_t ip,u32_t &dest_ip,string &if_name,string &hw);
|
||||
|
||||
int get_src_adress(u32_t &ip,u32_t remote_ip_uint32,int remote_port); //a trick to get src adress for a dest adress,so that we can use the src address in raw socket as source ip
|
||||
|
||||
int try_to_list_and_bind(int bind_fd,u32_t local_ip_uint32,int port); //try to bind to a port,may fail.
|
||||
int try_to_list_and_bind(int & bind_fd,u32_t local_ip_uint32,int port); //try to bind to a port,may fail.
|
||||
|
||||
int client_bind_to_a_new_port(int bind_fd,u32_t local_ip_uint32);//find a free port and bind to it.
|
||||
int client_bind_to_a_new_port(int & bind_fd,u32_t local_ip_uint32);//find a free port and bind to it.
|
||||
|
||||
int send_raw_ip(raw_info_t &raw_info,const char * payload,int payloadlen);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user