n2n/win32/n2n_win32.h
fengdaolong 92dfa67e22 Added DHCP function embedded in sn.
1. Automatically assign IP addresses to the edge through the DHCP function that comes with sn, the default IP address pool is 172.17.12.0/24.
2. The -d parameter is added to sn, and the IP address pool of the embedded DHCP can be customized.
3. Now edge does not need to add -a and -s parameters to automatically obtain the IP address.
4. The IP automatically obtained by the cross-community edge can be the same, because the communities are isolated from each other and do not interfere with each other.
5. On the management side of sn (127.0.0.1:5645), you can now view the IP address of the tutap adapter of each edge.
6. Fix many bugs that have a certain chance of causing memory leaks.
7. Note: This version is not fully compatible with the previous version.
2020-08-08 22:40:45 +08:00

115 lines
3.3 KiB
C

/*
(C) 2007-09 - Luca Deri <deri@ntop.org>
*/
#ifndef _N2N_WIN32_H_
#define _N2N_WIN32_H_
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#define WIN32_LEAN_AND_MEAN
#if defined(__MINGW32__)
/* should be defined here and before winsock gets included */
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x501 //Otherwise the linker doesnt find getaddrinfo
#endif /* #ifndef _WIN32_WINNT */
#include <inttypes.h>
#endif /* #if defined(__MINGW32__) */
#include <winsock2.h>
#include <windows.h>
#include <winioctl.h>
#include "wintap.h"
#ifdef _MSC_VER
#include "getopt.h"
/* Other Win environments are expected to support stdint.h */
/* stdint.h typedefs (C99) (not present in Visual Studio) */
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
/* sys/types.h typedefs (not present in Visual Studio) */
typedef unsigned int u_int32_t;
typedef unsigned short u_int16_t;
typedef unsigned char u_int8_t;
typedef int ssize_t;
#endif /* #ifdef _MSC_VER */
typedef unsigned long in_addr_t;
#undef EAFNOSUPPORT
#define EAFNOSUPPORT WSAEAFNOSUPPORT
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
#define snprintf _snprintf
#define strdup _strdup
#define socklen_t int
#define ETH_ADDR_LEN 6
/*
* Structure of a 10Mb/s Ethernet header.
*/
struct ether_hdr
{
uint8_t dhost[ETH_ADDR_LEN];
uint8_t shost[ETH_ADDR_LEN];
uint16_t type; /* higher layer protocol encapsulated */
};
typedef struct ether_hdr ether_hdr_t;
/* ************************************* */
struct ip {
#if BYTE_ORDER == LITTLE_ENDIAN
u_char ip_hl:4, /* header length */
ip_v:4; /* version */
#else
u_char ip_v:4, /* version */
ip_hl:4; /* header length */
#endif
u_char ip_tos; /* type of service */
short ip_len; /* total length */
u_short ip_id; /* identification */
short ip_off; /* fragment offset field */
#define IP_DF 0x4000 /* dont fragment flag */
#define IP_MF 0x2000 /* more fragments flag */
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
u_char ip_ttl; /* time to live */
u_char ip_p; /* protocol */
u_short ip_sum; /* checksum */
struct in_addr ip_src,ip_dst; /* source and dest address */
};
/* ************************************* */
typedef struct tuntap_dev {
HANDLE device_handle;
char *device_name;
char *ifName;
OVERLAPPED overlap_read, overlap_write;
n2n_mac_t mac_addr;
uint32_t ip_addr;
uint32_t device_mask;
unsigned int mtu;
} tuntap_dev;
#define index(a, b) strchr(a, b)
#define sleep(x) Sleep(x * 1000)
#endif