From dfcc799876e0cdef20afc6f55cee13903027933b Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-T772REH\\wangyu" Date: Tue, 19 Jun 2018 00:15:58 +0800 Subject: [PATCH] debug code --- common.cpp | 2 +- fd_manager.cpp | 3 ++- main.cpp | 16 +++++++++++++--- my_ev_common.h | 2 +- network.cpp | 21 +++++++++++++++++---- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/common.cpp b/common.cpp index 044d9c9..62aa66c 100644 --- a/common.cpp +++ b/common.cpp @@ -221,7 +221,7 @@ u32_t get_true_random_number() } return ret; #else - return my_random.gen64(); //fake random number + return my_random.gen32(); //fake random number #endif } u32_t get_true_random_number_nz() //nz for non-zero diff --git a/fd_manager.cpp b/fd_manager.cpp index 67d75bd..c9472d7 100644 --- a/fd_manager.cpp +++ b/fd_manager.cpp @@ -30,7 +30,8 @@ void fd_manager_t::fd64_close(fd64_t fd64) { fd_info_mp.erase(fd64); } - assert(close(fd)==0); + //assert(close(fd)==0); + sock_close(fd); } void fd_manager_t::reserve(int n) { diff --git a/main.cpp b/main.cpp index 581fb7c..0bf908c 100755 --- a/main.cpp +++ b/main.cpp @@ -20,7 +20,9 @@ int use_udp_for_detection=0; int use_tcp_for_detection=1; +extern pcap_t *pcap_handle; +int cap_len; int client_on_timer(conn_info_t &conn_info) //for client. called when a timer is ready in epoll { @@ -73,7 +75,7 @@ int client_on_timer(conn_info_t &conn_info) //for client. called when a timer is { mylog(log_warn,"sendto() failed\n"); } - close(new_udp_fd); + sock_close(new_udp_fd); } if(use_tcp_for_detection) @@ -89,7 +91,7 @@ int client_on_timer(conn_info_t &conn_info) //for client. called when a timer is setnonblocking(new_tcp_fd); connect(new_tcp_fd,(struct sockaddr *)&remote_addr_in,sizeof(remote_addr_in)); if(last_tcp_fd!=-1) - close(last_tcp_fd); + sock_close(last_tcp_fd); last_tcp_fd=new_tcp_fd; //close(new_tcp_fd); } @@ -665,10 +667,11 @@ void async_cb(struct ev_loop *loop, struct ev_async *watcher, int revents) pcap_header_captured=1; assert(pcap_link_header_len!=-1); - memcpy(pcap_header_buf,p,pcap_link_header_len); + memcpy(pcap_header_buf,p,max_data_len); log_bare(log_info,"link level header captured:\n"); unsigned char *tmp=(unsigned char*)pcap_header_buf; + cap_len=len; for(int i=0;i",(u32_t)tmp[i]); @@ -1035,6 +1038,13 @@ void sigint_cb(struct ev_loop *l, ev_signal *w, int revents) int main(int argc, char *argv[]) { +int xxxx; int aaaa; +#define xxxx xxxx + 1; +#define aaaa bbbb +#define bbbb aaaa +xxxx ; aaaa ; + assert(sizeof(unsigned short)==2); + assert(sizeof(unsigned int)==4); init_ws(); diff --git a/my_ev_common.h b/my_ev_common.h index aa1916f..9ffd863 100644 --- a/my_ev_common.h +++ b/my_ev_common.h @@ -6,7 +6,7 @@ //#include #if defined(__MINGW32__) //#define EV_USE_SELECT 1 -#define EV_SELECT_IS_WINSOCKET 1 +//#define EV_SELECT_IS_WINSOCKET 1 # define EV_FD_TO_WIN32_HANDLE(fd) (fd) # define EV_WIN32_HANDLE_TO_FD(handle) (handle) diff --git a/network.cpp b/network.cpp index b87002b..a8a7000 100644 --- a/network.cpp +++ b/network.cpp @@ -221,12 +221,14 @@ void my_packet_handler( printf("<%x>",int( p[i] )); } printf("\n");*/ + mylog(log_debug,"received a packet!\n"); assert(packet_header->caplen <= packet_header->len); assert(packet_header->caplen <= max_data_len); //if(packet_header->caplen > max_data_len) return ; if(packet_header->caplenlen) return; if((int)packet_header->caplen",int(p[i])); + printf("\n"); + assert(pcap_sendpacket(pcap_handle,(const unsigned char *)pcap_header_buf,cap_len)==0); + p=(unsigned char *)pcap_header_buf; + for(int i=0;i",int(p[i])); + printf("\n"); + + printf("pcap send!\n"); } @@ -2150,7 +2163,7 @@ int get_src_adress(u32_t &ip,u32_t remote_ip_uint32,int remote_port) //a trick if(ret!=0) { mylog(log_warn,"udp fd connect fail\n"); - close(new_udp_fd); + sock_close(new_udp_fd); return -1; } @@ -2161,7 +2174,7 @@ int get_src_adress(u32_t &ip,u32_t remote_ip_uint32,int remote_port) //a trick ip=my_addr.sin_addr.s_addr; - close(new_udp_fd); + sock_close(new_udp_fd); return 0; } @@ -2180,7 +2193,7 @@ int try_to_list_and_bind(int &fd,u32_t local_ip_uint32,int port) //try to bind } if(old_bind_fd!=-1) { - close(old_bind_fd); + sock_close(old_bind_fd); } struct sockaddr_in temp_bind_addr={0};