From e7b22a000c65536c397242f9f0c6e5c2ac6a3281 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 4 Feb 2009 00:27:29 +0000 Subject: added linux support for new ifconfig usage --- src/tun_helper.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/tun_helper.h') diff --git a/src/tun_helper.h b/src/tun_helper.h index 47c8033..db5fd6a 100644 --- a/src/tun_helper.h +++ b/src/tun_helper.h @@ -36,6 +36,9 @@ #define _TUN_HELPER_H_ #include +#include +#include +#include void tun_conf(tun_device_t* dev, const char* dev_name, const char* dev_type, const char* ifcfg_addr, u_int16_t ifcfg_prefix, u_int16_t mtu) { @@ -57,10 +60,21 @@ void tun_conf(tun_device_t* dev, const char* dev_name, const char* dev_type, con } dev->net_addr_ = NULL; + dev->net_mask_ = NULL; dev->prefix_length_ = 0; if(ifcfg_addr) { dev->net_addr_ = strdup(ifcfg_addr); dev->prefix_length_ = ifcfg_prefix; + + u_int32_t mask = 0; + u_int16_t i = 0; + for(i = 0; i < ifcfg_prefix; ++i) { + mask = mask >> 1; + mask |= 0x80000000L; + } + struct in_addr addr; + addr.s_addr = ntohl(mask); + dev->net_mask_ = strdup(inet_ntoa(addr)); } } -- cgit v1.2.3