mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 06:19:31 +08:00
fixed possible alignment issue
This commit is contained in:
parent
16a9b3ba89
commit
d3290a9a94
16
common.cpp
16
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<int(sizeof(id_t)*3)) return -1;
|
||||
id1=ntohl( *((id_t*)(data+0)) );
|
||||
id2=ntohl( *((id_t*)(data+sizeof(id_t))) );
|
||||
id3=ntohl( *((id_t*)(data+sizeof(id_t)*2)) );
|
||||
//id1=ntohl( *((id_t*)(data+0)) );
|
||||
memcpy(&id1,data+0,sizeof(id1));
|
||||
id1=ntohl(id1);
|
||||
//id2=ntohl( *((id_t*)(data+sizeof(id_t))) );
|
||||
memcpy(&id2,data+sizeof(id_t),sizeof(id2));
|
||||
id2=ntohl(id2);
|
||||
//id3=ntohl( *((id_t*)(data+sizeof(id_t)*2)) );
|
||||
memcpy(&id3,data+sizeof(id_t)*2,sizeof(id3));
|
||||
id3=ntohl(id3);
|
||||
return 0;
|
||||
}
|
||||
int hex_to_u32(const string & a,u32_t &output)
|
||||
|
@ -159,6 +159,10 @@ facktcp模式并没有模拟tcp的全部。所以理论上有办法把faketcp和
|
||||
在client 端,运行`traceroute <server_ip>`,记下第一跳的地址,这个就是`网关ip`。再运行`arp -s <网关ip>`,可以同时查到出口网卡名和mac。
|
||||
|
||||
![](/images/lower_level.PNG)
|
||||
|
||||
如果traceroute第一跳结果是`* * *`,说明网关屏蔽了对traceroute的应答。需要用`ip route`或`route`查询网关:
|
||||
|
||||
![](/images/route.PNG)
|
||||
##### server端获得--lower-level参数的办法
|
||||
如果client有公网ip,就`traceroute <client_ip>`。下一步和client端的方法一样。
|
||||
|
||||
|
BIN
images/route.PNG
Normal file
BIN
images/route.PNG
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
75
main.cpp
75
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();
|
||||
|
||||
|
1
makefile
1
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
|
||||
|
49
network.cpp
49
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]<send_info.ts_ack= %u>\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,"<send_info.ts_ack= %u>\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
|
||||
|
Loading…
x
Reference in New Issue
Block a user