mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 14:29:34 +08:00
fixed clear bug,add option random-drop
This commit is contained in:
parent
dcde8828c4
commit
54f32f0611
@ -219,6 +219,7 @@ conv_manager_t::~conv_manager_t()
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
clear_it=it;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -451,6 +452,7 @@ int conn_manager_t::clear_inactive0()
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
clear_it=it;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
12
misc.cpp
12
misc.cpp
@ -236,6 +236,7 @@ void process_arg(int argc, char *argv[]) //process all options
|
||||
{"seq-mode", required_argument, 0, 1},
|
||||
{"conf-file", required_argument, 0, 1},
|
||||
{"force-sock-buf", no_argument, 0, 1},
|
||||
{"random-drop", required_argument, 0, 1},
|
||||
{NULL, 0, 0, 0}
|
||||
};
|
||||
|
||||
@ -558,10 +559,21 @@ void process_arg(int argc, char *argv[]) //process all options
|
||||
myexit(-1);
|
||||
}
|
||||
}
|
||||
else if(strcmp(long_options[option_index].name,"random-drop")==0)
|
||||
{
|
||||
sscanf(optarg,"%d",&random_drop);
|
||||
if(random_drop<0||random_drop>10000)
|
||||
{
|
||||
mylog(log_fatal,"random_drop must be between 0 10000 \n");
|
||||
myexit(-1);
|
||||
}
|
||||
mylog(log_info,"random_drop =%d \n",random_drop);
|
||||
}
|
||||
else if(strcmp(long_options[option_index].name,"conf-file")==0)
|
||||
{
|
||||
mylog(log_info,"configuration loaded from %s\n",optarg);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
mylog(log_warn,"ignored unknown long option ,option_index:%d code:<%x>\n",option_index, optopt);
|
||||
|
@ -15,6 +15,7 @@ u32_t link_level_header_len=0;//set it to 14 if SOCK_RAW is used in socket(PF_PA
|
||||
|
||||
int seq_mode=3;
|
||||
int max_seq_mode=4;
|
||||
int random_drop=0;
|
||||
|
||||
int filter_port=-1;
|
||||
|
||||
@ -1623,6 +1624,12 @@ int recv_raw_tcp_deprecated(packet_info_t &info,char * &payload,int &payloadlen)
|
||||
}*/
|
||||
int send_raw0(raw_info_t &raw_info,const char * payload,int payloadlen)
|
||||
{
|
||||
if (random_drop != 0) {
|
||||
if (get_true_random_number() % 10000 < (u32_t) random_drop) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
packet_info_t &send_info=raw_info.send_info;
|
||||
packet_info_t &recv_info=raw_info.recv_info;
|
||||
mylog(log_trace,"send_raw : from %x %d to %x %d\n",send_info.src_ip,send_info.src_port,send_info.dst_ip,send_info.dst_port);
|
||||
|
Loading…
x
Reference in New Issue
Block a user