diff options
Diffstat (limited to 'imap4d/util.c')
-rw-r--r-- | imap4d/util.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/imap4d/util.c b/imap4d/util.c index 92f46bd7a..65fdb04ab 100644 --- a/imap4d/util.c +++ b/imap4d/util.c @@ -1,5 +1,5 @@ /* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 1999-2019 Free Software Foundation, Inc. + Copyright (C) 1999-2024 Free Software Foundation, Inc. GNU Mailutils is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -179,7 +179,7 @@ util_attribute_matches_flag (mu_attribute_t attr, const char *item) } char * -util_localname () +util_localname (void) { static char *localname; @@ -188,7 +188,7 @@ util_localname () char *name; int name_len = 256; int status = 1; - struct hostent *hp; + struct addrinfo hints, *res; name = malloc (name_len); while (name @@ -204,18 +204,17 @@ util_localname () exit (EX_OSERR); } - hp = gethostbyname (name); - if (hp) + memset (&hints, 0, sizeof (hints)); + hints.ai_family = AF_INET; + hints.ai_flags = AI_CANONNAME; + if (getaddrinfo (name, NULL, &hints, &res) == 0) { - struct in_addr inaddr; - inaddr.s_addr = *(unsigned int *) hp->h_addr; - hp = gethostbyaddr ((const char *) &inaddr, - sizeof (struct in_addr), AF_INET); - if (hp) + if (res->ai_canonname) { free (name); - name = mu_strdup ((char *) hp->h_name); + name = mu_strdup (res->ai_canonname); } + freeaddrinfo (res); } localname = name; } |