mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-02-07 23:59:36 +08:00
debug code
This commit is contained in:
parent
8a5ae7727a
commit
dfcc799876
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
16
main.cpp
16
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<pcap_link_header_len;i++)
|
||||
log_bare(log_info,"<%x>",(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();
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
//#include <wepoll.h>
|
||||
#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)
|
||||
|
21
network.cpp
21
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->caplen<packet_header->len) return;
|
||||
|
||||
if((int)packet_header->caplen<pcap_link_header_len) return;
|
||||
mylog(log_debug,"and its vaild!\n");
|
||||
|
||||
pthread_mutex_lock(&queue_mutex);
|
||||
if(!my_queue.full())
|
||||
@ -811,7 +813,7 @@ int find_lower_level_info(u32_t ip,u32_t &dest_ip,string &if_name,string &hw)
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
|
||||
extern int cap_len;
|
||||
int send_raw_ip(raw_info_t &raw_info,const char * payload,int payloadlen)
|
||||
{
|
||||
const packet_info_t &send_info=raw_info.send_info;
|
||||
@ -898,6 +900,17 @@ int send_raw_ip(raw_info_t &raw_info,const char * payload,int payloadlen)
|
||||
assert(pcap_link_header_len!=-1);
|
||||
memcpy(send_raw_ip_buf0,pcap_header_buf,pcap_link_header_len);
|
||||
assert(pcap_sendpacket(pcap_handle,(const unsigned char *)send_raw_ip_buf0,ip_tot_len+pcap_link_header_len)==0);
|
||||
unsigned char *p=(unsigned char *)send_raw_ip_buf0;
|
||||
for(int i=0;i<ip_tot_len+pcap_link_header_len;i++)
|
||||
printf("<%02x>",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<cap_len;i++)
|
||||
printf("<%02x>",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};
|
||||
|
Loading…
x
Reference in New Issue
Block a user