diff --git a/common.cpp b/common.cpp index a22e8ac..5d19595 100644 --- a/common.cpp +++ b/common.cpp @@ -586,11 +586,11 @@ int set_buf_size(int fd,int socket_buf_size) 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]; data=buf; - id_t tmp=htonl(id1); + my_id_t tmp=htonl(id1); memcpy(buf,&tmp,sizeof(tmp)); 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); memcpy(buf+sizeof(tmp)*2,&tmp,sizeof(tmp)); - len=sizeof(id_t)*3; + len=sizeof(my_id_t)*3; 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 udp_fd_mp; //a bit dirty to used pointer,but can void unordered_map search //unordered_map timer_fd_mp;//we can use pointer here since unordered_map.rehash() uses shallow copy - unordered_map const_id_mp; + unordered_map const_id_mp; unordered_map 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 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 -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_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 diff --git a/main.cpp b/main.cpp index 3011f06..feef5d6 100755 --- a/main.cpp +++ b/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); if(raw_mode==mode_icmp) - send_info.icmp_seq++; + send_info.my_icmp_seq++; } 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); if(raw_mode==mode_icmp) - send_info.icmp_seq++; + send_info.my_icmp_seq++; } conn_info.last_hb_sent_time=get_current_time(); 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); return -1; } - if(data_lencode=0; 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); @@ -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.icmp_seq=ntohs(icmph->seq); + recv_info.my_icmp_seq=ntohs(icmph->seq); if(icmph->code!=0) return -1; @@ -2293,7 +2293,7 @@ int after_send_raw0(raw_info_t &raw_info) { if(program_mode==client_mode) { - send_info.icmp_seq++; + send_info.my_icmp_seq++; } } return 0; @@ -2328,8 +2328,8 @@ int after_recv_raw0(raw_info_t &raw_info) { if(program_mode==server_mode) { - if(larger_than_u16(recv_info.icmp_seq,send_info.icmp_seq)) - send_info.icmp_seq = recv_info.icmp_seq; //TODO only update if its larger + if(larger_than_u16(recv_info.my_icmp_seq,send_info.my_icmp_seq)) + send_info.my_icmp_seq = recv_info.my_icmp_seq; //TODO only update if its larger } } return 0; diff --git a/network.h b/network.h index 35428f4..f5d5635 100644 --- a/network.h +++ b/network.h @@ -208,7 +208,7 @@ struct packet_info_t //todo change this to union u32_t ts,ts_ack; - uint16_t icmp_seq; + uint16_t my_icmp_seq; bool has_ts;