tun_device: add a getter for the address previously passed to set_address()
This commit is contained in:
@@ -73,6 +73,16 @@ struct private_tun_device_t {
|
|||||||
* The current MTU
|
* The current MTU
|
||||||
*/
|
*/
|
||||||
int mtu;
|
int mtu;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Associated address
|
||||||
|
*/
|
||||||
|
host_t *address;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Netmask for address
|
||||||
|
*/
|
||||||
|
u_int8_t netmask;
|
||||||
};
|
};
|
||||||
|
|
||||||
METHOD(tun_device_t, set_address, bool,
|
METHOD(tun_device_t, set_address, bool,
|
||||||
@@ -117,9 +127,21 @@ METHOD(tun_device_t, set_address, bool,
|
|||||||
this->if_name, strerror(errno));
|
this->if_name, strerror(errno));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
this->address = addr->clone(addr);
|
||||||
|
this->netmask = netmask;
|
||||||
return TRUE;
|
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,
|
METHOD(tun_device_t, up, bool,
|
||||||
private_tun_device_t *this)
|
private_tun_device_t *this)
|
||||||
{
|
{
|
||||||
@@ -277,6 +299,7 @@ METHOD(tun_device_t, destroy, void,
|
|||||||
{
|
{
|
||||||
close(this->sock);
|
close(this->sock);
|
||||||
}
|
}
|
||||||
|
DESTROY_IF(this->address);
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,6 +429,7 @@ tun_device_t *tun_device_create(const char *name_tmpl)
|
|||||||
.get_name = _get_name,
|
.get_name = _get_name,
|
||||||
.get_fd = _get_fd,
|
.get_fd = _get_fd,
|
||||||
.set_address = _set_address,
|
.set_address = _set_address,
|
||||||
|
.get_address = _get_address,
|
||||||
.up = _up,
|
.up = _up,
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -65,6 +65,14 @@ struct tun_device_t {
|
|||||||
*/
|
*/
|
||||||
bool (*set_address)(tun_device_t *this, host_t *addr, u_int8_t netmask);
|
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
|
* Bring the TUN device up
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user