reduce diff

This commit is contained in:
wangyu- 2018-08-29 20:00:37 -05:00
parent c72480110f
commit 92fcdbb31a
3 changed files with 56 additions and 16 deletions

@ -347,6 +347,52 @@ int my_ip_t::from_str(char * str)
}*/
#if defined(__MINGW32__)
int inet_pton(int af, const char *src, void *dst)
{
struct sockaddr_storage ss;
int size = sizeof(ss);
char src_copy[max_addr_len+1];
ZeroMemory(&ss, sizeof(ss));
/* stupid non-const API */
strncpy (src_copy, src, max_addr_len+1);
src_copy[max_addr_len] = 0;
if (WSAStringToAddress(src_copy, af, NULL, (struct sockaddr *)&ss, &size) == 0) {
switch(af) {
case AF_INET:
*(struct in_addr *)dst = ((struct sockaddr_in *)&ss)->sin_addr;
return 1;
case AF_INET6:
*(struct in6_addr *)dst = ((struct sockaddr_in6 *)&ss)->sin6_addr;
return 1;
}
}
return 0;
}
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size)
{
struct sockaddr_storage ss;
unsigned long s = size;
ZeroMemory(&ss, sizeof(ss));
ss.ss_family = af;
switch(af) {
case AF_INET:
((struct sockaddr_in *)&ss)->sin_addr = *(struct in_addr *)src;
break;
case AF_INET6:
((struct sockaddr_in6 *)&ss)->sin6_addr = *(struct in6_addr *)src;
break;
default:
return NULL;
}
/* cannot direclty use &size because of strict aliasing rules */
return (WSAAddressToString((struct sockaddr *)&ss, sizeof(ss), NULL, dst, &s) == 0)?
dst : NULL;
}
char *get_sock_error()
{
static char buf[1000];

@ -17,20 +17,14 @@
#include<unistd.h>
#include<errno.h>
//#include <sys/epoll.h>
//#include <sys/wait.h>
#include <sys/stat.h>
#include <stdlib.h> //for exit(0);
#include <errno.h> //For errno - the error number
#include <fcntl.h>
#include <sys/time.h>
#include <time.h>
#include <stdarg.h>
#include <assert.h>
#include <pthread.h>
#if defined(UDP2RAW_MP)
@ -41,6 +35,7 @@
#include <pcap_wrapper.h>
#define NO_LIBNET
#endif
#ifndef NO_LIBNET
#include <libnet.h>
#endif
@ -70,8 +65,8 @@ typedef int socklen_t;
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#endif
@ -84,7 +79,6 @@ typedef int socklen_t;
#include <list>
using namespace std;
#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || \
defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ || \
defined(__BIG_ENDIAN__) || \
@ -115,7 +109,10 @@ using namespace std;
#error "endian detection failed"
#endif
#if defined(__MINGW32__)
int inet_pton(int af, const char *src, void *dst);
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
#define setsockopt(a,b,c,d,e) setsockopt(a,b,c,(const char *)(d),e)
#endif
@ -137,6 +134,7 @@ inline int sock_close(my_fd_t fd)
#endif
typedef unsigned long long u64_t; //this works on most platform,avoid using the PRId64
typedef long long i64_t;
@ -370,12 +368,10 @@ u64_t hton64(u64_t a);
void write_u16(char *,u16_t a);// network order
u16_t read_u16(char *);
void write_u32(char *,u32_t a);// network order
u32_t read_u32(char *);
void write_u64(char *,u64_t a);
u64_t read_uu64(char *);
u64_t read_u64(char *);
bool larger_than_u16(uint16_t a,uint16_t b);
bool larger_than_u32(u32_t a,u32_t b);
@ -416,7 +412,6 @@ int create_fifo(char * file);
void print_binary_chars(const char * a,int len);
template <class key_t>
struct lru_collector_t:not_copy_able_t
{
@ -505,6 +500,4 @@ struct lru_collector_t:not_copy_able_t
};
#endif /* COMMON_H_ */

@ -460,6 +460,7 @@ void remove_filter()
//exit(-1);
}
}
int init_ifindex(const char * if_name,int fd,int &index)
{
struct ifreq ifr;
@ -1327,7 +1328,7 @@ int send_raw_tcp(raw_info_t &raw_info,const char * payload, int payloadlen) {
tcph->urg = 0;
//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->urg_ptr = 0;
@ -2266,7 +2267,7 @@ int after_send_raw0(raw_info_t &raw_info)
send_info.seq += raw_info.send_info.data_len; //////////////////modify
} 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
}
else if(seq_mode==3||seq_mode==4)