mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Added DHCP::hostname.
This commit is contained in:
@@ -309,6 +309,15 @@ namespace Tins {
|
||||
* \param name The domain name.
|
||||
*/
|
||||
void domain_name(const std::string &name);
|
||||
|
||||
/**
|
||||
* \brief Adds a hostname option.
|
||||
*
|
||||
* The new option is appended at the end of the list.
|
||||
*
|
||||
* \param name The hostname.
|
||||
*/
|
||||
void hostname(const std::string &name);
|
||||
|
||||
// Option getters
|
||||
|
||||
@@ -423,6 +432,16 @@ namespace Tins {
|
||||
* \return std::string Containing the domain name.
|
||||
*/
|
||||
std::string domain_name() const;
|
||||
|
||||
/**
|
||||
* \brief Searchs for a hostname option.
|
||||
*
|
||||
* If the option is not found, an option_not_found exception
|
||||
* is thrown.
|
||||
*
|
||||
* \return std::string Containing the hostname.
|
||||
*/
|
||||
std::string hostname() const;
|
||||
|
||||
/**
|
||||
* \brief Getter for the options list.
|
||||
|
||||
@@ -187,6 +187,14 @@ std::string DHCP::domain_name() const {
|
||||
return search_and_convert<std::string>(DOMAIN_NAME);
|
||||
}
|
||||
|
||||
void DHCP::hostname(const std::string &name) {
|
||||
add_option(option(HOST_NAME, name.size(), (const uint8_t*)name.c_str()));
|
||||
}
|
||||
|
||||
std::string DHCP::hostname() const {
|
||||
return search_and_convert<std::string>(HOST_NAME);
|
||||
}
|
||||
|
||||
void DHCP::rebind_time(uint32_t time) {
|
||||
time = Endian::host_to_be(time);
|
||||
add_option(option(DHCP_REBINDING_TIME, sizeof(uint32_t), (uint8_t*)&time));
|
||||
|
||||
@@ -225,11 +225,18 @@ TEST_F(DHCPTest, DNSOption) {
|
||||
|
||||
TEST_F(DHCPTest, DomainNameOption) {
|
||||
DHCP dhcp;
|
||||
string domain = "libtins.test.domain", domain_found;
|
||||
string domain = "libtins.test.domain";
|
||||
dhcp.domain_name(domain);
|
||||
EXPECT_EQ(domain, dhcp.domain_name());
|
||||
}
|
||||
|
||||
TEST_F(DHCPTest, HostnameOption) {
|
||||
DHCP dhcp;
|
||||
string hostname = "libtins-hostname";
|
||||
dhcp.hostname(hostname);
|
||||
EXPECT_EQ(hostname, dhcp.hostname());
|
||||
}
|
||||
|
||||
TEST_F(DHCPTest, BroadcastOption) {
|
||||
DHCP dhcp;
|
||||
IPv4Address ip = "192.168.0.1", ip_found;
|
||||
|
||||
Reference in New Issue
Block a user