mirror of https://github.com/oxen-io/lokinet
make x.x.x.y+1 the default router on windows
This commit is contained in:
parent
400f5d3902
commit
f283c565e7
|
@ -11,10 +11,7 @@
|
|||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#pragma comment(lib, "iphlpapi.lib")
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
#include <strsafe.h>
|
||||
#endif
|
||||
|
||||
/// do a lokimq request on an lmq instance blocking style
|
||||
|
@ -319,6 +316,7 @@ AddDefaultRouteViaInterface(std::string ifname)
|
|||
#ifdef __linux__
|
||||
Execute("ip route add default dev " + ifname);
|
||||
#elif _WIN32
|
||||
ifname.back()++;
|
||||
Execute("route ADD 0.0.0.0 MASK 128.0.0.0 " + ifname);
|
||||
Execute("route ADD 128.0.0.0 MASK 128.0.0.0 " + ifname);
|
||||
#elif __APPLE__
|
||||
|
@ -334,6 +332,7 @@ DelDefaultRouteViaInterface(std::string ifname)
|
|||
#ifdef __linux__
|
||||
Execute("ip route del default dev " + ifname);
|
||||
#elif _WIN32
|
||||
ifname.back()++;
|
||||
Execute("route DELETE 0.0.0.0 MASK 128.0.0.0 " + ifname);
|
||||
Execute("route DELETE 128.0.0.0 MASK 128.0.0.0 " + ifname);
|
||||
#elif __APPLE__
|
||||
|
@ -399,7 +398,7 @@ GetGatewaysNotOnInterface(std::string ifname)
|
|||
gateway.S_un.S_addr = (u_long)pIpForwardTable->table[i].dwForwardDest;
|
||||
interface_addr.S_un.S_addr = (u_long)pIpForwardTable->table[i].dwForwardNextHop;
|
||||
std::array<char, 128> interface_str{};
|
||||
strcpy_s(interface_str.data(), interface_str.size(), inet_ntoa(interface_addr));
|
||||
StringCchCopy(interface_str.data(), interface_str.size(), inet_ntoa(interface_addr));
|
||||
std::string interface_name{interface_str.data()};
|
||||
if ((!gateway.S_un.S_addr) and interface_name != ifname)
|
||||
{
|
||||
|
|
|
@ -382,6 +382,12 @@ tuntap_sys_set_ipv4(struct device *dev, t_tun_in_addr *s, uint32_t mask)
|
|||
uint8_t length;
|
||||
uint32_t value[2];
|
||||
} dns;
|
||||
struct
|
||||
{
|
||||
uint8_t dhcp_opt;
|
||||
uint8_t length;
|
||||
uint32_t value;
|
||||
} gateway;
|
||||
#pragma pack(pop)
|
||||
|
||||
sock[0] = s->S_un.S_addr;
|
||||
|
@ -398,10 +404,10 @@ tuntap_sys_set_ipv4(struct device *dev, t_tun_in_addr *s, uint32_t mask)
|
|||
|
||||
ep[0] = s->S_un.S_addr;
|
||||
ep[1] = mask;
|
||||
ep[2] = (s->S_un.S_addr | ~mask)
|
||||
- (mask + 1); /* For the 10.x.0.y subnet (in a class C config), _should_
|
||||
ep[2] = (s->S_un.S_addr | ~mask) - htonl(1);
|
||||
/*+ (mask + 1);*/ /* For the 10.x.0.y subnet (in a class C config), _should_
|
||||
be 10.x.0.254 i think */
|
||||
ep[3] = 3153600; /* one year */
|
||||
ep[3] = 31536000; /* one year */
|
||||
|
||||
ret = DeviceIoControl(dev->tun_fd, TAP_IOCTL_CONFIG_DHCP_MASQ, ep, sizeof(ep),
|
||||
ep, sizeof(ep), &len, NULL);
|
||||
|
@ -427,6 +433,14 @@ tuntap_sys_set_ipv4(struct device *dev, t_tun_in_addr *s, uint32_t mask)
|
|||
ret = DeviceIoControl(dev->tun_fd, TAP_IOCTL_CONFIG_DHCP_SET_OPT, &dns,
|
||||
sizeof(dns), &dns, sizeof(dns), &len, NULL);
|
||||
|
||||
/* set router address to interface address */
|
||||
gateway.dhcp_opt = 3;
|
||||
gateway.length = 4;
|
||||
gateway.value = (s->S_un.S_addr)+htonl(1);
|
||||
|
||||
ret = DeviceIoControl(dev->tun_fd, TAP_IOCTL_CONFIG_DHCP_SET_OPT, &gateway,
|
||||
sizeof(gateway), &gateway, sizeof(gateway), &len, NULL);
|
||||
|
||||
if(!ret)
|
||||
{
|
||||
int errcode = GetLastError();
|
||||
|
@ -519,4 +533,4 @@ tuntap_set_ifname(struct device *dev, const char *name)
|
|||
tuntap_log(TUNTAP_LOG_NOTICE,
|
||||
"Your system does not support tuntap_set_ifname()");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue