mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 14:29:34 +08:00
sync a few mp version update
This commit is contained in:
parent
10869eb197
commit
278ade5d36
14
common.cpp
14
common.cpp
@ -586,11 +586,11 @@ int set_buf_size(int fd,int socket_buf_size)
|
|||||||
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);
|
||||||
@ -599,21 +599,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
@ -100,7 +100,7 @@ typedef int i32_t;
|
|||||||
typedef unsigned short u16_t;
|
typedef unsigned short u16_t;
|
||||||
typedef short i16_t;
|
typedef short i16_t;
|
||||||
|
|
||||||
typedef u32_t id_t;
|
typedef u32_t my_id_t;
|
||||||
|
|
||||||
typedef u64_t iv_t;
|
typedef u64_t iv_t;
|
||||||
|
|
||||||
@ -344,8 +344,8 @@ void myexit(int a);
|
|||||||
unsigned short csum(const unsigned short *ptr,int nbytes);
|
unsigned short csum(const unsigned short *ptr,int nbytes);
|
||||||
unsigned short csum_with_header(char* header,int hlen,const unsigned short *ptr,int nbytes);
|
unsigned short csum_with_header(char* header,int hlen,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;
|
||||||
|
@ -429,7 +429,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;
|
||||||
@ -470,7 +470,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));
|
||||||
|
|
||||||
@ -532,18 +532,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)
|
||||||
@ -558,8 +558,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
@ -240,14 +240,14 @@ 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;
|
||||||
fd64_t udp_fd64;
|
fd64_t udp_fd64;
|
||||||
|
|
||||||
id_t oppsite_const_id;
|
my_id_t oppsite_const_id;
|
||||||
|
|
||||||
blob_t *blob;
|
blob_t *blob;
|
||||||
|
|
||||||
@ -279,7 +279,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<address_t,conn_info_t*> mp; //put it at end so that it de-consturcts first
|
unordered_map<address_t,conn_info_t*> mp; //put it at end so that it de-consturcts first
|
||||||
|
|
||||||
@ -319,7 +319,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
|
||||||
|
40
main.cpp
40
main.cpp
@ -190,7 +190,7 @@ int client_on_timer(conn_info_t &conn_info) //for client. called when a timer is
|
|||||||
|
|
||||||
send_handshake(raw_info,conn_info.my_id,0,const_id);
|
send_handshake(raw_info,conn_info.my_id,0,const_id);
|
||||||
if(raw_mode==mode_icmp)
|
if(raw_mode==mode_icmp)
|
||||||
send_info.icmp_seq++;
|
send_info.my_icmp_seq++;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn_info.last_hb_sent_time=get_current_time();
|
conn_info.last_hb_sent_time=get_current_time();
|
||||||
@ -231,7 +231,7 @@ int client_on_timer(conn_info_t &conn_info) //for client. called when a timer is
|
|||||||
|
|
||||||
send_handshake(raw_info,conn_info.my_id,conn_info.oppsite_id,const_id);
|
send_handshake(raw_info,conn_info.my_id,conn_info.oppsite_id,const_id);
|
||||||
if(raw_mode==mode_icmp)
|
if(raw_mode==mode_icmp)
|
||||||
send_info.icmp_seq++;
|
send_info.my_icmp_seq++;
|
||||||
}
|
}
|
||||||
conn_info.last_hb_sent_time=get_current_time();
|
conn_info.last_hb_sent_time=get_current_time();
|
||||||
mylog(log_info,"(re)sent handshake2\n");
|
mylog(log_info,"(re)sent handshake2\n");
|
||||||
@ -350,24 +350,24 @@ int client_on_raw_recv(conn_info_t &conn_info) //called when raw fd received a p
|
|||||||
mylog(log_debug,"unexpected adress %s %s %d %d\n",recv_info.new_src_ip.get_str1(),send_info.new_dst_ip.get_str2(),recv_info.src_port,send_info.dst_port);
|
mylog(log_debug,"unexpected adress %s %s %d %d\n",recv_info.new_src_ip.get_str1(),send_info.new_dst_ip.get_str2(),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= ntohl(* ((u32_t *)&data[0]));
|
//id_t tmp_oppsite_id= ntohl(* ((u32_t *)&data[0]));
|
||||||
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=ntohl(* ((u32_t *)&data[sizeof(id_t)]));
|
//id_t tmp_my_id=ntohl(* ((u32_t *)&data[sizeof(id_t)]));
|
||||||
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=ntohl(* ((u32_t *)&data[sizeof(id_t)*2]));
|
//id_t tmp_oppsite_const_id=ntohl(* ((u32_t *)&data[sizeof(id_t)*2]));
|
||||||
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)
|
||||||
@ -670,7 +670,7 @@ int server_on_raw_recv_ready(conn_info_t &conn_info,char * ip_port,char type,cha
|
|||||||
{
|
{
|
||||||
|
|
||||||
//u32_t tmp_conv_id = ntohl(*((u32_t *) &data[0]));
|
//u32_t tmp_conv_id = ntohl(*((u32_t *) &data[0]));
|
||||||
id_t tmp_conv_id;
|
my_id_t tmp_conv_id;
|
||||||
memcpy(&tmp_conv_id,&data[0],sizeof(tmp_conv_id));
|
memcpy(&tmp_conv_id,&data[0],sizeof(tmp_conv_id));
|
||||||
tmp_conv_id=ntohl(tmp_conv_id);
|
tmp_conv_id=ntohl(tmp_conv_id);
|
||||||
|
|
||||||
@ -920,19 +920,19 @@ int server_on_raw_recv_handshake1(conn_info_t &conn_info,char * ip_port,char * d
|
|||||||
//char ip_port[40];
|
//char ip_port[40];
|
||||||
//sprintf(ip_port,"%s:%d",my_ntoa(ip),port);
|
//sprintf(ip_port,"%s:%d",my_ntoa(ip),port);
|
||||||
|
|
||||||
if(data_len<int( 3*sizeof(id_t)))
|
if(data_len<int( 3*sizeof(my_id_t)))
|
||||||
{
|
{
|
||||||
mylog(log_debug,"[%s] data_len=%d too short to be a handshake\n",ip_port,data_len);
|
mylog(log_debug,"[%s] data_len=%d too short to be a handshake\n",ip_port,data_len);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
//id_t tmp_oppsite_id= ntohl(* ((u32_t *)&data[0]));
|
//id_t tmp_oppsite_id= ntohl(* ((u32_t *)&data[0]));
|
||||||
id_t tmp_oppsite_id;
|
my_id_t tmp_oppsite_id;
|
||||||
memcpy(&tmp_oppsite_id,(u32_t *)&data[0],sizeof(tmp_oppsite_id));
|
memcpy(&tmp_oppsite_id,(u32_t *)&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=ntohl(* ((u32_t *)&data[sizeof(id_t)]));
|
//id_t tmp_my_id=ntohl(* ((u32_t *)&data[sizeof(id_t)]));
|
||||||
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);
|
||||||
|
|
||||||
if(tmp_my_id==0) //received init handshake again
|
if(tmp_my_id==0) //received init handshake again
|
||||||
@ -945,7 +945,7 @@ int server_on_raw_recv_handshake1(conn_info_t &conn_info,char * ip_port,char * d
|
|||||||
}
|
}
|
||||||
if(raw_mode==mode_icmp)
|
if(raw_mode==mode_icmp)
|
||||||
{
|
{
|
||||||
send_info.icmp_seq=recv_info.icmp_seq;
|
send_info.my_icmp_seq=recv_info.my_icmp_seq;
|
||||||
}
|
}
|
||||||
send_handshake(raw_info,conn_info.my_id,tmp_oppsite_id,const_id); //////////////send
|
send_handshake(raw_info,conn_info.my_id,tmp_oppsite_id,const_id); //////////////send
|
||||||
|
|
||||||
@ -956,8 +956,8 @@ int server_on_raw_recv_handshake1(conn_info_t &conn_info,char * ip_port,char * d
|
|||||||
conn_info.oppsite_id=tmp_oppsite_id;
|
conn_info.oppsite_id=tmp_oppsite_id;
|
||||||
//id_t tmp_oppsite_const_id=ntohl(* ((u32_t *)&data[sizeof(id_t)*2]));
|
//id_t tmp_oppsite_const_id=ntohl(* ((u32_t *)&data[sizeof(id_t)*2]));
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
|
||||||
@ -970,7 +970,7 @@ int server_on_raw_recv_handshake1(conn_info_t &conn_info,char * ip_port,char * d
|
|||||||
|
|
||||||
if(raw_mode==mode_icmp)
|
if(raw_mode==mode_icmp)
|
||||||
{
|
{
|
||||||
send_info.icmp_seq=recv_info.icmp_seq;
|
send_info.my_icmp_seq=recv_info.my_icmp_seq;
|
||||||
}
|
}
|
||||||
|
|
||||||
server_on_raw_recv_pre_ready(conn_info,ip_port,tmp_oppsite_const_id);
|
server_on_raw_recv_pre_ready(conn_info,ip_port,tmp_oppsite_const_id);
|
||||||
@ -1086,15 +1086,15 @@ int server_on_raw_recv_multi() //called when server received an raw packet
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(data_len<int( 3*sizeof(id_t)))
|
if(data_len<int( 3*sizeof(my_id_t)))
|
||||||
{
|
{
|
||||||
mylog(log_debug,"[%s]too short to be a handshake\n",ip_port);
|
mylog(log_debug,"[%s]too short to be a handshake\n",ip_port);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//id_t zero=ntohl(* ((u32_t *)&data[sizeof(id_t)]));
|
//id_t zero=ntohl(* ((u32_t *)&data[sizeof(id_t)]));
|
||||||
id_t zero;
|
my_id_t zero;
|
||||||
memcpy(&zero,&data[sizeof(id_t)],sizeof(zero));
|
memcpy(&zero,&data[sizeof(my_id_t)],sizeof(zero));
|
||||||
zero=ntohl(zero);
|
zero=ntohl(zero);
|
||||||
|
|
||||||
if(zero!=0)
|
if(zero!=0)
|
||||||
|
2
misc.cpp
2
misc.cpp
@ -42,7 +42,7 @@ int bind_addr_used=0;
|
|||||||
int force_source_ip=0; //if --source-ip is enabled
|
int force_source_ip=0; //if --source-ip is enabled
|
||||||
int force_source_port=0;
|
int force_source_port=0;
|
||||||
|
|
||||||
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
@ -87,7 +87,7 @@ extern int force_source_ip; //if --source-ip is enabled
|
|||||||
extern int force_source_port;
|
extern int force_source_port;
|
||||||
extern int source_port;
|
extern int source_port;
|
||||||
|
|
||||||
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
|
||||||
|
12
network.cpp
12
network.cpp
@ -248,7 +248,7 @@ packet_info_t::packet_info_t()
|
|||||||
assert(raw_ip_version==AF_INET6);
|
assert(raw_ip_version==AF_INET6);
|
||||||
protocol = IPPROTO_ICMPV6;
|
protocol = IPPROTO_ICMPV6;
|
||||||
}
|
}
|
||||||
icmp_seq=0;
|
my_icmp_seq=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1125,7 +1125,7 @@ int send_raw_icmp(raw_info_t &raw_info, const char * payload, int payloadlen)
|
|||||||
icmph->code=0;
|
icmph->code=0;
|
||||||
icmph->id=htons(send_info.src_port);
|
icmph->id=htons(send_info.src_port);
|
||||||
|
|
||||||
icmph->seq=htons(send_info.icmp_seq); /////////////modify
|
icmph->seq=htons(send_info.my_icmp_seq); /////////////modify
|
||||||
|
|
||||||
memcpy(send_raw_icmp_buf+sizeof(my_icmphdr),payload,payloadlen);
|
memcpy(send_raw_icmp_buf+sizeof(my_icmphdr),payload,payloadlen);
|
||||||
|
|
||||||
@ -1579,7 +1579,7 @@ int recv_raw_icmp(raw_info_t &raw_info, char *&payload, int &payloadlen)
|
|||||||
}
|
}
|
||||||
|
|
||||||
recv_info.src_port=recv_info.dst_port=ntohs(icmph->id);
|
recv_info.src_port=recv_info.dst_port=ntohs(icmph->id);
|
||||||
recv_info.icmp_seq=ntohs(icmph->seq);
|
recv_info.my_icmp_seq=ntohs(icmph->seq);
|
||||||
|
|
||||||
if(icmph->code!=0)
|
if(icmph->code!=0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -2293,7 +2293,7 @@ int after_send_raw0(raw_info_t &raw_info)
|
|||||||
{
|
{
|
||||||
if(program_mode==client_mode)
|
if(program_mode==client_mode)
|
||||||
{
|
{
|
||||||
send_info.icmp_seq++;
|
send_info.my_icmp_seq++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -2328,8 +2328,8 @@ int after_recv_raw0(raw_info_t &raw_info)
|
|||||||
{
|
{
|
||||||
if(program_mode==server_mode)
|
if(program_mode==server_mode)
|
||||||
{
|
{
|
||||||
if(larger_than_u16(recv_info.icmp_seq,send_info.icmp_seq))
|
if(larger_than_u16(recv_info.my_icmp_seq,send_info.my_icmp_seq))
|
||||||
send_info.icmp_seq = recv_info.icmp_seq; //TODO only update if its larger
|
send_info.my_icmp_seq = recv_info.my_icmp_seq; //TODO only update if its larger
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user