diff options
author | Martin Willi <martin@revosec.ch> | 2013-04-12 13:03:21 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2013-05-06 16:10:11 +0200 |
commit | 2af65b26d90a85ade6406dfc1bed244aae1767dd (patch) | |
tree | 7a346e9e98d9973e4ac9d770e99a69d82d728e76 | |
parent | 60babe02364de90737f91c56e16a54692e5cca9c (diff) | |
download | strongswan-2af65b26d90a85ade6406dfc1bed244aae1767dd.tar.bz2 strongswan-2af65b26d90a85ade6406dfc1bed244aae1767dd.tar.xz |
tun_device: add a getter for the address previously passed to set_address()
-rw-r--r-- | src/libstrongswan/networking/tun_device.c | 24 | ||||
-rw-r--r-- | src/libstrongswan/networking/tun_device.h | 8 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/libstrongswan/networking/tun_device.c b/src/libstrongswan/networking/tun_device.c index b0be8688e..2191198e2 100644 --- a/src/libstrongswan/networking/tun_device.c +++ b/src/libstrongswan/networking/tun_device.c @@ -73,6 +73,16 @@ struct private_tun_device_t { * The current MTU */ int mtu; + + /** + * Associated address + */ + host_t *address; + + /** + * Netmask for address + */ + u_int8_t netmask; }; METHOD(tun_device_t, set_address, bool, @@ -117,9 +127,21 @@ METHOD(tun_device_t, set_address, bool, this->if_name, strerror(errno)); return FALSE; } + this->address = addr->clone(addr); + this->netmask = netmask; return TRUE; } +METHOD(tun_device_t, get_address, host_t*, + private_tun_device_t *this, u_int8_t *netmask) +{ + if (netmask && this->address) + { + *netmask = this->netmask; + } + return this->address; +} + METHOD(tun_device_t, up, bool, private_tun_device_t *this) { @@ -277,6 +299,7 @@ METHOD(tun_device_t, destroy, void, { close(this->sock); } + DESTROY_IF(this->address); free(this); } @@ -406,6 +429,7 @@ tun_device_t *tun_device_create(const char *name_tmpl) .get_name = _get_name, .get_fd = _get_fd, .set_address = _set_address, + .get_address = _get_address, .up = _up, .destroy = _destroy, }, diff --git a/src/libstrongswan/networking/tun_device.h b/src/libstrongswan/networking/tun_device.h index 3bdb02a5d..1d330f133 100644 --- a/src/libstrongswan/networking/tun_device.h +++ b/src/libstrongswan/networking/tun_device.h @@ -66,6 +66,14 @@ struct tun_device_t { bool (*set_address)(tun_device_t *this, host_t *addr, u_int8_t netmask); /** + * Get the IP address previously assigned to using set_address(). + * + * @param netmask pointer receiving the configured netmask, or NULL + * @return address previously set, NULL if none + */ + host_t* (*get_address)(tun_device_t *this, u_int8_t *netmask); + + /** * Bring the TUN device up * * @return TRUE if operation successful |