mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-24 02:25:13 +00:00
Added setting of ip, does not seem to work though
This commit is contained in:
parent
a939ad4f16
commit
29f2433e78
33
src/tun.c
33
src/tun.c
@ -258,7 +258,7 @@ close_tun(int tun_fd)
|
|||||||
int
|
int
|
||||||
write_tun(int tun_fd, char *data, size_t len)
|
write_tun(int tun_fd, char *data, size_t len)
|
||||||
{
|
{
|
||||||
#if defined (FREEBSD) || defined (DARWIN) || defined(NETBSD)
|
#if defined (FREEBSD) || defined (DARWIN) || defined(NETBSD) || defined(WINDOWS32)
|
||||||
data += 4;
|
data += 4;
|
||||||
len -= 4;
|
len -= 4;
|
||||||
#else /* !FREEBSD/DARWIN */
|
#else /* !FREEBSD/DARWIN */
|
||||||
@ -285,7 +285,7 @@ write_tun(int tun_fd, char *data, size_t len)
|
|||||||
ssize_t
|
ssize_t
|
||||||
read_tun(int tun_fd, char *buf, size_t len)
|
read_tun(int tun_fd, char *buf, size_t len)
|
||||||
{
|
{
|
||||||
#if defined (FREEBSD) || defined (DARWIN) || defined(NETBSD)
|
#if defined (FREEBSD) || defined (DARWIN) || defined(NETBSD) || defined(WINDOWS32)
|
||||||
/* FreeBSD/Darwin/NetBSD has no header */
|
/* FreeBSD/Darwin/NetBSD has no header */
|
||||||
return read(tun_fd, buf + 4, len - 4) + 4;
|
return read(tun_fd, buf + 4, len - 4) + 4;
|
||||||
#else /* !FREEBSD */
|
#else /* !FREEBSD */
|
||||||
@ -340,11 +340,38 @@ tun_setip(const char *ip, int netbits)
|
|||||||
return 1;
|
return 1;
|
||||||
#else /* WINDOWS32 */
|
#else /* WINDOWS32 */
|
||||||
DWORD status;
|
DWORD status;
|
||||||
|
DWORD ipdata[3];
|
||||||
|
struct in_addr addr;
|
||||||
|
int i;
|
||||||
|
int netmask;
|
||||||
DWORD len;
|
DWORD len;
|
||||||
|
BOOL res;
|
||||||
|
|
||||||
/* Set device as connected */
|
/* Set device as connected */
|
||||||
status = 1;
|
status = 1;
|
||||||
DeviceIoControl(dev_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof(status), &len, NULL);
|
res =DeviceIoControl(dev_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status,
|
||||||
|
sizeof(status), &status, sizeof(status), &len, NULL);
|
||||||
|
if (!res) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
netmask = 0;
|
||||||
|
for (i = 0; i < netbits; i++) {
|
||||||
|
netmask = (netmask << 1) | 1;
|
||||||
|
}
|
||||||
|
netmask <<= (32 - netbits);
|
||||||
|
ipdata[2] = (DWORD) htonl(netmask);
|
||||||
|
|
||||||
|
if (inet_aton(ip, &addr)) {
|
||||||
|
ipdata[0] = (DWORD) addr.s_addr;
|
||||||
|
ipdata[1] = ipdata[2] & ipdata[0]; /* Get network bits */
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
res = DeviceIoControl(dev_handle, TAP_IOCTL_CONFIG_TUN, &ipdata,
|
||||||
|
sizeof(ipdata), &ipdata, sizeof(ipdata), &len, NULL);
|
||||||
|
if (!res) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user