diff --git a/common.h b/common.h index 839b622..901443d 100644 --- a/common.h +++ b/common.h @@ -47,6 +47,9 @@ #include #include #include +#include +#include + #include diff --git a/main.cpp b/main.cpp index 10e4fe3..d61ca47 100755 --- a/main.cpp +++ b/main.cpp @@ -168,7 +168,7 @@ int client_on_timer(conn_info_t &conn_info) //for client. called when a timer is send_handshake(raw_info,conn_info.my_id,0,const_id); if(raw_mode==mode_icmp) - send_info.icmp_seq++; + send_info.my_icmp_seq++; } conn_info.last_hb_sent_time=get_current_time(); @@ -209,7 +209,7 @@ int client_on_timer(conn_info_t &conn_info) //for client. called when a timer is send_handshake(raw_info,conn_info.my_id,conn_info.oppsite_id,const_id); if(raw_mode==mode_icmp) - send_info.icmp_seq++; + send_info.my_icmp_seq++; } conn_info.last_hb_sent_time=get_current_time(); mylog(log_info,"(re)sent handshake2\n"); @@ -768,6 +768,11 @@ int client_event_loop() int main(int argc, char *argv[]) { + libnet_t *l; /* the libnet context */ + char errbuf[LIBNET_ERRBUF_SIZE]; + + l = libnet_init(LIBNET_RAW4, NULL, errbuf); + dup2(1, 2);//redirect stderr to stdout signal(SIGINT, signal_handler); signal(SIGHUP, signal_handler); diff --git a/makefile b/makefile index cc3074e..859a6f4 100755 --- a/makefile +++ b/makefile @@ -10,7 +10,7 @@ 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 ${OPT} -COMMON=main.cpp lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp connection.cpp misc.cpp fd_manager.cpp -lpthread my_ev.cpp -isystem libev +COMMON=main.cpp lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp connection.cpp misc.cpp fd_manager.cpp -lpthread my_ev.cpp -isystem libev -lpcap -D_DEFAULT_SOURCE `libnet-config --defines` `libnet-config --libs` SOURCES= $(COMMON) lib/aes_faster_c/aes.c lib/aes_faster_c/wrapper.c SOURCES_TINY_AES= $(COMMON) lib/aes.c diff --git a/misc.cpp b/misc.cpp index a4efe55..d6e1af7 100644 --- a/misc.cpp +++ b/misc.cpp @@ -279,6 +279,7 @@ void process_arg(int argc, char *argv[]) //process all options {"max-rst-to-show", required_argument, 0, 1}, {"max-rst-allowed", required_argument, 0, 1}, {"set-ttl", required_argument, 0, 1}, + {"dev", required_argument, 0, 1}, {"dns-resolve", no_argument, 0, 1}, {NULL, 0, 0, 0} }; @@ -666,6 +667,11 @@ void process_arg(int argc, char *argv[]) //process all options enable_dns_resolve=1; mylog(log_info,"dns-resolve enabled\n"); } + else if(strcmp(long_options[option_index].name,"dev")==0) // currently not used + { + sscanf(optarg,"%s",dev); + mylog(log_info,"dev=[%s]\n",dev); + } else { mylog(log_warn,"ignored unknown long option ,option_index:%d code:<%x>\n",option_index, optopt); diff --git a/network.cpp b/network.cpp index c95d70c..097c4f9 100644 --- a/network.cpp +++ b/network.cpp @@ -28,6 +28,8 @@ int lower_level_manual=0; int ifindex=-1; char if_name[100]=""; +char dev[100]=""; + unsigned short g_ip_id_counter=0; unsigned char dest_hw_addr[sizeof(sockaddr_ll::sll_addr)]= @@ -164,7 +166,7 @@ packet_info_t::packet_info_t() else if (raw_mode == mode_icmp) { protocol = IPPROTO_ICMP; - icmp_seq=0; + my_icmp_seq=0; } } @@ -815,7 +817,7 @@ int send_raw_icmp(raw_info_t &raw_info, const char * payload, int payloadlen) icmph->id=htons(send_info.src_port); - icmph->seq=htons(send_info.icmp_seq); /////////////modify + icmph->seq=htons(send_info.my_icmp_seq); /////////////modify memcpy(send_raw_icmp_buf+sizeof(icmphdr),payload,payloadlen); @@ -1205,7 +1207,7 @@ int recv_raw_icmp(raw_info_t &raw_info, char *&payload, int &payloadlen) } recv_info.src_port=recv_info.dst_port=ntohs(icmph->id); - recv_info.icmp_seq=ntohs(icmph->seq); + recv_info.my_icmp_seq=ntohs(icmph->seq); if(program_mode==client_mode) @@ -1754,7 +1756,7 @@ int after_send_raw0(raw_info_t &raw_info) { if(program_mode==client_mode) { - send_info.icmp_seq++; + send_info.my_icmp_seq++; } } return 0; @@ -1789,8 +1791,8 @@ int after_recv_raw0(raw_info_t &raw_info) { if(program_mode==server_mode) { - if(larger_than_u16(recv_info.icmp_seq,send_info.icmp_seq)) - send_info.icmp_seq = recv_info.icmp_seq; //TODO only update if its larger + if(larger_than_u16(recv_info.my_icmp_seq,send_info.my_icmp_seq)) + send_info.my_icmp_seq = recv_info.my_icmp_seq; //TODO only update if its larger } } return 0; diff --git a/network.h b/network.h index a87f458..cfc5e20 100644 --- a/network.h +++ b/network.h @@ -21,6 +21,8 @@ extern int lower_level_manual; extern char if_name[100]; extern unsigned char dest_hw_addr[]; +extern char dev[100]; + extern int random_drop; extern int ifindex; @@ -62,7 +64,7 @@ struct packet_info_t //todo change this to union u32_t ts,ts_ack; - uint16_t icmp_seq; + uint16_t my_icmp_seq; bool has_ts;