port to mac

This commit is contained in:
wangyu 2018-06-03 20:39:31 -07:00
parent 5fcf83e61a
commit 5b9da8dd43
6 changed files with 50 additions and 17 deletions

View File

@ -198,6 +198,8 @@ u32_t get_true_random_number_nz() //nz for non-zero
} }
return ret; return ret;
} }
/*
u64_t ntoh64(u64_t a) u64_t ntoh64(u64_t a)
{ {
if(__BYTE_ORDER == __LITTLE_ENDIAN) if(__BYTE_ORDER == __LITTLE_ENDIAN)
@ -215,7 +217,7 @@ u64_t hton64(u64_t a)
} }
else return a; else return a;
} }*/
void setnonblocking(int sock) { void setnonblocking(int sock) {
int opts; int opts;
@ -295,8 +297,9 @@ unsigned short tcp_csum(const pseudo_header & ph,const unsigned short *ptr,int n
int set_buf_size(int fd,int socket_buf_size,int force_socket_buf) int set_buf_size(int fd,int socket_buf_size,int force_socket_buf)
{ {
if(force_socket_buf) if(0)
{ {
/*
if(setsockopt(fd, SOL_SOCKET, SO_SNDBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0) if(setsockopt(fd, SOL_SOCKET, SO_SNDBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0)
{ {
mylog(log_fatal,"SO_SNDBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno)); mylog(log_fatal,"SO_SNDBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
@ -307,6 +310,7 @@ int set_buf_size(int fd,int socket_buf_size,int force_socket_buf)
mylog(log_fatal,"SO_RCVBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno)); mylog(log_fatal,"SO_RCVBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
myexit(1); myexit(1);
} }
*/
} }
else else
{ {
@ -447,7 +451,7 @@ int random_between(u32_t a,u32_t b)
else return a+get_true_random_number()%(b+1-a); else return a+get_true_random_number()%(b+1-a);
} }
/*
int set_timer_ms(int epollfd,int &timer_fd,u32_t timer_interval) int set_timer_ms(int epollfd,int &timer_fd,u32_t timer_interval)
{ {
int ret; int ret;
@ -476,7 +480,7 @@ int set_timer_ms(int epollfd,int &timer_fd,u32_t timer_interval)
myexit(-1); myexit(-1);
} }
return 0; return 0;
} }*/
/* /*
int create_new_udp(int &new_udp_fd,int remote_address_uint32,int remote_port) int create_new_udp(int &new_udp_fd,int remote_address_uint32,int remote_port)
{ {
@ -579,7 +583,7 @@ int new_listen_socket(int &fd,u32_t ip,int port)
local_me.sin_port = htons(port); local_me.sin_port = htons(port);
local_me.sin_addr.s_addr = ip; local_me.sin_addr.s_addr = ip;
if (bind(fd, (struct sockaddr*) &local_me, slen) == -1) { if (::bind(fd, (struct sockaddr*) &local_me, slen) == -1) {
mylog(log_fatal,"socket bind error\n"); mylog(log_fatal,"socket bind error\n");
//perror("socket bind error"); //perror("socket bind error");
myexit(1); myexit(1);

View File

@ -17,7 +17,6 @@
#include<unistd.h> #include<unistd.h>
#include<errno.h> #include<errno.h>
#include <sys/epoll.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/socket.h> //for socket ofcourse #include <sys/socket.h> //for socket ofcourse
#include <sys/types.h> #include <sys/types.h>
@ -30,21 +29,15 @@
#include <netinet/if_ether.h> #include <netinet/if_ether.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <fcntl.h> #include <fcntl.h>
#include <byteswap.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <linux/if_ether.h>
#include <linux/filter.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <sys/timerfd.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <net/if.h> #include <net/if.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <stdarg.h> #include <stdarg.h>
#include <assert.h> #include <assert.h>
#include <linux/if_packet.h>
#include <linux/if_tun.h>
#include <my_ev.h> #include <my_ev.h>
@ -65,6 +58,11 @@ typedef int i32_t;
typedef unsigned short u16_t; typedef unsigned short u16_t;
typedef short i16_t; typedef short i16_t;
struct itimerspec {
struct timespec it_interval; /* Timer interval */
struct timespec it_value; /* Initial expiration */
};
typedef u64_t my_time_t; typedef u64_t my_time_t;
const int max_data_len=3600; const int max_data_len=3600;

View File

@ -28,6 +28,7 @@ int header_overhead=40;
u32_t fec_buff_num=2000;// how many packet can fec_decode_manager hold. shouldnt be very large,or it will cost huge memory u32_t fec_buff_num=2000;// how many packet can fec_decode_manager hold. shouldnt be very large,or it will cost huge memory
blob_encode_t::blob_encode_t() blob_encode_t::blob_encode_t()
{ {
clear(); clear();

5
log.h
View File

@ -14,7 +14,6 @@
#include <fcntl.h> #include <fcntl.h>
//#include"aes.h" //#include"aes.h"
#include <sys/epoll.h>
#include <sys/wait.h> #include <sys/wait.h>
#include<map> #include<map>
@ -32,17 +31,13 @@
#include <netinet/if_ether.h> #include <netinet/if_ether.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <fcntl.h> #include <fcntl.h>
#include <byteswap.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h> #include <sys/types.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <linux/if_ether.h>
#include <linux/filter.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <sys/timerfd.h>
#include <set> #include <set>
//#include <encrypt.h> //#include <encrypt.h>
#include <inttypes.h> #include <inttypes.h>

View File

@ -74,9 +74,39 @@ static void print_help()
} }
void sigpipe_cb(struct ev_loop *l, ev_signal *w, int revents)
{
mylog(log_info, "got sigpipe, ignored");
}
void sigterm_cb(struct ev_loop *l, ev_signal *w, int revents)
{
mylog(log_info, "got sigterm, exit");
myexit(0);
}
void sigint_cb(struct ev_loop *l, ev_signal *w, int revents)
{
mylog(log_info, "got sigint, exit");
myexit(0);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct ev_loop* loop=ev_default_loop(0);
ev_signal signal_watcher_sigpipe;
ev_signal_init(&signal_watcher_sigpipe, sigpipe_cb, SIGPIPE);
ev_signal_start(loop, &signal_watcher_sigpipe);
ev_signal signal_watcher_sigterm;
ev_signal_init(&signal_watcher_sigterm, sigterm_cb, SIGTERM);
ev_signal_start(loop, &signal_watcher_sigterm);
ev_signal signal_watcher_sigint;
ev_signal_init(&signal_watcher_sigint, sigint_cb, SIGINT);
ev_signal_start(loop, &signal_watcher_sigint);
//working_mode=tunnel_mode; //working_mode=tunnel_mode;
assert(sizeof(u64_t)==8); assert(sizeof(u64_t)==8);

View File

@ -18,6 +18,11 @@ TAR=${NAME}_binaries.tar.gz `echo ${TARGETS}|sed -r 's/([^ ]+)/speederv2_\1/g'`
all:git_version all:git_version
rm -f ${NAME} rm -f ${NAME}
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -ggdb -static -O3 ${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -ggdb -static -O3
mac:git_version
rm -f ${NAME}
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -ggdb -O3 -Wno-c++17-compat-mangling
debug: git_version debug: git_version
rm -f ${NAME} rm -f ${NAME}
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -Wformat-nonliteral -D MY_DEBUG ${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -Wformat-nonliteral -D MY_DEBUG