diff options
author | Christian Hesse <mail@eworm.de> | 2021-12-13 10:29:34 +0100 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2021-12-13 10:29:34 +0100 |
commit | 3450f14847fd73c49a3da3ddeea7a03ab1b525aa (patch) | |
tree | 39c106a59fef3233e6a5caf69d3d755c3447de8b | |
parent | fcd828e19728c6c99d98ba246d2de3352c77507e (diff) | |
download | dyndhcpd-3450f14847fd73c49a3da3ddeea7a03ab1b525aa.tar.gz dyndhcpd-3450f14847fd73c49a3da3ddeea7a03ab1b525aa.tar.zst |
get hostname and domainname from gethostname()
-rw-r--r-- | dyndhcpd.c | 11 |
1 files changed, 5 insertions, 6 deletions
@@ -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; } |