summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2021-12-13 10:29:34 +0100
committerGravatar Christian Hesse <mail@eworm.de>2021-12-13 10:29:34 +0100
commit3450f14847fd73c49a3da3ddeea7a03ab1b525aa (patch)
tree39c106a59fef3233e6a5caf69d3d755c3447de8b
parentfcd828e19728c6c99d98ba246d2de3352c77507e (diff)
downloaddyndhcpd-3450f14847fd73c49a3da3ddeea7a03ab1b525aa.tar.gz
dyndhcpd-3450f14847fd73c49a3da3ddeea7a03ab1b525aa.tar.zst
get hostname and domainname from gethostname()
-rw-r--r--dyndhcpd.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/dyndhcpd.c b/dyndhcpd.c
index 873dc75..0cd009e 100644
--- a/dyndhcpd.c
+++ b/dyndhcpd.c
@@ -57,8 +57,7 @@ int main(int argc, char ** argv) {
char * interface = NULL;
char hostname[HOST_NAME_MAX];
- const char * domainname;
- struct hostent *hp;
+ char * domainname;
char * template = NULL;
FILE * templatefile;
@@ -140,11 +139,11 @@ int main(int argc, char ** argv) {
goto out;
}
- /* get the domainname */
- hp = gethostbyname(hostname);
- if (hp && (domainname = strchr(hp->h_name, '.')) != NULL)
+ /* get the domainname and strip it from hostname */
+ if ((domainname = strchr(hostname, '.')) != NULL) {
+ *domainname = 0;
domainname++;
- else {
+ } else {
fprintf(stderr, "Could not get domainname, using '" FALLBACKDOMAIN "'\n");
domainname = FALLBACKDOMAIN;
}