Wireless Daemon for Linux
 help / color / mirror / Atom feed
* [PATCH 1/4] net: Add l_net_hostname_is_root
@ 2019-12-11 23:08 Tim Kourt
  2019-12-11 23:08 ` [PATCH 2/4] net: Add l_net_hostname_is_localhost Tim Kourt
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tim Kourt @ 2019-12-11 23:08 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 1210 bytes --]

The function identifies if the given hostname is root domain name.
---
 ell/net.c | 23 +++++++++++++++++++++++
 ell/net.h |  1 +
 2 files changed, 24 insertions(+)

diff --git a/ell/net.c b/ell/net.c
index b5b5f9d..3b6e0dc 100644
--- a/ell/net.c
+++ b/ell/net.c
@@ -110,3 +110,26 @@ LIB_EXPORT char *l_net_get_name(uint32_t ifindex)
 
 	return l_strdup(ifr.ifr_name);
 }
+
+/**
+ * l_net_hostname_is_root:
+ * @hostname: Hostname to validate
+ *
+ * Identifies if the hostname given by @hostname is root domain name or
+ * not.
+ *
+ * Returns: #true if the given hostname is root and #false otherwise.
+ **/
+LIB_EXPORT bool l_net_hostname_is_root(const char *hostname)
+{
+	if (unlikely(!hostname))
+		return false;
+
+	if (!strcmp(hostname, ""))
+		return true;
+
+	if (!strcmp(hostname, "."))
+		return true;
+
+	return false;
+}
diff --git a/ell/net.h b/ell/net.h
index 25b1ca2..7afcf86 100644
--- a/ell/net.h
+++ b/ell/net.h
@@ -32,6 +32,7 @@ extern "C" {
 
 bool l_net_get_mac_address(uint32_t ifindex, uint8_t *out_addr);
 char *l_net_get_name(uint32_t ifindex);
+bool l_net_hostname_is_root(const char *hostname);
 
 #ifdef __cplusplus
 }
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-11 23:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-11 23:08 [PATCH 1/4] net: Add l_net_hostname_is_root Tim Kourt
2019-12-11 23:08 ` [PATCH 2/4] net: Add l_net_hostname_is_localhost Tim Kourt
2019-12-11 23:08 ` [PATCH 3/4] unit: Add tests for net Tim Kourt
2019-12-11 23:08 ` [PATCH 4/4] dhcp-lease: Add domain name option handler Tim Kourt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox