summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2016-09-30 09:21:50 +0200
committerGravatar Christian Hesse <mail@eworm.de>2016-09-30 09:21:50 +0200
commit14ad87900ea7a286a2b1319f8a19df6b3736d42e (patch)
treea349b39cffbd6c60c6663f38166b883176170ff6
parent4b19f5d7fa199439db85b4f8144fcde34da5617d (diff)
downloaddyndhcpd-14ad87900ea7a286a2b1319f8a19df6b3736d42e.tar.gz
dyndhcpd-14ad87900ea7a286a2b1319f8a19df6b3736d42e.tar.zst
add error handling for hostname
-rw-r--r--dyndhcpd.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/dyndhcpd.c b/dyndhcpd.c
index bee300a..a9283a0 100644
--- a/dyndhcpd.c
+++ b/dyndhcpd.c
@@ -107,8 +107,13 @@ int main(int argc, char ** argv) {
goto out;
}
+ /* get the hostname */
+ if (gethostname(hostname, HOST_NAME_MAX) == -1) {
+ fprintf(stderr, "Failed to get the hostname.\n");
+ goto out;
+ }
+
/* get the domainname */
- gethostname(hostname, HOST_NAME_MAX);
hp = gethostbyname(hostname);
if ((domainname = strchr(hp->h_name, '.')) != NULL)
domainname++;