mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-02-07 23:59:36 +08:00
renamed id_t to avoid conflict on bsd
This commit is contained in:
parent
23df5160d1
commit
b9af389168
14
common.cpp
14
common.cpp
@ -183,11 +183,11 @@ int set_buf_size(int fd,int socket_buf_size,int force_socket_buf)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int numbers_to_char(id_t id1,id_t id2,id_t id3,char * &data,int &len)
|
int numbers_to_char(my_id_t id1,my_id_t id2,my_id_t id3,char * &data,int &len)
|
||||||
{
|
{
|
||||||
static char buf[buf_len];
|
static char buf[buf_len];
|
||||||
data=buf;
|
data=buf;
|
||||||
id_t tmp=htonl(id1);
|
my_id_t tmp=htonl(id1);
|
||||||
memcpy(buf,&tmp,sizeof(tmp));
|
memcpy(buf,&tmp,sizeof(tmp));
|
||||||
|
|
||||||
tmp=htonl(id2);
|
tmp=htonl(id2);
|
||||||
@ -196,21 +196,21 @@ int numbers_to_char(id_t id1,id_t id2,id_t id3,char * &data,int &len)
|
|||||||
tmp=htonl(id3);
|
tmp=htonl(id3);
|
||||||
memcpy(buf+sizeof(tmp)*2,&tmp,sizeof(tmp));
|
memcpy(buf+sizeof(tmp)*2,&tmp,sizeof(tmp));
|
||||||
|
|
||||||
len=sizeof(id_t)*3;
|
len=sizeof(my_id_t)*3;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int char_to_numbers(const char * data,int len,id_t &id1,id_t &id2,id_t &id3)
|
int char_to_numbers(const char * data,int len,my_id_t &id1,my_id_t &id2,my_id_t &id3)
|
||||||
{
|
{
|
||||||
if(len<int(sizeof(id_t)*3)) return -1;
|
if(len<int(sizeof(my_id_t)*3)) return -1;
|
||||||
//id1=ntohl( *((id_t*)(data+0)) );
|
//id1=ntohl( *((id_t*)(data+0)) );
|
||||||
memcpy(&id1,data+0,sizeof(id1));
|
memcpy(&id1,data+0,sizeof(id1));
|
||||||
id1=ntohl(id1);
|
id1=ntohl(id1);
|
||||||
//id2=ntohl( *((id_t*)(data+sizeof(id_t))) );
|
//id2=ntohl( *((id_t*)(data+sizeof(id_t))) );
|
||||||
memcpy(&id2,data+sizeof(id_t),sizeof(id2));
|
memcpy(&id2,data+sizeof(my_id_t),sizeof(id2));
|
||||||
id2=ntohl(id2);
|
id2=ntohl(id2);
|
||||||
//id3=ntohl( *((id_t*)(data+sizeof(id_t)*2)) );
|
//id3=ntohl( *((id_t*)(data+sizeof(id_t)*2)) );
|
||||||
memcpy(&id3,data+sizeof(id_t)*2,sizeof(id3));
|
memcpy(&id3,data+sizeof(my_id_t)*2,sizeof(id3));
|
||||||
id3=ntohl(id3);
|
id3=ntohl(id3);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
6
common.h
6
common.h
@ -95,7 +95,7 @@ typedef long long i64_t;
|
|||||||
typedef unsigned int u32_t;
|
typedef unsigned int u32_t;
|
||||||
typedef int i32_t;
|
typedef int i32_t;
|
||||||
|
|
||||||
typedef u32_t id_t;
|
typedef u32_t my_id_t;
|
||||||
|
|
||||||
typedef u64_t iv_t;
|
typedef u64_t iv_t;
|
||||||
|
|
||||||
@ -187,8 +187,8 @@ void myexit(int a);
|
|||||||
|
|
||||||
unsigned short csum(const unsigned short *ptr,int nbytes);
|
unsigned short csum(const unsigned short *ptr,int nbytes);
|
||||||
|
|
||||||
int numbers_to_char(id_t id1,id_t id2,id_t id3,char * &data,int &len);
|
int numbers_to_char(my_id_t id1,my_id_t id2,my_id_t id3,char * &data,int &len);
|
||||||
int char_to_numbers(const char * data,int len,id_t &id1,id_t &id2,id_t &id3);
|
int char_to_numbers(const char * data,int len,my_id_t &id1,my_id_t &id2,my_id_t &id3);
|
||||||
|
|
||||||
const int show_none=0;
|
const int show_none=0;
|
||||||
const int show_command=0x1;
|
const int show_command=0x1;
|
||||||
|
@ -559,7 +559,7 @@ int recv_bare(raw_info_t &raw_info,char* & data,int & len)//recv function with e
|
|||||||
return reserved_parse_bare(data,len,data,len);
|
return reserved_parse_bare(data,len,data,len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int send_handshake(raw_info_t &raw_info,id_t id1,id_t id2,id_t id3)// a warp for send_bare for sending handshake(this is not tcp handshake) easily
|
int send_handshake(raw_info_t &raw_info,my_id_t id1,my_id_t id2,my_id_t id3)// a warp for send_bare for sending handshake(this is not tcp handshake) easily
|
||||||
{
|
{
|
||||||
packet_info_t &send_info=raw_info.send_info;
|
packet_info_t &send_info=raw_info.send_info;
|
||||||
packet_info_t &recv_info=raw_info.recv_info;
|
packet_info_t &recv_info=raw_info.recv_info;
|
||||||
@ -600,7 +600,7 @@ int send_safer(conn_info_t &conn_info,char type,const char* data,int len) //saf
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
id_t n_tmp_id=htonl(conn_info.my_id);
|
my_id_t n_tmp_id=htonl(conn_info.my_id);
|
||||||
|
|
||||||
memcpy(send_data_buf,&n_tmp_id,sizeof(n_tmp_id));
|
memcpy(send_data_buf,&n_tmp_id,sizeof(n_tmp_id));
|
||||||
|
|
||||||
@ -662,18 +662,18 @@ int reserved_parse_safer(conn_info_t &conn_info,const char * input,int input_len
|
|||||||
|
|
||||||
//char *a=recv_data_buf;
|
//char *a=recv_data_buf;
|
||||||
//id_t h_oppiste_id= ntohl ( *((id_t * )(recv_data_buf)) );
|
//id_t h_oppiste_id= ntohl ( *((id_t * )(recv_data_buf)) );
|
||||||
id_t h_oppsite_id;
|
my_id_t h_oppsite_id;
|
||||||
memcpy(&h_oppsite_id,recv_data_buf,sizeof(h_oppsite_id));
|
memcpy(&h_oppsite_id,recv_data_buf,sizeof(h_oppsite_id));
|
||||||
h_oppsite_id=ntohl(h_oppsite_id);
|
h_oppsite_id=ntohl(h_oppsite_id);
|
||||||
|
|
||||||
//id_t h_my_id= ntohl ( *((id_t * )(recv_data_buf+sizeof(id_t))) );
|
//id_t h_my_id= ntohl ( *((id_t * )(recv_data_buf+sizeof(id_t))) );
|
||||||
id_t h_my_id;
|
my_id_t h_my_id;
|
||||||
memcpy(&h_my_id,recv_data_buf+sizeof(id_t),sizeof(h_my_id));
|
memcpy(&h_my_id,recv_data_buf+sizeof(my_id_t),sizeof(h_my_id));
|
||||||
h_my_id=ntohl(h_my_id);
|
h_my_id=ntohl(h_my_id);
|
||||||
|
|
||||||
//anti_replay_seq_t h_seq= ntoh64 ( *((anti_replay_seq_t * )(recv_data_buf +sizeof(id_t) *2 )) );
|
//anti_replay_seq_t h_seq= ntoh64 ( *((anti_replay_seq_t * )(recv_data_buf +sizeof(id_t) *2 )) );
|
||||||
anti_replay_seq_t h_seq;
|
anti_replay_seq_t h_seq;
|
||||||
memcpy(&h_seq,recv_data_buf +sizeof(id_t) *2 ,sizeof(h_seq));
|
memcpy(&h_seq,recv_data_buf +sizeof(my_id_t) *2 ,sizeof(h_seq));
|
||||||
h_seq=ntoh64(h_seq);
|
h_seq=ntoh64(h_seq);
|
||||||
|
|
||||||
if(h_oppsite_id!=conn_info.oppsite_id||h_my_id!=conn_info.my_id)
|
if(h_oppsite_id!=conn_info.oppsite_id||h_my_id!=conn_info.my_id)
|
||||||
@ -688,8 +688,8 @@ int reserved_parse_safer(conn_info_t &conn_info,const char * input,int input_len
|
|||||||
}
|
}
|
||||||
|
|
||||||
//printf("recv _len %d\n ",recv_len);
|
//printf("recv _len %d\n ",recv_len);
|
||||||
data=recv_data_buf+sizeof(anti_replay_seq_t)+sizeof(id_t)*2;
|
data=recv_data_buf+sizeof(anti_replay_seq_t)+sizeof(my_id_t)*2;
|
||||||
len=input_len-(sizeof(anti_replay_seq_t)+sizeof(id_t)*2 );
|
len=input_len-(sizeof(anti_replay_seq_t)+sizeof(my_id_t)*2 );
|
||||||
|
|
||||||
|
|
||||||
if(data[0]!='h'&&data[0]!='d')
|
if(data[0]!='h'&&data[0]!='d')
|
||||||
|
10
connection.h
10
connection.h
@ -81,13 +81,13 @@ struct conn_info_t //stores info for a raw connection.for client ,there is o
|
|||||||
u64_t last_hb_recv_time;
|
u64_t last_hb_recv_time;
|
||||||
//long long last_resent_time;
|
//long long last_resent_time;
|
||||||
|
|
||||||
id_t my_id;
|
my_id_t my_id;
|
||||||
id_t oppsite_id;
|
my_id_t oppsite_id;
|
||||||
|
|
||||||
|
|
||||||
fd64_t timer_fd64;
|
fd64_t timer_fd64;
|
||||||
|
|
||||||
id_t oppsite_const_id;
|
my_id_t oppsite_const_id;
|
||||||
|
|
||||||
blob_t *blob;
|
blob_t *blob;
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ struct conn_manager_t //manager for connections. for client,we dont need conn_m
|
|||||||
//unordered_map<int,conn_info_t *> udp_fd_mp; //a bit dirty to used pointer,but can void unordered_map search
|
//unordered_map<int,conn_info_t *> udp_fd_mp; //a bit dirty to used pointer,but can void unordered_map search
|
||||||
//unordered_map<int,conn_info_t *> timer_fd_mp;//we can use pointer here since unordered_map.rehash() uses shallow copy
|
//unordered_map<int,conn_info_t *> timer_fd_mp;//we can use pointer here since unordered_map.rehash() uses shallow copy
|
||||||
|
|
||||||
unordered_map<id_t,conn_info_t *> const_id_mp;
|
unordered_map<my_id_t,conn_info_t *> const_id_mp;
|
||||||
|
|
||||||
unordered_map<u64_t,conn_info_t*> mp; //put it at end so that it de-consturcts first
|
unordered_map<u64_t,conn_info_t*> mp; //put it at end so that it de-consturcts first
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ int send_bare(raw_info_t &raw_info,const char* data,int len);//send function wit
|
|||||||
//int reserved_parse_bare(const char *input,int input_len,char* & data,int & len); // a sub function used in recv_bare
|
//int reserved_parse_bare(const char *input,int input_len,char* & data,int & len); // a sub function used in recv_bare
|
||||||
int recv_bare(raw_info_t &raw_info,char* & data,int & len);//recv function with encryption but no anti replay,this is used when client and server verifys each other
|
int recv_bare(raw_info_t &raw_info,char* & data,int & len);//recv function with encryption but no anti replay,this is used when client and server verifys each other
|
||||||
//you have to design the protocol carefully, so that you wont be affect by relay attack
|
//you have to design the protocol carefully, so that you wont be affect by relay attack
|
||||||
int send_handshake(raw_info_t &raw_info,id_t id1,id_t id2,id_t id3);// a warp for send_bare for sending handshake(this is not tcp handshake) easily
|
int send_handshake(raw_info_t &raw_info,my_id_t id1,my_id_t id2,my_id_t id3);// a warp for send_bare for sending handshake(this is not tcp handshake) easily
|
||||||
int send_safer(conn_info_t &conn_info,char type,const char* data,int len); //safer transfer function with anti-replay,when mutually verification is done.
|
int send_safer(conn_info_t &conn_info,char type,const char* data,int len); //safer transfer function with anti-replay,when mutually verification is done.
|
||||||
int send_data_safer(conn_info_t &conn_info,const char* data,int len,u32_t conv_num);//a wrap for send_safer for transfer data.
|
int send_data_safer(conn_info_t &conn_info,const char* data,int len,u32_t conv_num);//a wrap for send_safer for transfer data.
|
||||||
//int reserved_parse_safer(conn_info_t &conn_info,const char * input,int input_len,char &type,char* &data,int &len);//subfunction for recv_safer,allow overlap
|
//int reserved_parse_safer(conn_info_t &conn_info,const char * input,int input_len,char &type,char* &data,int &len);//subfunction for recv_safer,allow overlap
|
||||||
|
12
main.cpp
12
main.cpp
@ -332,21 +332,21 @@ int client_on_raw_recv(conn_info_t &conn_info) //called when raw fd received a p
|
|||||||
mylog(log_debug,"unexpected adress %x %x %d %d\n",recv_info.src_ip,send_info.dst_ip,recv_info.src_port,send_info.dst_port);
|
mylog(log_debug,"unexpected adress %x %x %d %d\n",recv_info.src_ip,send_info.dst_ip,recv_info.src_port,send_info.dst_port);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(data_len<int( 3*sizeof(id_t)))
|
if(data_len<int( 3*sizeof(my_id_t)))
|
||||||
{
|
{
|
||||||
mylog(log_debug,"too short to be a handshake\n");
|
mylog(log_debug,"too short to be a handshake\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
id_t tmp_oppsite_id;
|
my_id_t tmp_oppsite_id;
|
||||||
memcpy(&tmp_oppsite_id,&data[0],sizeof(tmp_oppsite_id));
|
memcpy(&tmp_oppsite_id,&data[0],sizeof(tmp_oppsite_id));
|
||||||
tmp_oppsite_id=ntohl(tmp_oppsite_id);
|
tmp_oppsite_id=ntohl(tmp_oppsite_id);
|
||||||
|
|
||||||
id_t tmp_my_id;
|
my_id_t tmp_my_id;
|
||||||
memcpy(&tmp_my_id,&data[sizeof(id_t)],sizeof(tmp_my_id));
|
memcpy(&tmp_my_id,&data[sizeof(my_id_t)],sizeof(tmp_my_id));
|
||||||
tmp_my_id=ntohl(tmp_my_id);
|
tmp_my_id=ntohl(tmp_my_id);
|
||||||
|
|
||||||
id_t tmp_oppsite_const_id;
|
my_id_t tmp_oppsite_const_id;
|
||||||
memcpy(&tmp_oppsite_const_id,&data[sizeof(id_t)*2],sizeof(tmp_oppsite_const_id));
|
memcpy(&tmp_oppsite_const_id,&data[sizeof(my_id_t)*2],sizeof(tmp_oppsite_const_id));
|
||||||
tmp_oppsite_const_id=ntohl(tmp_oppsite_const_id);
|
tmp_oppsite_const_id=ntohl(tmp_oppsite_const_id);
|
||||||
|
|
||||||
if(tmp_my_id!=conn_info.my_id)
|
if(tmp_my_id!=conn_info.my_id)
|
||||||
|
2
misc.cpp
2
misc.cpp
@ -35,7 +35,7 @@ int local_port = -1, remote_port=-1,source_port=0;//similiar to local_ip remote
|
|||||||
|
|
||||||
int force_source_ip=0; //if --source-ip is enabled
|
int force_source_ip=0; //if --source-ip is enabled
|
||||||
|
|
||||||
id_t const_id=0;//an id used for connection recovery,its generated randomly,it never change since its generated
|
my_id_t const_id=0;//an id used for connection recovery,its generated randomly,it never change since its generated
|
||||||
|
|
||||||
int udp_fd=-1; //for client only. client use this fd to listen and handle udp connection
|
int udp_fd=-1; //for client only. client use this fd to listen and handle udp connection
|
||||||
int bind_fd=-1; //bind only,never send or recv. its just a dummy fd for bind,so that other program wont occupy the same port
|
int bind_fd=-1; //bind only,never send or recv. its just a dummy fd for bind,so that other program wont occupy the same port
|
||||||
|
2
misc.h
2
misc.h
@ -80,7 +80,7 @@ extern int local_port , remote_port,source_port;//similiar to local_ip remote_i
|
|||||||
|
|
||||||
extern int force_source_ip; //if --source-ip is enabled
|
extern int force_source_ip; //if --source-ip is enabled
|
||||||
|
|
||||||
extern id_t const_id;//an id used for connection recovery,its generated randomly,it never change since its generated
|
extern my_id_t const_id;//an id used for connection recovery,its generated randomly,it never change since its generated
|
||||||
|
|
||||||
extern int udp_fd; //for client only. client use this fd to listen and handle udp connection
|
extern int udp_fd; //for client only. client use this fd to listen and handle udp connection
|
||||||
extern int bind_fd; //bind only,never send or recv. its just a dummy fd for bind,so that other program wont occupy the same port
|
extern int bind_fd; //bind only,never send or recv. its just a dummy fd for bind,so that other program wont occupy the same port
|
||||||
|
Loading…
x
Reference in New Issue
Block a user