From 3450f14847fd73c49a3da3ddeea7a03ab1b525aa Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 13 Dec 2021 10:29:34 +0100 Subject: get hostname and domainname from gethostname() --- dyndhcpd.c | 11 +++++------ 1 file 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; } -- cgit v1.2.3-70-g09d2