From 5c7d48e711ad171887fa60c25893ba2cb752786e Mon Sep 17 00:00:00 2001 From: wangyu- Date: Tue, 5 Jun 2018 11:40:09 -0500 Subject: [PATCH] new option set-ttl --- misc.cpp | 9 +++++++++ misc.h | 2 ++ network.cpp | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/misc.cpp b/misc.cpp index ce5f9b1..e85dcda 100644 --- a/misc.cpp +++ b/misc.cpp @@ -24,6 +24,7 @@ int max_rst_allowed=-1; int enable_dns_resolve=0; +int ttl_value=64; fd_manager_t fd_manager; @@ -277,6 +278,7 @@ void process_arg(int argc, char *argv[]) //process all options {"mtu-warn", required_argument, 0, 1}, {"max-rst-to-show", required_argument, 0, 1}, {"max-rst-allowed", required_argument, 0, 1}, + {"set-ttl", required_argument, 0, 1}, {"dns-resolve", no_argument, 0, 1}, {NULL, 0, 0, 0} }; @@ -650,6 +652,13 @@ void process_arg(int argc, char *argv[]) //process all options assert(max_rst_allowed>=-1); mylog(log_info,"max_rst_allowed=%d \n",max_rst_allowed); } + else if(strcmp(long_options[option_index].name,"set-ttl")==0) + { + sscanf(optarg,"%d",&ttl_value); + assert(ttl_value>=0&&ttl_value<=255); + mylog(log_info,"ttl_value=%d",ttl_value); + } + else if(strcmp(long_options[option_index].name,"dns-resolve")==0) { enable_dns_resolve=1; diff --git a/misc.h b/misc.h index f9527db..3f43a9d 100644 --- a/misc.h +++ b/misc.h @@ -22,6 +22,8 @@ extern int max_rst_to_show; extern int enable_dns_resolve; +extern int ttl_value; + const u32_t max_handshake_conn_num=10000; const u32_t max_ready_conn_num=1000; diff --git a/network.cpp b/network.cpp index 825b596..c95d70c 100644 --- a/network.cpp +++ b/network.cpp @@ -591,7 +591,7 @@ int send_raw_ip(raw_info_t &raw_info,const char * payload,int payloadlen) iph->frag_off = htons(0x4000); //DF set,others are zero // iph->frag_off = htons(0x0000); //DF set,others are zero - iph->ttl = 64; + iph->ttl = (unsigned char)ttl_value; iph->protocol = send_info.protocol; iph->check = 0; //Set to 0 before calculating checksum iph->saddr = send_info.src_ip; //Spoof the source ip address @@ -1039,7 +1039,7 @@ int send_raw_tcp_deprecated(const packet_info_t &info,const char * payload,int p iph->id = htonl (ip_id++); //Id of this packet iph->frag_off = htons(0x4000); //DF set,others are zero - iph->ttl = 64; + iph->ttl = (unsigned char)ttl_value; iph->protocol = IPPROTO_TCP; iph->check = 0; //Set to 0 before calculating checksum iph->saddr = info.src_ip; //Spoof the source ip address