mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-02-07 23:59:36 +08:00
trival
This commit is contained in:
parent
db7b43001a
commit
086cba4b1d
11
common.cpp
11
common.cpp
@ -98,9 +98,10 @@ int get_sock_errno()
|
||||
|
||||
u64_t get_current_time()
|
||||
{
|
||||
timespec tmp_time;
|
||||
clock_gettime(CLOCK_MONOTONIC, &tmp_time);
|
||||
return ((u64_t)tmp_time.tv_sec)*1000llu+((u64_t)tmp_time.tv_nsec)/(1000*1000llu);
|
||||
//timespec tmp_time;
|
||||
//clock_gettime(CLOCK_MONOTONIC, &tmp_time);
|
||||
//return ((u64_t)tmp_time.tv_sec)*1000llu+((u64_t)tmp_time.tv_nsec)/(1000*1000llu);
|
||||
return (u64_t)(ev_time()*1000);
|
||||
}
|
||||
|
||||
u64_t pack_u64(u32_t a,u32_t b)
|
||||
@ -335,12 +336,12 @@ int set_buf_size(int fd,int socket_buf_size,int force_socket_buf)
|
||||
{
|
||||
if(setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||
{
|
||||
mylog(log_fatal,"SO_SNDBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||
mylog(log_fatal,"SO_SNDBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,get_sock_error());
|
||||
myexit(1);
|
||||
}
|
||||
if(setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||
{
|
||||
mylog(log_fatal,"SO_RCVBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||
mylog(log_fatal,"SO_RCVBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,get_sock_error());
|
||||
myexit(1);
|
||||
}
|
||||
}
|
||||
|
8
main.cpp
8
main.cpp
@ -181,7 +181,7 @@ int client_on_timer(conn_info_t &conn_info) //for client. called when a timer is
|
||||
|
||||
setnonblocking(bind_fd);
|
||||
int ret=connect(bind_fd,(struct sockaddr *)&remote_addr_in,sizeof(remote_addr_in));
|
||||
mylog(log_info,"ret=%d,errno=%s,%d %d\n",ret,strerror(errno),bind_fd,remote_port);
|
||||
mylog(log_info,"ret=%d,errno=%s,%d %d\n",ret,get_sock_error(),bind_fd,remote_port);
|
||||
conn_info.state.client_current_state=client_tcp_handshake_dummy;
|
||||
mylog(log_info,"state changed from client_idle to client_tcp_handshake_dummy\n");
|
||||
}
|
||||
@ -597,8 +597,8 @@ void udp_accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents)
|
||||
socklen_t udp_new_addr_len = sizeof(sockaddr_in);
|
||||
if ((recv_len = recvfrom(udp_fd, buf, max_data_len+1, 0,
|
||||
(struct sockaddr *) &udp_new_addr_in, &udp_new_addr_len)) == -1) {
|
||||
mylog(log_error,"recv_from error,this shouldnt happen at client\n");
|
||||
myexit(1);
|
||||
mylog(log_warn,"recv_from error,this shouldnt happen at client,but lets try to continue\n");
|
||||
//myexit(1);
|
||||
};
|
||||
|
||||
if(recv_len==max_data_len+1)
|
||||
@ -722,7 +722,7 @@ void fifo_cb(struct ev_loop *loop, struct ev_io *watcher, int revents)
|
||||
int len=read (fifo_fd, buf, sizeof (buf));
|
||||
if(len<0)
|
||||
{
|
||||
mylog(log_warn,"fifo read failed len=%d,errno=%s\n",len,strerror(errno));
|
||||
mylog(log_warn,"fifo read failed len=%d,errno=%s\n",len,get_sock_error());
|
||||
return;
|
||||
}
|
||||
buf[len]=0;
|
||||
|
10
misc.cpp
10
misc.cpp
@ -193,7 +193,7 @@ int load_config(char *file_name, int &argc, vector<string> &argv) //load conf fi
|
||||
std::string line;
|
||||
if(conf_file.fail())
|
||||
{
|
||||
mylog(log_fatal,"conf_file %s open failed,reason :%s\n",file_name,strerror(errno));
|
||||
mylog(log_fatal,"conf_file %s open failed,reason :%s\n",file_name,get_sock_error());
|
||||
myexit(-1);
|
||||
}
|
||||
while(std::getline(conf_file,line))
|
||||
@ -474,6 +474,13 @@ void process_arg(int argc, char *argv[]) //process all options
|
||||
mylog(log_info,"source: %d\n",source_port);
|
||||
}
|
||||
else if(strcmp(long_options[option_index].name,"raw-mode")==0)
|
||||
{
|
||||
if(strcmp(optarg,"easyfaketcp")==0||strcmp(optarg,"easy_faketcp")==0||strcmp(optarg,"easy-faketcp")==0)
|
||||
{
|
||||
raw_mode=mode_faketcp;
|
||||
use_tcp_dummy_socket=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i=0;i<mode_end;i++)
|
||||
{
|
||||
@ -491,6 +498,7 @@ void process_arg(int argc, char *argv[]) //process all options
|
||||
myexit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(strcmp(long_options[option_index].name,"auth-mode")==0)
|
||||
{
|
||||
for(i=0;i<auth_end;i++)
|
||||
|
10
network.cpp
10
network.cpp
@ -247,10 +247,14 @@ void *pcap_recv_thread_entry(void *none)
|
||||
struct pcap_pkthdr *packet_header;
|
||||
const u_char *pkt_data;
|
||||
|
||||
while(1)
|
||||
{
|
||||
int ret=pcap_loop(pcap_handle, 0, my_packet_handler, NULL);
|
||||
|
||||
mylog(log_fatal,"pcap_loop returned with value %d\n",ret);
|
||||
myexit(-1);
|
||||
mylog(log_warn,"pcap_loop exited with value %d\n",ret);
|
||||
sleep(5);
|
||||
//myexit(-1);
|
||||
}
|
||||
/*
|
||||
while(1)
|
||||
{
|
||||
@ -959,7 +963,7 @@ int peek_raw(packet_info_t &peek_info)
|
||||
if(recv_len<int(sizeof(my_iphdr)))
|
||||
{
|
||||
mylog(log_trace,"failed here %d %d\n",recv_len,int(sizeof(my_iphdr)));
|
||||
mylog(log_trace,"%s\n ",strerror(errno));
|
||||
mylog(log_trace,"%s\n ",get_sock_error());
|
||||
return -1;
|
||||
}
|
||||
peek_info.src_ip=iph->saddr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user