mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 14:29:34 +08:00
handle truncated packet
This commit is contained in:
parent
3138b2ca8e
commit
7cb65ec45d
2
common.h
2
common.h
@ -85,7 +85,7 @@ struct ip_port_t
|
|||||||
|
|
||||||
typedef u64_t fd64_t;
|
typedef u64_t fd64_t;
|
||||||
|
|
||||||
const int max_data_len=1600;
|
const int max_data_len=1800;
|
||||||
const int buf_len=max_data_len+400;
|
const int buf_len=max_data_len+400;
|
||||||
|
|
||||||
u64_t get_current_time();
|
u64_t get_current_time();
|
||||||
|
16
main.cpp
16
main.cpp
@ -1294,12 +1294,18 @@ int client_event_loop()
|
|||||||
int recv_len;
|
int recv_len;
|
||||||
struct sockaddr_in udp_new_addr_in={0};
|
struct sockaddr_in udp_new_addr_in={0};
|
||||||
socklen_t udp_new_addr_len = sizeof(sockaddr_in);
|
socklen_t udp_new_addr_len = sizeof(sockaddr_in);
|
||||||
if ((recv_len = recvfrom(udp_fd, buf, max_data_len, 0,
|
if ((recv_len = recvfrom(udp_fd, buf, max_data_len+1, 0,
|
||||||
(struct sockaddr *) &udp_new_addr_in, &udp_new_addr_len)) == -1) {
|
(struct sockaddr *) &udp_new_addr_in, &udp_new_addr_len)) == -1) {
|
||||||
mylog(log_error,"recv_from error,this shouldnt happen at client\n");
|
mylog(log_error,"recv_from error,this shouldnt happen at client\n");
|
||||||
myexit(1);
|
myexit(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if(recv_len==max_data_len+1)
|
||||||
|
{
|
||||||
|
mylog(log_warn,"huge packet, data_len > %d,dropped\n",max_data_len);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if(recv_len>=mtu_warn)
|
if(recv_len>=mtu_warn)
|
||||||
{
|
{
|
||||||
mylog(log_warn,"huge packet,data len=%d (>=%d).strongly suggested to set a smaller mtu at upper level,to get rid of this warn\n ",recv_len,mtu_warn);
|
mylog(log_warn,"huge packet,data len=%d (>=%d).strongly suggested to set a smaller mtu at upper level,to get rid of this warn\n ",recv_len,mtu_warn);
|
||||||
@ -1639,10 +1645,16 @@ int server_event_loop()
|
|||||||
|
|
||||||
int fd=fd_manager.to_fd(fd64);
|
int fd=fd_manager.to_fd(fd64);
|
||||||
|
|
||||||
int recv_len=recv(fd,buf,max_data_len,0);
|
int recv_len=recv(fd,buf,max_data_len+1,0);
|
||||||
|
|
||||||
mylog(log_trace,"received a packet from udp_fd,len:%d\n",recv_len);
|
mylog(log_trace,"received a packet from udp_fd,len:%d\n",recv_len);
|
||||||
|
|
||||||
|
if(recv_len==max_data_len+1)
|
||||||
|
{
|
||||||
|
mylog(log_warn,"huge packet, data_len > %d,dropped\n",max_data_len);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if(recv_len<0)
|
if(recv_len<0)
|
||||||
{
|
{
|
||||||
mylog(log_debug,"udp fd,recv_len<0 continue,%s\n",strerror(errno));
|
mylog(log_debug,"udp fd,recv_len<0 continue,%s\n",strerror(errno));
|
||||||
|
@ -704,7 +704,13 @@ int recv_raw_ip(raw_info_t &raw_info,char * &payload,int &payloadlen)
|
|||||||
struct sockaddr_ll saddr={0};
|
struct sockaddr_ll saddr={0};
|
||||||
socklen_t saddr_size = sizeof(saddr);
|
socklen_t saddr_size = sizeof(saddr);
|
||||||
int flag=0;
|
int flag=0;
|
||||||
int recv_len = recvfrom(raw_recv_fd, recv_raw_ip_buf, max_data_len, flag ,(sockaddr*)&saddr , &saddr_size);
|
int recv_len = recvfrom(raw_recv_fd, recv_raw_ip_buf, max_data_len+1, flag ,(sockaddr*)&saddr , &saddr_size);
|
||||||
|
|
||||||
|
if(recv_len==max_data_len+1)
|
||||||
|
{
|
||||||
|
mylog(log_warn,"huge packet, data_len > %d,dropped\n",max_data_len);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if(recv_len<0)
|
if(recv_len<0)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user