From d3290a9a94eccaf7da42f0f0dd7c41459f25a88d Mon Sep 17 00:00:00 2001 From: wangyu- Date: Thu, 31 Aug 2017 10:36:33 -0500 Subject: [PATCH] fixed possible alignment issue --- common.cpp | 16 +++++++--- doc/README.zh-cn.md | 4 +++ images/route.PNG | Bin 0 -> 17806 bytes main.cpp | 75 ++++++++++++++++++++++++++++++++++---------- makefile | 1 + network.cpp | 49 ++++++++++++++++++++--------- 6 files changed, 110 insertions(+), 35 deletions(-) create mode 100644 images/route.PNG diff --git a/common.cpp b/common.cpp index 3dd1fc8..2aaf085 100644 --- a/common.cpp +++ b/common.cpp @@ -330,12 +330,12 @@ int set_buf_size(int fd) { if(setsockopt(fd, SOL_SOCKET, SO_SNDBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0) { - mylog(log_fatal,"SO_SNDBUFFORCE fail,fd %d\n",fd); + mylog(log_fatal,"SO_SNDBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno)); myexit(1); } if(setsockopt(fd, SOL_SOCKET, SO_RCVBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0) { - mylog(log_fatal,"SO_RCVBUFFORCE fail,fd %d\n",fd); + mylog(log_fatal,"SO_RCVBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno)); myexit(1); } return 0; @@ -386,9 +386,15 @@ int numbers_to_char(id_t id1,id_t id2,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) { if(len`,记下第一跳的地址,这个就是`网关ip`。再运行`arp -s <网关ip>`,可以同时查到出口网卡名和mac。 ![](/images/lower_level.PNG) + +如果traceroute第一跳结果是`* * *`,说明网关屏蔽了对traceroute的应答。需要用`ip route`或`route`查询网关: + +![](/images/route.PNG) ##### server端获得--lower-level参数的办法 如果client有公网ip,就`traceroute `。下一步和client端的方法一样。 diff --git a/images/route.PNG b/images/route.PNG new file mode 100644 index 0000000000000000000000000000000000000000..8433e51907a80f7d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7q(+4iP}x1KxCTJ?KN#QffGl?5+<+z!0@&Br#Vm(eQa_>nE`3+9Up z-8*@EzK_n`y3XHg9K90#{X^_e{5bvoNKEm4skvok$KR`bZryBqE_e0690A7+1Bu5{ z8IE4MZzjo~w}=Q?RbLeI)&JDIU<0WI#ZlLuPrBvZ_Q?HzSaf{FCex{>x6Q3>-*iT9 z&a_Ys_tU$!O_rQgCZ+(+Jr%jPudiMx^TvNc-KPaHTl;}ccSDQk;!b6b%jE8@ydD4f z$Km8E_oI>9zTbeR+51xS%WRiTGhVe`yTT_k&O1m)jr_aA} z;{11T*>YeW&+S`~mW(x|m|^HZYR5RJ7c~fg6efNXSd#a$Zt{iO{^s9)?^OI)?fvRr woo%(>{Q1D8CkxHjznw1kWS$^MX^X<%GzG->boFyt=akR{0DZwP;{X5v literal 0 HcmV?d00001 diff --git a/main.cpp b/main.cpp index 6f2ac0e..16366f4 100755 --- a/main.cpp +++ b/main.cpp @@ -787,9 +787,9 @@ int send_data_safer(conn_info_t &conn_info,const char* data,int len,u32_t conv_n } int 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 { - static char recv_data_buf0[buf_len]; + static char recv_data_buf[buf_len]; - char *recv_data_buf=recv_data_buf0; //fix strict alias warning + // char *recv_data_buf=recv_data_buf0; //fix strict alias warning if(my_decrypt(input,recv_data_buf,input_len,key)!=0) { //printf("decrypt fail\n"); @@ -799,15 +799,24 @@ int parse_safer(conn_info_t &conn_info,const char * input,int input_len,char &ty //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; + memcpy(&h_oppsite_id,recv_data_buf,sizeof(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; + memcpy(&h_my_id,recv_data_buf+sizeof(id_t),sizeof(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; + memcpy(&h_seq,recv_data_buf +sizeof(id_t) *2 ,sizeof(h_seq)); + h_seq=ntoh64(h_seq); - if(h_oppiste_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) { - mylog(log_debug,"id and oppsite_id verification failed %x %x %x %x \n",h_oppiste_id,conn_info.oppsite_id,h_my_id,conn_info.my_id); + mylog(log_debug,"id and oppsite_id verification failed %x %x %x %x \n",h_oppsite_id,conn_info.oppsite_id,h_my_id,conn_info.my_id); return -1; } @@ -1331,9 +1340,20 @@ int client_on_raw_recv(conn_info_t &conn_info) //called when raw fd received a p mylog(log_debug,"too short to be a handshake\n"); return -1; } - id_t tmp_oppsite_id= ntohl(* ((u32_t *)&data[0])); - id_t tmp_my_id=ntohl(* ((u32_t *)&data[sizeof(id_t)])); - id_t tmp_oppsite_const_id=ntohl(* ((u32_t *)&data[sizeof(id_t)*2])); + //id_t tmp_oppsite_id= ntohl(* ((u32_t *)&data[0])); + id_t tmp_oppsite_id; + memcpy(&tmp_oppsite_id,&data[0],sizeof(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; + memcpy(&tmp_my_id,&data[sizeof(id_t)],sizeof(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; + memcpy(&tmp_oppsite_const_id,&data[sizeof(id_t)*2],sizeof(tmp_oppsite_const_id)); + tmp_oppsite_const_id=ntohl(tmp_oppsite_const_id); if(tmp_my_id!=conn_info.my_id) { @@ -1401,7 +1421,10 @@ int client_on_raw_recv(conn_info_t &conn_info) //called when raw fd received a p conn_info.last_hb_recv_time=get_current_time(); - u32_t tmp_conv_id= ntohl(* ((u32_t *)&data[0])); + //u32_t tmp_conv_id= ntohl(* ((u32_t *)&data[0])); + u32_t tmp_conv_id; + memcpy(&tmp_conv_id,&data[0],sizeof(tmp_conv_id)); + tmp_conv_id=ntohl(tmp_conv_id); if(!conn_info.blob->conv_manager.is_conv_used(tmp_conv_id)) { @@ -1566,7 +1589,11 @@ int server_on_raw_recv_multi() //called when server received an raw packet 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; + memcpy(&zero,&data[sizeof(id_t)],sizeof(zero)); + zero=ntohl(zero); + if(zero!=0) { mylog(log_debug,"[%s]not a invalid initial handshake\n",ip_port); @@ -1663,8 +1690,15 @@ int server_on_raw_recv_handshake1(conn_info_t &conn_info,char * ip_port,char * d mylog(log_debug,"[%s] data_len=%d too short to be a handshake\n",ip_port,data_len); return -1; } - id_t tmp_oppsite_id= ntohl(* ((u32_t *)&data[0])); - id_t tmp_my_id=ntohl(* ((u32_t *)&data[sizeof(id_t)])); + //id_t tmp_oppsite_id= ntohl(* ((u32_t *)&data[0])); + id_t tmp_oppsite_id; + memcpy(&tmp_oppsite_id,(u32_t *)&data[0],sizeof(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; + memcpy(&tmp_my_id,&data[sizeof(id_t)],sizeof(tmp_my_id)); + tmp_my_id=ntohl(tmp_my_id); if(tmp_my_id==0) //received init handshake again { @@ -1685,7 +1719,12 @@ int server_on_raw_recv_handshake1(conn_info_t &conn_info,char * ip_port,char * d else if(tmp_my_id==conn_info.my_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; + memcpy(&tmp_oppsite_const_id,&data[sizeof(id_t)*2],sizeof(tmp_oppsite_const_id)); + tmp_oppsite_const_id=ntohl(tmp_oppsite_const_id); + if(raw_mode==mode_faketcp) { @@ -1735,7 +1774,11 @@ int server_on_raw_recv_ready(conn_info_t &conn_info,char * ip_port,char type,cha } else if (type== 'd' && data_len >=int( sizeof(u32_t) )) { - 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; + memcpy(&tmp_conv_id,&data[0],sizeof(tmp_conv_id)); + tmp_conv_id=ntohl(tmp_conv_id); + conn_info.last_hb_recv_time = get_current_time(); diff --git a/makefile b/makefile index 006a022..641c49c 100755 --- a/makefile +++ b/makefile @@ -1,6 +1,7 @@ cc_cross=/home/wangyu/Desktop/arm-2014.05/bin/arm-none-linux-gnueabi-g++ cc_local=g++ cc_mips34kc=/toolchains/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++ +#cc_arm= /toolchains/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-g++ -march=armv6 -marm cc_arm= /toolchains/arm-2014.05/bin/arm-none-linux-gnueabi-g++ #cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++ FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers diff --git a/network.cpp b/network.cpp index 67dd4e1..fde70ca 100644 --- a/network.cpp +++ b/network.cpp @@ -201,7 +201,7 @@ int init_raw_socket() if(setsockopt(raw_send_fd, SOL_SOCKET, SO_SNDBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0) { - mylog(log_fatal,"SO_SNDBUFFORCE fail\n"); + mylog(log_fatal,"SO_SNDBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno)); myexit(1); } @@ -219,7 +219,7 @@ int init_raw_socket() if(setsockopt(raw_recv_fd, SOL_SOCKET, SO_RCVBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0) { - mylog(log_fatal,"SO_RCVBUFFORCE fail\n"); + mylog(log_fatal,"SO_RCVBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno)); myexit(1); } @@ -844,8 +844,8 @@ int send_raw_tcp(raw_info_t &raw_info,const char * payload, int payloadlen) { //mylog(log_debug,"syn %d\n",send_info.syn); - char send_raw_tcp_buf0[buf_len]; - char *send_raw_tcp_buf=send_raw_tcp_buf0; + char send_raw_tcp_buf[buf_len]; + //char *send_raw_tcp_buf=send_raw_tcp_buf0; struct tcphdr *tcph = (struct tcphdr *) (send_raw_tcp_buf + sizeof(struct pseudo_header)); @@ -884,14 +884,20 @@ int send_raw_tcp(raw_info_t &raw_info,const char * payload, int payloadlen) { send_raw_tcp_buf[i++] = 0x08; //ts i=6 send_raw_tcp_buf[i++] = 0x0a; //i=7 - *(u32_t*) (&send_raw_tcp_buf[i]) = htonl( - (u32_t) get_current_time()); + //*(u32_t*) (&send_raw_tcp_buf[i]) = htonl( + // (u32_t) get_current_time()); + + u32_t ts=htonl((u32_t) get_current_time()); + memcpy(&send_raw_tcp_buf[i],&ts,sizeof(ts)); i += 4; //mylog(log_info,"[syn]\n",send_info.ts_ack); - *(u32_t*) (&send_raw_tcp_buf[i]) = htonl(send_info.ts_ack); + //*(u32_t*) (&send_raw_tcp_buf[i]) = htonl(send_info.ts_ack); + u32_t ts_ack=htonl(send_info.ts_ack); + memcpy(&send_raw_tcp_buf[i],&ts_ack,sizeof(ts_ack)); + i += 4; send_raw_tcp_buf[i++] = 0x01; @@ -908,14 +914,19 @@ int send_raw_tcp(raw_info_t &raw_info,const char * payload, int payloadlen) { send_raw_tcp_buf[i++] = 0x08; //ts //i=2 send_raw_tcp_buf[i++] = 0x0a; //i=3; - *(u32_t*) (&send_raw_tcp_buf[i]) = htonl( - (u32_t) get_current_time()); + //*(u32_t*) (&send_raw_tcp_buf[i]) = htonl( + // (u32_t) get_current_time()); + + u32_t ts=htonl((u32_t) get_current_time()); + memcpy(&send_raw_tcp_buf[i],&ts,sizeof(ts)); i += 4; //mylog(log_info,"\n",send_info.ts_ack); - *(u32_t*) (&send_raw_tcp_buf[i]) = htonl(send_info.ts_ack); + //*(u32_t*) (&send_raw_tcp_buf[i]) = htonl(send_info.ts_ack); + u32_t ts_ack=htonl(send_info.ts_ack); + memcpy(&send_raw_tcp_buf[i],&ts_ack,sizeof(ts_ack)); i += 4; } @@ -1334,8 +1345,14 @@ int recv_raw_tcp(raw_info_t &raw_info,char * &payload,int &payloadlen) if(tcp_option[6]==0x08 &&tcp_option[7]==0x0a) { recv_info.has_ts=1; - recv_info.ts=ntohl(*(u32_t*)(&tcp_option[8])); - recv_info.ts_ack=ntohl(*(u32_t*)(&tcp_option[12])); + //recv_info.ts=ntohl(*(u32_t*)(&tcp_option[8])); + memcpy(&recv_info.ts,&tcp_option[8],sizeof(recv_info.ts)); + recv_info.ts=ntohl(recv_info.ts); + + //recv_info.ts_ack=ntohl(*(u32_t*)(&tcp_option[12])); + memcpy(&recv_info.ts_ack,&tcp_option[12],sizeof(recv_info.ts_ack)); + recv_info.ts_ack=ntohl(recv_info.ts_ack); + //g_packet_info_send.ts_ack= ntohl(*(uint32_t*)(&tcp_option[8])); } else @@ -1348,8 +1365,12 @@ int recv_raw_tcp(raw_info_t &raw_info,char * &payload,int &payloadlen) if(tcp_option[2]==0x08 &&tcp_option[3]==0x0a) { recv_info.has_ts=1; - recv_info.ts=ntohl(*(u32_t*)(&tcp_option[4])); - recv_info.ts_ack=ntohl(*(u32_t*)(&tcp_option[8])); + //recv_info.ts=ntohl(*(u32_t*)(&tcp_option[4])); + memcpy(&recv_info.ts,&tcp_option[4],sizeof(recv_info.ts)); + recv_info.ts=ntohl(recv_info.ts); + //recv_info.ts_ack=ntohl(*(u32_t*)(&tcp_option[8])); + memcpy(&recv_info.ts_ack,&tcp_option[8],sizeof(recv_info.ts_ack)); + recv_info.ts_ack=ntohl(recv_info.ts_ack); //g_packet_info_send.ts_ack= ntohl(*(uint32_t*)(&tcp_option[0])); } else