mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-02-07 23:59:36 +08:00
mingw compiles but not work yet
This commit is contained in:
parent
26b356866f
commit
f75eb798dc
185
common.cpp
185
common.cpp
@ -9,9 +9,93 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
|
#include <random>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
static int random_number_fd=-1;
|
static int random_number_fd=-1;
|
||||||
|
|
||||||
|
int init_ws()
|
||||||
|
{
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
WORD wVersionRequested;
|
||||||
|
WSADATA wsaData;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
/* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
|
||||||
|
wVersionRequested = MAKEWORD(2, 2);
|
||||||
|
|
||||||
|
err = WSAStartup(wVersionRequested, &wsaData);
|
||||||
|
if (err != 0) {
|
||||||
|
/* Tell the user that we could not find a usable */
|
||||||
|
/* Winsock DLL. */
|
||||||
|
printf("WSAStartup failed with error: %d\n", err);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Confirm that the WinSock DLL supports 2.2.*/
|
||||||
|
/* Note that if the DLL supports versions greater */
|
||||||
|
/* than 2.2 in addition to 2.2, it will still return */
|
||||||
|
/* 2.2 in wVersion since that is the version we */
|
||||||
|
/* requested. */
|
||||||
|
|
||||||
|
if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
|
||||||
|
/* Tell the user that we could not find a usable */
|
||||||
|
/* WinSock DLL. */
|
||||||
|
printf("Could not find a usable version of Winsock.dll\n");
|
||||||
|
WSACleanup();
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("The Winsock 2.2 dll was found okay");
|
||||||
|
}
|
||||||
|
|
||||||
|
int tmp[]={0,100,200,300,500,800,1000,2000,3000,4000,-1};
|
||||||
|
int succ=0;
|
||||||
|
for(int i=1;tmp[i]!=-1;i++)
|
||||||
|
{
|
||||||
|
if(_setmaxstdio(100)==-1) break;
|
||||||
|
else succ=i;
|
||||||
|
}
|
||||||
|
printf(", _setmaxstdio() was set to %d\n",tmp[succ]);
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
char *get_sock_error()
|
||||||
|
{
|
||||||
|
static char buf[1000];
|
||||||
|
int e=WSAGetLastError();
|
||||||
|
wchar_t *s = NULL;
|
||||||
|
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
|
NULL, e,
|
||||||
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
|
(LPWSTR)&s, 0, NULL);
|
||||||
|
sprintf(buf, "%d:%S", e,s);
|
||||||
|
int len=strlen(buf);
|
||||||
|
if(len>0&&buf[len-1]=='\n') buf[len-1]=0;
|
||||||
|
LocalFree(s);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
int get_sock_errno()
|
||||||
|
{
|
||||||
|
return WSAGetLastError();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
char *get_sock_error()
|
||||||
|
{
|
||||||
|
static char buf[1000];
|
||||||
|
sprintf(buf, "%d:%s", errno,strerror(errno));
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
int get_sock_errno()
|
||||||
|
{
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
u64_t get_current_time()
|
u64_t get_current_time()
|
||||||
{
|
{
|
||||||
timespec tmp_time;
|
timespec tmp_time;
|
||||||
@ -42,9 +126,12 @@ char * my_ntoa(u32_t ip)
|
|||||||
return inet_ntoa(a);
|
return inet_ntoa(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_random_number_fd()
|
#if !defined(__MINGW32__)
|
||||||
|
struct random_fd_t
|
||||||
|
{
|
||||||
|
int random_number_fd;
|
||||||
|
random_fd_t()
|
||||||
{
|
{
|
||||||
|
|
||||||
random_number_fd=open("/dev/urandom",O_RDONLY);
|
random_number_fd=open("/dev/urandom",O_RDONLY);
|
||||||
|
|
||||||
if(random_number_fd==-1)
|
if(random_number_fd==-1)
|
||||||
@ -54,28 +141,88 @@ void init_random_number_fd()
|
|||||||
}
|
}
|
||||||
setnonblocking(random_number_fd);
|
setnonblocking(random_number_fd);
|
||||||
}
|
}
|
||||||
|
int get_fd()
|
||||||
|
{
|
||||||
|
return random_number_fd;
|
||||||
|
}
|
||||||
|
}random_fd;
|
||||||
|
#else
|
||||||
|
struct my_random_t
|
||||||
|
{
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 gen;
|
||||||
|
std::uniform_int_distribution<u64_t> dis64;
|
||||||
|
std::uniform_int_distribution<u32_t> dis32;
|
||||||
|
|
||||||
|
std::uniform_int_distribution<unsigned char> dis8;
|
||||||
|
|
||||||
|
my_random_t()
|
||||||
|
{
|
||||||
|
std::mt19937 gen_tmp(rd());
|
||||||
|
gen=gen_tmp;
|
||||||
|
gen.discard(700000); //magic
|
||||||
|
}
|
||||||
|
u64_t gen64()
|
||||||
|
{
|
||||||
|
return dis64(gen);
|
||||||
|
}
|
||||||
|
u32_t gen32()
|
||||||
|
{
|
||||||
|
return dis32(gen);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char gen8()
|
||||||
|
{
|
||||||
|
return dis8(gen);
|
||||||
|
}
|
||||||
|
/*int random_number_fd;
|
||||||
|
random_fd_t()
|
||||||
|
{
|
||||||
|
random_number_fd=open("/dev/urandom",O_RDONLY);
|
||||||
|
if(random_number_fd==-1)
|
||||||
|
{
|
||||||
|
mylog(log_fatal,"error open /dev/urandom\n");
|
||||||
|
myexit(-1);
|
||||||
|
}
|
||||||
|
setnonblocking(random_number_fd);
|
||||||
|
}
|
||||||
|
int get_fd()
|
||||||
|
{
|
||||||
|
return random_number_fd;
|
||||||
|
}*/
|
||||||
|
}my_random;
|
||||||
|
#endif
|
||||||
|
|
||||||
u64_t get_true_random_number_64()
|
u64_t get_true_random_number_64()
|
||||||
{
|
{
|
||||||
|
#if !defined(__MINGW32__)
|
||||||
u64_t ret;
|
u64_t ret;
|
||||||
int size=read(random_number_fd,&ret,sizeof(ret));
|
int size=read(random_fd.get_fd(),&ret,sizeof(ret));
|
||||||
if(size!=sizeof(ret))
|
if(size!=sizeof(ret))
|
||||||
{
|
{
|
||||||
mylog(log_fatal,"get random number failed %d\n",size);
|
mylog(log_fatal,"get random number failed %d\n",size);
|
||||||
|
|
||||||
myexit(-1);
|
myexit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
#else
|
||||||
|
return my_random.gen64(); //fake random number
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
u32_t get_true_random_number()
|
u32_t get_true_random_number()
|
||||||
{
|
{
|
||||||
|
#if !defined(__MINGW32__)
|
||||||
u32_t ret;
|
u32_t ret;
|
||||||
int size=read(random_number_fd,&ret,sizeof(ret));
|
int size=read(random_fd.get_fd(),&ret,sizeof(ret));
|
||||||
if(size!=sizeof(ret))
|
if(size!=sizeof(ret))
|
||||||
{
|
{
|
||||||
mylog(log_fatal,"get random number failed %d\n",size);
|
mylog(log_fatal,"get random number failed %d\n",size);
|
||||||
myexit(-1);
|
myexit(-1);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
#else
|
||||||
|
return my_random.gen64(); //fake random number
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
u32_t get_true_random_number_nz() //nz for non-zero
|
u32_t get_true_random_number_nz() //nz for non-zero
|
||||||
{
|
{
|
||||||
@ -86,6 +233,7 @@ u32_t get_true_random_number_nz() //nz for non-zero
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int is_big_endian()
|
inline int is_big_endian()
|
||||||
{
|
{
|
||||||
int i=1;
|
int i=1;
|
||||||
@ -109,6 +257,7 @@ u64_t hton64(u64_t a)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setnonblocking(int sock) {
|
void setnonblocking(int sock) {
|
||||||
|
#if !defined(__MINGW32__)
|
||||||
int opts;
|
int opts;
|
||||||
opts = fcntl(sock, F_GETFL);
|
opts = fcntl(sock, F_GETFL);
|
||||||
|
|
||||||
@ -123,7 +272,14 @@ void setnonblocking(int sock) {
|
|||||||
//perror("fcntl(sock,SETFL,opts)");
|
//perror("fcntl(sock,SETFL,opts)");
|
||||||
myexit(1);
|
myexit(1);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
int iResult;
|
||||||
|
u_long iMode = 1;
|
||||||
|
iResult = ioctlsocket(sock, FIONBIO, &iMode);
|
||||||
|
if (iResult != NO_ERROR)
|
||||||
|
printf("ioctlsocket failed with error: %d\n", iResult);
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -154,8 +310,11 @@ unsigned short csum(const unsigned short *ptr,int nbytes) {//works both for big
|
|||||||
|
|
||||||
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(force_socket_buf)
|
||||||
{
|
{
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
assert(0==1);
|
||||||
|
#else
|
||||||
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));
|
||||||
@ -166,8 +325,10 @@ 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);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
else*/
|
else
|
||||||
{
|
{
|
||||||
if(setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &socket_buf_size, sizeof(socket_buf_size))<0)
|
if(setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||||
{
|
{
|
||||||
@ -180,6 +341,7 @@ int set_buf_size(int fd,int socket_buf_size,int force_socket_buf)
|
|||||||
myexit(1);
|
myexit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,7 +549,10 @@ int read_file(const char * file,string &output)
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int run_command(string command0,char * &output,int flag) {
|
int run_command(string command0,char * &output,int flag) {
|
||||||
|
assert(0==1 && "not implemented\n");
|
||||||
|
#if 0
|
||||||
FILE *in;
|
FILE *in;
|
||||||
|
|
||||||
|
|
||||||
@ -441,6 +606,7 @@ int run_command(string command0,char * &output,int flag) {
|
|||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -561,6 +727,7 @@ vector<string> parse_conf_line(const string& s0)
|
|||||||
|
|
||||||
int create_fifo(char * file)
|
int create_fifo(char * file)
|
||||||
{
|
{
|
||||||
|
#if !defined(__MINGW32__)
|
||||||
if(mkfifo (file, 0666)!=0)
|
if(mkfifo (file, 0666)!=0)
|
||||||
{
|
{
|
||||||
if(errno==EEXIST)
|
if(errno==EEXIST)
|
||||||
@ -594,6 +761,10 @@ int create_fifo(char * file)
|
|||||||
|
|
||||||
setnonblocking(fifo_fd);
|
setnonblocking(fifo_fd);
|
||||||
return fifo_fd;
|
return fifo_fd;
|
||||||
|
#else
|
||||||
|
assert(0==1&&"not implemented");
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ip_port_t::from_u64(u64_t u64)
|
void ip_port_t::from_u64(u64_t u64)
|
||||||
|
43
common.h
43
common.h
@ -19,8 +19,7 @@
|
|||||||
#include<errno.h>
|
#include<errno.h>
|
||||||
//#include <sys/epoll.h>
|
//#include <sys/epoll.h>
|
||||||
//#include <sys/wait.h>
|
//#include <sys/wait.h>
|
||||||
#include <sys/socket.h> //for socket ofcourse
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdlib.h> //for exit(0);
|
#include <stdlib.h> //for exit(0);
|
||||||
#include <errno.h> //For errno - the error number
|
#include <errno.h> //For errno - the error number
|
||||||
@ -38,7 +37,6 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
//#include <sys/timerfd.h>
|
//#include <sys/timerfd.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>
|
||||||
@ -48,7 +46,7 @@
|
|||||||
//#include <byteswap.h>
|
//#include <byteswap.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#ifndef __CYGWIN__
|
#if !defined(__CYGWIN__) && !defined(__MINGW32__)
|
||||||
#include <pcap.h>
|
#include <pcap.h>
|
||||||
#else
|
#else
|
||||||
#include <pcap_wrapper.h>
|
#include <pcap_wrapper.h>
|
||||||
@ -61,6 +59,19 @@
|
|||||||
|
|
||||||
#include <my_ev.h>
|
#include <my_ev.h>
|
||||||
|
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
#include <winsock2.h>
|
||||||
|
typedef unsigned char u_int8_t;
|
||||||
|
typedef unsigned short u_int16_t;
|
||||||
|
typedef unsigned int u_int32_t;
|
||||||
|
typedef int socklen_t;
|
||||||
|
#else
|
||||||
|
#include <sys/socket.h> //for socket ofcourse
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include<unordered_map>
|
#include<unordered_map>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -100,6 +111,29 @@ using namespace std;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
#define setsockopt(a,b,c,d,e) setsockopt(a,b,c,(const char *)(d),e)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char *get_sock_error();
|
||||||
|
int get_sock_errno();
|
||||||
|
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
typedef SOCKET my_fd_t;
|
||||||
|
inline int sock_close(my_fd_t fd)
|
||||||
|
{
|
||||||
|
return closesocket(fd);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
typedef int my_fd_t;
|
||||||
|
inline int sock_close(my_fd_t fd)
|
||||||
|
{
|
||||||
|
return close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
typedef unsigned long long u64_t; //this works on most platform,avoid using the PRId64
|
typedef unsigned long long u64_t; //this works on most platform,avoid using the PRId64
|
||||||
typedef long long i64_t;
|
typedef long long i64_t;
|
||||||
|
|
||||||
@ -173,6 +207,7 @@ struct queue_t
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int init_ws();
|
||||||
|
|
||||||
u64_t get_current_time();
|
u64_t get_current_time();
|
||||||
u64_t pack_u64(u32_t a,u32_t b);
|
u64_t pack_u64(u32_t a,u32_t b);
|
||||||
|
@ -2473,7 +2473,8 @@ evpipe_write (EV_P_ EV_ATOMIC_T *flag)
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSABUF buf;
|
WSABUF buf;
|
||||||
DWORD sent;
|
DWORD sent;
|
||||||
buf.buf = &buf;
|
// buf.buf=&buf;
|
||||||
|
buf.buf = (char *)&buf;
|
||||||
buf.len = 1;
|
buf.len = 1;
|
||||||
WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0);
|
WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0);
|
||||||
#else
|
#else
|
||||||
|
15
main.cpp
15
main.cpp
@ -1033,9 +1033,12 @@ void sigint_cb(struct ev_loop *l, ev_signal *w, int revents)
|
|||||||
myexit(0);
|
myexit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <winsock2.h>
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
|
init_ws();
|
||||||
|
|
||||||
int i=0;
|
int i=0;
|
||||||
|
|
||||||
//libnet_t *l; /* the libnet context */
|
//libnet_t *l; /* the libnet context */
|
||||||
@ -1051,9 +1054,13 @@ int main(int argc, char *argv[])
|
|||||||
//signal(SIGQUIT, signal_handler);
|
//signal(SIGQUIT, signal_handler);
|
||||||
|
|
||||||
struct ev_loop* loop=ev_default_loop(0);
|
struct ev_loop* loop=ev_default_loop(0);
|
||||||
|
printf("%x %x\n",ev_supported_backends(),ev_backend(loop));
|
||||||
|
|
||||||
|
#if !defined(__MINGW32__)
|
||||||
ev_signal signal_watcher_sigpipe;
|
ev_signal signal_watcher_sigpipe;
|
||||||
ev_signal_init(&signal_watcher_sigpipe, sigpipe_cb, SIGPIPE);
|
ev_signal_init(&signal_watcher_sigpipe, sigpipe_cb, SIGPIPE);
|
||||||
ev_signal_start(loop, &signal_watcher_sigpipe);
|
ev_signal_start(loop, &signal_watcher_sigpipe);
|
||||||
|
#endif
|
||||||
|
|
||||||
ev_signal signal_watcher_sigterm;
|
ev_signal signal_watcher_sigterm;
|
||||||
ev_signal_init(&signal_watcher_sigterm, sigterm_cb, SIGTERM);
|
ev_signal_init(&signal_watcher_sigterm, sigterm_cb, SIGTERM);
|
||||||
@ -1065,7 +1072,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
|
|
||||||
pre_process_arg(argc,argv);
|
pre_process_arg(argc,argv);
|
||||||
|
#if !defined(__MINGW32__)
|
||||||
if(geteuid() != 0)
|
if(geteuid() != 0)
|
||||||
{
|
{
|
||||||
mylog(log_warn,"root check failed, it seems like you are using a non-root account. we can try to continue, but it may fail. If you want to run udp2raw as non-root, you have to add iptables rule manually, and grant udp2raw CAP_NET_RAW capability, check README.md in repo for more info.\n");
|
mylog(log_warn,"root check failed, it seems like you are using a non-root account. we can try to continue, but it may fail. If you want to run udp2raw as non-root, you have to add iptables rule manually, and grant udp2raw CAP_NET_RAW capability, check README.md in repo for more info.\n");
|
||||||
@ -1074,7 +1081,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
mylog(log_warn,"you can run udp2raw with non-root account for better security. check README.md in repo for more info.\n");
|
mylog(log_warn,"you can run udp2raw with non-root account for better security. check README.md in repo for more info.\n");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
local_ip_uint32=inet_addr(local_ip);
|
local_ip_uint32=inet_addr(local_ip);
|
||||||
source_ip_uint32=inet_addr(source_ip);
|
source_ip_uint32=inet_addr(source_ip);
|
||||||
|
|
||||||
@ -1082,7 +1089,7 @@ int main(int argc, char *argv[])
|
|||||||
mylog(log_info,"remote_ip=[%s], make sure this is a vaild IP address\n",remote_ip);
|
mylog(log_info,"remote_ip=[%s], make sure this is a vaild IP address\n",remote_ip);
|
||||||
remote_ip_uint32=inet_addr(remote_ip);
|
remote_ip_uint32=inet_addr(remote_ip);
|
||||||
|
|
||||||
init_random_number_fd();
|
//init_random_number_fd();
|
||||||
srand(get_true_random_number_nz());
|
srand(get_true_random_number_nz());
|
||||||
const_id=get_true_random_number_nz();
|
const_id=get_true_random_number_nz();
|
||||||
|
|
||||||
|
4
makefile
4
makefile
@ -32,6 +32,10 @@ cygwin:git_version
|
|||||||
rm -f ${NAME}
|
rm -f ${NAME}
|
||||||
${cc_local} -o ${NAME} -I. ${SOURCES} pcap_wrapper.cpp ${FLAGS} -lrt -ggdb -static -O2 -D_GNU_SOURCE
|
${cc_local} -o ${NAME} -I. ${SOURCES} pcap_wrapper.cpp ${FLAGS} -lrt -ggdb -static -O2 -D_GNU_SOURCE
|
||||||
|
|
||||||
|
mingw:git_version
|
||||||
|
rm -f ${NAME}
|
||||||
|
${cc_local} -o ${NAME} -I. ${SOURCES} pcap_wrapper.cpp ${FLAGS} -ggdb -static -O2 -lws2_32
|
||||||
|
|
||||||
linux:git_version
|
linux:git_version
|
||||||
rm -f ${NAME}
|
rm -f ${NAME}
|
||||||
${cc_local} -o ${NAME} -I. ${SOURCES} ${PCAP} ${LIBNET} ${FLAGS} -lrt -ggdb -static -O2
|
${cc_local} -o ${NAME} -I. ${SOURCES} ${PCAP} ${LIBNET} ${FLAGS} -lrt -ggdb -static -O2
|
||||||
|
2
misc.cpp
2
misc.cpp
@ -533,7 +533,7 @@ void process_arg(int argc, char *argv[]) //process all options
|
|||||||
else if(strcmp(long_options[option_index].name,"lower-level")==0)
|
else if(strcmp(long_options[option_index].name,"lower-level")==0)
|
||||||
{
|
{
|
||||||
assert(0==1);
|
assert(0==1);
|
||||||
process_lower_level_arg();
|
//process_lower_level_arg();
|
||||||
//lower_level=1;
|
//lower_level=1;
|
||||||
//strcpy(lower_level_arg,optarg);
|
//strcpy(lower_level_arg,optarg);
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,17 @@
|
|||||||
#define EV_STANDALONE 1
|
#define EV_STANDALONE 1
|
||||||
#define EV_COMMON void *data; unsigned long long u64;
|
#define EV_COMMON void *data; unsigned long long u64;
|
||||||
#define EV_COMPAT3 0
|
#define EV_COMPAT3 0
|
||||||
|
|
||||||
|
//#include <wepoll.h>
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
//#define EV_USE_SELECT 1
|
||||||
|
#define EV_SELECT_IS_WINSOCKET 1
|
||||||
|
|
||||||
|
# define EV_FD_TO_WIN32_HANDLE(fd) (fd)
|
||||||
|
# define EV_WIN32_HANDLE_TO_FD(handle) (handle)
|
||||||
|
# define EV_WIN32_CLOSE_FD(fd) closesocket (fd)
|
||||||
|
# define FD_SETSIZE 4096
|
||||||
|
|
||||||
|
#endif
|
||||||
//#define EV_VERIFY 2
|
//#define EV_VERIFY 2
|
||||||
|
|
||||||
|
@ -586,6 +586,8 @@ int init_ifindex(const char * if_name,int &index)
|
|||||||
*/
|
*/
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
bool interface_has_arp(const char * interface) {
|
bool interface_has_arp(const char * interface) {
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
// int sock = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
|
// int sock = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
|
||||||
@ -600,6 +602,7 @@ bool interface_has_arp(const char * interface) {
|
|||||||
//close(sock);
|
//close(sock);
|
||||||
return !(ifr.ifr_flags & IFF_NOARP);
|
return !(ifr.ifr_flags & IFF_NOARP);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
struct route_info_t
|
struct route_info_t
|
||||||
{
|
{
|
||||||
string if_name;
|
string if_name;
|
||||||
@ -1273,7 +1276,7 @@ int send_raw_tcp(raw_info_t &raw_info,const char * payload, int payloadlen) {
|
|||||||
|
|
||||||
tcph->urg = 0;
|
tcph->urg = 0;
|
||||||
//tcph->window = htons((uint16_t)(1024));
|
//tcph->window = htons((uint16_t)(1024));
|
||||||
tcph->window = htons((uint16_t) (receive_window_lower_bound + random() % receive_window_random_range));
|
tcph->window = htons((uint16_t) (receive_window_lower_bound + get_true_random_number() % receive_window_random_range));
|
||||||
|
|
||||||
tcph->check = 0; //leave checksum 0 now, filled later by pseudo header
|
tcph->check = 0; //leave checksum 0 now, filled later by pseudo header
|
||||||
tcph->urg_ptr = 0;
|
tcph->urg_ptr = 0;
|
||||||
@ -2016,7 +2019,7 @@ int after_send_raw0(raw_info_t &raw_info)
|
|||||||
send_info.seq += raw_info.send_info.data_len; //////////////////modify
|
send_info.seq += raw_info.send_info.data_len; //////////////////modify
|
||||||
} else if (seq_mode == 2)
|
} else if (seq_mode == 2)
|
||||||
{
|
{
|
||||||
if (random() % 5 == 3)
|
if (get_true_random_number() % 5 == 3)
|
||||||
send_info.seq += raw_info.send_info.data_len; //////////////////modify
|
send_info.seq += raw_info.send_info.data_len; //////////////////modify
|
||||||
}
|
}
|
||||||
else if(seq_mode==3||seq_mode==4)
|
else if(seq_mode==3||seq_mode==4)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user