mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 14:29:34 +08:00
fixed warnings
This commit is contained in:
parent
701eb8dbcf
commit
0efcacfdf4
@ -189,7 +189,7 @@ 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)
|
int char_to_numbers(const char * data,int len,id_t &id1,id_t &id2,id_t &id3)
|
||||||
{
|
{
|
||||||
if(len<sizeof(id_t)*3) return -1;
|
if(len<int(sizeof(id_t)*3)) return -1;
|
||||||
id1=ntohl( *((id_t*)(data+0)) );
|
id1=ntohl( *((id_t*)(data+0)) );
|
||||||
id2=ntohl( *((id_t*)(data+sizeof(id_t))) );
|
id2=ntohl( *((id_t*)(data+sizeof(id_t))) );
|
||||||
id3=ntohl( *((id_t*)(data+sizeof(id_t)*2)) );
|
id3=ntohl( *((id_t*)(data+sizeof(id_t)*2)) );
|
||||||
|
22
common.h
22
common.h
@ -66,28 +66,28 @@ using namespace std;
|
|||||||
const int max_data_len=65535;
|
const int max_data_len=65535;
|
||||||
const int buf_len=max_data_len+200;
|
const int buf_len=max_data_len+200;
|
||||||
|
|
||||||
const int handshake_timeout=2000;
|
const uint32_t handshake_timeout=2000;
|
||||||
const int server_handshake_timeout=10000;
|
const uint32_t server_handshake_timeout=10000;
|
||||||
|
|
||||||
const int heartbeat_timeout=10000;
|
const uint32_t heartbeat_timeout=10000;
|
||||||
const int udp_timeout=3000;
|
const uint32_t udp_timeout=3000;
|
||||||
|
|
||||||
const int heartbeat_interval=1000;
|
const uint32_t heartbeat_interval=1000;
|
||||||
|
|
||||||
const int timer_interval=500;
|
const uint32_t timer_interval=500;
|
||||||
|
|
||||||
const int RETRY_TIME=3;
|
const int RETRY_TIME=3;
|
||||||
|
|
||||||
const int anti_replay_window_size=1000;
|
const uint32_t anti_replay_window_size=1000;
|
||||||
|
|
||||||
const int max_conv_num=10000;
|
const int max_conv_num=10000;
|
||||||
const int conv_timeout=120000; //60 second
|
const uint32_t conv_timeout=120000; //60 second
|
||||||
const int conv_clear_ratio=10;
|
const int conv_clear_ratio=10;
|
||||||
|
|
||||||
const int max_handshake_conn_num=10000;
|
const uint32_t max_handshake_conn_num=10000;
|
||||||
const int max_ready_conn_num=1000;
|
const uint32_t max_ready_conn_num=1000;
|
||||||
|
|
||||||
const int conn_timeout=60000;
|
const uint32_t conn_timeout=60000;
|
||||||
const int conn_clear_ratio=10;
|
const int conn_clear_ratio=10;
|
||||||
|
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ int cipher_aes128cbc_encrypt(const char *data,char *output,int &len,char * key)
|
|||||||
}
|
}
|
||||||
int auth_crc32_verify(const char *data,int &len)
|
int auth_crc32_verify(const char *data,int &len)
|
||||||
{
|
{
|
||||||
if(len<(sizeof(unsigned int)))
|
if(len<int(sizeof(unsigned int)))
|
||||||
{
|
{
|
||||||
mylog(log_debug,"auth_crc32_verify len<16\n");
|
mylog(log_debug,"auth_crc32_verify len<16\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
25
main.cpp
25
main.cpp
@ -82,7 +82,7 @@ struct anti_replay_t
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int i=max_packet_received+1;i<seq;i++)
|
for (uint32_t i=max_packet_received+1;i<seq;i++)
|
||||||
window[i%anti_replay_window_size]=0;
|
window[i%anti_replay_window_size]=0;
|
||||||
window[seq%anti_replay_window_size]=1;
|
window[seq%anti_replay_window_size]=1;
|
||||||
}
|
}
|
||||||
@ -289,7 +289,7 @@ struct conn_info_t
|
|||||||
struct conn_manager_t
|
struct conn_manager_t
|
||||||
{
|
{
|
||||||
unordered_map<uint64_t,conn_info_t> mp;
|
unordered_map<uint64_t,conn_info_t> mp;
|
||||||
int ready_num;
|
uint32_t ready_num;
|
||||||
|
|
||||||
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
|
||||||
@ -1285,7 +1285,7 @@ int client_on_raw_recv(conn_info_t &conn_info)
|
|||||||
conn_info.last_hb_recv_time=current_time_rough;
|
conn_info.last_hb_recv_time=current_time_rough;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if(data_len>=sizeof(uint32_t)+1&&data[0]=='d')
|
else if(data_len>= int( sizeof(uint32_t)+1 )&&data[0]=='d')
|
||||||
{
|
{
|
||||||
mylog(log_trace,"received a data from fake tcp,len:%d\n",data_len);
|
mylog(log_trace,"received a data from fake tcp,len:%d\n",data_len);
|
||||||
|
|
||||||
@ -1351,7 +1351,7 @@ int server_on_raw_ready(conn_info_t &conn_info)
|
|||||||
mylog(log_debug, "received hb <%x,%x>\n", conn_info.oppsite_id, tmp);
|
mylog(log_debug, "received hb <%x,%x>\n", conn_info.oppsite_id, tmp);
|
||||||
conn_info.last_hb_recv_time = current_time_rough;
|
conn_info.last_hb_recv_time = current_time_rough;
|
||||||
return 0;
|
return 0;
|
||||||
} else if (data[0] == 'd' && data_len >= sizeof(uint32_t) + 1) {
|
} else if (data[0] == 'd' && data_len >=int( sizeof(uint32_t) + 1)) {
|
||||||
uint32_t tmp_conv_id = ntohl(*((uint32_t *) &data[1]));
|
uint32_t tmp_conv_id = ntohl(*((uint32_t *) &data[1]));
|
||||||
|
|
||||||
conn_info.last_hb_recv_time = current_time_rough;
|
conn_info.last_hb_recv_time = current_time_rough;
|
||||||
@ -2109,21 +2109,21 @@ int client_event_loop()
|
|||||||
}
|
}
|
||||||
int n;
|
int n;
|
||||||
for (n = 0; n < nfds; ++n) {
|
for (n = 0; n < nfds; ++n) {
|
||||||
if (events[n].data.u64 == raw_recv_fd)
|
if (events[n].data.u64 == (uint64_t)raw_recv_fd)
|
||||||
{
|
{
|
||||||
iphdr *iph;tcphdr *tcph;
|
iphdr *iph;tcphdr *tcph;
|
||||||
client_on_raw_recv(conn_info);
|
client_on_raw_recv(conn_info);
|
||||||
}
|
}
|
||||||
if(events[n].data.u64 ==timer_fd)
|
if(events[n].data.u64 ==(uint64_t)timer_fd)
|
||||||
{
|
{
|
||||||
uint64_t value;
|
uint64_t value;
|
||||||
read(timer_fd, &value, 8);
|
read(timer_fd, &value, 8);
|
||||||
keep_connection_client(conn_info);
|
keep_connection_client(conn_info);
|
||||||
}
|
}
|
||||||
if (events[n].data.u64 == udp_fd)
|
if (events[n].data.u64 == (uint64_t)udp_fd)
|
||||||
{
|
{
|
||||||
|
|
||||||
socklen_t recv_len;
|
int recv_len;
|
||||||
struct sockaddr_in udp_new_addr_in;
|
struct sockaddr_in udp_new_addr_in;
|
||||||
if ((recv_len = recvfrom(udp_fd, buf, buf_len, 0,
|
if ((recv_len = recvfrom(udp_fd, buf, buf_len, 0,
|
||||||
(struct sockaddr *) &udp_new_addr_in, &slen)) == -1) {
|
(struct sockaddr *) &udp_new_addr_in, &slen)) == -1) {
|
||||||
@ -2265,7 +2265,7 @@ int server_event_loop()
|
|||||||
for (n = 0; n < nfds; ++n)
|
for (n = 0; n < nfds; ++n)
|
||||||
{
|
{
|
||||||
//printf("%d %d %d %d\n",timer_fd,raw_recv_fd,raw_send_fd,n);
|
//printf("%d %d %d %d\n",timer_fd,raw_recv_fd,raw_send_fd,n);
|
||||||
if ((events[n].data.u64 ) == timer_fd)
|
if ((events[n].data.u64 ) == (uint64_t)timer_fd)
|
||||||
{
|
{
|
||||||
uint64_t dummy;
|
uint64_t dummy;
|
||||||
read(timer_fd, &dummy, 8);
|
read(timer_fd, &dummy, 8);
|
||||||
@ -2293,7 +2293,7 @@ int server_event_loop()
|
|||||||
//conn_info_t &conn_info=conn_manager.find(ip,port);
|
//conn_info_t &conn_info=conn_manager.find(ip,port);
|
||||||
keep_connection_server_multi(*p_conn_info);
|
keep_connection_server_multi(*p_conn_info);
|
||||||
}
|
}
|
||||||
else if (events[n].data.u64 == raw_recv_fd)
|
else if (events[n].data.u64 == (uint64_t)raw_recv_fd)
|
||||||
{
|
{
|
||||||
iphdr *iph;tcphdr *tcph;
|
iphdr *iph;tcphdr *tcph;
|
||||||
server_on_raw_recv_multi();
|
server_on_raw_recv_multi();
|
||||||
@ -2707,6 +2707,11 @@ void iptables_warn()
|
|||||||
}
|
}
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
|
uint32_t b=0xffff;
|
||||||
|
int32_t a=b;
|
||||||
|
printf("<%d>",a);
|
||||||
|
|
||||||
dup2(1, 2);//redirect stderr to stdout
|
dup2(1, 2);//redirect stderr to stdout
|
||||||
signal(SIGINT, INThandler);
|
signal(SIGINT, INThandler);
|
||||||
process_arg(argc,argv);
|
process_arg(argc,argv);
|
||||||
|
2
makefile
2
makefile
@ -1,5 +1,5 @@
|
|||||||
ccmips=mips-openwrt-linux-g++
|
ccmips=mips-openwrt-linux-g++
|
||||||
FLAGS=-Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-sign-compare
|
FLAGS=-Wall -Wextra -Wno-unused-variable -Wno-unused-parameter
|
||||||
all:
|
all:
|
||||||
sudo killall udp2raw||true
|
sudo killall udp2raw||true
|
||||||
sleep 0.2
|
sleep 0.2
|
||||||
|
14
network.cpp
14
network.cpp
@ -285,7 +285,7 @@ int peek_raw(uint32_t &ip,uint16_t &port)
|
|||||||
int recv_len = recvfrom(raw_recv_fd, peek_raw_buf,buf_len, MSG_PEEK ,&saddr , &saddr_size);//change buf_len to something smaller,we only need header here
|
int recv_len = recvfrom(raw_recv_fd, peek_raw_buf,buf_len, MSG_PEEK ,&saddr , &saddr_size);//change buf_len to something smaller,we only need header here
|
||||||
iphdr * iph = (struct iphdr *) (ip_begin);
|
iphdr * iph = (struct iphdr *) (ip_begin);
|
||||||
//mylog(log_info,"recv_len %d\n",recv_len);
|
//mylog(log_info,"recv_len %d\n",recv_len);
|
||||||
if(recv_len<sizeof(iphdr))
|
if(recv_len<int(sizeof(iphdr)))
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -300,7 +300,7 @@ int peek_raw(uint32_t &ip,uint16_t &port)
|
|||||||
{
|
{
|
||||||
if(iph->protocol!=IPPROTO_TCP) return -1;
|
if(iph->protocol!=IPPROTO_TCP) return -1;
|
||||||
struct tcphdr *tcph=(tcphdr *)payload;
|
struct tcphdr *tcph=(tcphdr *)payload;
|
||||||
if(recv_len<iphdrlen+sizeof(tcphdr))
|
if(recv_len<int( iphdrlen+sizeof(tcphdr) ))
|
||||||
return -1;
|
return -1;
|
||||||
port=ntohs(tcph->source);
|
port=ntohs(tcph->source);
|
||||||
break;
|
break;
|
||||||
@ -309,7 +309,7 @@ int peek_raw(uint32_t &ip,uint16_t &port)
|
|||||||
{
|
{
|
||||||
if(iph->protocol!=IPPROTO_UDP) return -1;
|
if(iph->protocol!=IPPROTO_UDP) return -1;
|
||||||
struct udphdr *udph=(udphdr *)payload;
|
struct udphdr *udph=(udphdr *)payload;
|
||||||
if(recv_len<iphdrlen+sizeof(udphdr))
|
if(recv_len<int(iphdrlen+sizeof(udphdr)))
|
||||||
return -1;
|
return -1;
|
||||||
port=ntohs(udph->source);
|
port=ntohs(udph->source);
|
||||||
break;
|
break;
|
||||||
@ -318,7 +318,7 @@ int peek_raw(uint32_t &ip,uint16_t &port)
|
|||||||
{
|
{
|
||||||
if(iph->protocol!=IPPROTO_ICMP) return -1;
|
if(iph->protocol!=IPPROTO_ICMP) return -1;
|
||||||
struct icmphdr *icmph=(icmphdr *)payload;
|
struct icmphdr *icmph=(icmphdr *)payload;
|
||||||
if(recv_len<iphdrlen+sizeof(icmphdr))
|
if(recv_len<int( iphdrlen+sizeof(icmphdr) ))
|
||||||
return -1;
|
return -1;
|
||||||
port=ntohs(icmph->id);
|
port=ntohs(icmph->id);
|
||||||
break;
|
break;
|
||||||
@ -347,7 +347,7 @@ int recv_raw_ip(raw_info_t &raw_info,char * &payload,int &payloadlen)
|
|||||||
mylog(log_trace,"recv_len %d\n",recv_len);
|
mylog(log_trace,"recv_len %d\n",recv_len);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(recv_len<link_level_header_len)
|
if(recv_len<int(link_level_header_len))
|
||||||
{
|
{
|
||||||
mylog(log_trace,"length error\n");
|
mylog(log_trace,"length error\n");
|
||||||
}
|
}
|
||||||
@ -383,7 +383,7 @@ int recv_raw_ip(raw_info_t &raw_info,char * &payload,int &payloadlen)
|
|||||||
|
|
||||||
int ip_len=ntohs(iph->tot_len);
|
int ip_len=ntohs(iph->tot_len);
|
||||||
|
|
||||||
if(recv_len-link_level_header_len <ip_len)
|
if(recv_len-int(link_level_header_len) <ip_len)
|
||||||
{
|
{
|
||||||
mylog(log_debug,"incomplete packet\n");
|
mylog(log_debug,"incomplete packet\n");
|
||||||
return -1;
|
return -1;
|
||||||
@ -853,7 +853,7 @@ int recv_raw_udp(raw_info_t &raw_info, char *&payload, int &payloadlen)
|
|||||||
//printf("not udp protocol\n");
|
//printf("not udp protocol\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(ip_payloadlen<sizeof(udphdr))
|
if(ip_payloadlen<int( sizeof(udphdr) ))
|
||||||
{
|
{
|
||||||
mylog(log_debug,"too short to hold udpheader\n");
|
mylog(log_debug,"too short to hold udpheader\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user