|
@ -228,7 +228,9 @@ int open_wintap(struct tuntap_dev *device, |
|
|
char *device_ip, |
|
|
char *device_ip, |
|
|
char *device_mask, |
|
|
char *device_mask, |
|
|
const char *device_mac, |
|
|
const char *device_mac, |
|
|
int mtu) { |
|
|
int mtu, |
|
|
|
|
|
int metric) { |
|
|
|
|
|
|
|
|
char cmd[256]; |
|
|
char cmd[256]; |
|
|
DWORD len; |
|
|
DWORD len; |
|
|
ULONG status = TRUE; |
|
|
ULONG status = TRUE; |
|
@ -299,14 +301,33 @@ int open_wintap(struct tuntap_dev *device, |
|
|
|
|
|
|
|
|
/* ****************** */ |
|
|
/* ****************** */ |
|
|
|
|
|
|
|
|
/* MTU and network metric */ |
|
|
/* MTU */ |
|
|
|
|
|
|
|
|
|
|
|
_snprintf(cmd, sizeof(cmd), |
|
|
|
|
|
"netsh interface ipv4 set subinterface \"%s\" mtu=%d store=persistent > nul", |
|
|
|
|
|
device->ifName, mtu); |
|
|
|
|
|
|
|
|
|
|
|
if(system(cmd) != 0) |
|
|
|
|
|
printf("WARNING: Unable to set device %s parameters MTU=%d store=persistent [%s]\n", |
|
|
|
|
|
device->ifName, mtu, cmd); |
|
|
|
|
|
|
|
|
|
|
|
/* ****************** */ |
|
|
|
|
|
|
|
|
|
|
|
/* metric */ |
|
|
|
|
|
|
|
|
|
|
|
device->metric = metric; |
|
|
|
|
|
|
|
|
_snprintf(cmd, sizeof(cmd), |
|
|
_snprintf(cmd, sizeof(cmd), |
|
|
"netsh interface ipv4 set subinterface \"%s\" mtu=%d metric=%d store=persistent > nul", |
|
|
"netsh interface ipv4 set interface \"%s\" metric=%d > nul", |
|
|
device->ifName, mtu, device->metric); |
|
|
device->ifName, device->metric); |
|
|
|
|
|
|
|
|
if(system(cmd) != 0) |
|
|
if(system(cmd) != 0) |
|
|
printf("WARNING: Unable to set device %s parameters MTU=%d metric=%d store=persistent [%s]\n", |
|
|
printf("WARNING: Unable to set device %s parameters metric=%d [%s]\n", |
|
|
device->ifName, mtu, device->metric, cmd); |
|
|
device->ifName, device->metric, cmd); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ****************** */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* set driver media status to 'connected' (i.e. set the interface up) */ |
|
|
/* set driver media status to 'connected' (i.e. set the interface up) */ |
|
|
if (!DeviceIoControl (device->device_handle, TAP_IOCTL_SET_MEDIA_STATUS, |
|
|
if (!DeviceIoControl (device->device_handle, TAP_IOCTL_SET_MEDIA_STATUS, |
|
@ -389,8 +410,9 @@ int tuntap_open(struct tuntap_dev *device, |
|
|
char *device_ip, |
|
|
char *device_ip, |
|
|
char *device_mask, |
|
|
char *device_mask, |
|
|
const char * device_mac, |
|
|
const char * device_mac, |
|
|
int mtu) { |
|
|
int mtu, |
|
|
return(open_wintap(device, dev, address_mode, device_ip, device_mask, device_mac, mtu)); |
|
|
int metric) { |
|
|
|
|
|
return(open_wintap(device, dev, address_mode, device_ip, device_mask, device_mac, mtu, metric)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* ************************************************ */ |
|
|
/* ************************************************ */ |
|
@ -415,7 +437,7 @@ int main(int argc, char* argv[]) { |
|
|
|
|
|
|
|
|
printf("Welcome to n2n\n"); |
|
|
printf("Welcome to n2n\n"); |
|
|
initWin32(); |
|
|
initWin32(); |
|
|
open_wintap(&tuntap, "static", "1.2.3.20", "255.255.255.0", mtu); |
|
|
open_wintap(&tuntap, "static", "1.2.3.20", "255.255.255.0", mtu, 0); |
|
|
|
|
|
|
|
|
for(i=0; i<10; i++) { |
|
|
for(i=0; i<10; i++) { |
|
|
u_char buf[MTU]; |
|
|
u_char buf[MTU]; |
|
|