]>
Commit | Line | Data |
---|---|---|
30a4f2a8 | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
e25c139f | 3 | * |
0545caaa AJ |
4 | * Squid software is distributed under GPLv2+ license and includes |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
30a4f2a8 | 7 | */ |
0545caaa | 8 | |
f7f3304a | 9 | #include "squid.h" |
e1f7507e | 10 | #include "getfullhostname.h" |
0d94e9fe | 11 | |
e1f7507e AJ |
12 | #if HAVE_UNISTD_H |
13 | /* for gethostname() function */ | |
14 | #include <unistd.h> | |
15 | #endif | |
489520a9 | 16 | #if HAVE_NETDB_H |
e1f7507e | 17 | /* for gethostbyname() */ |
090089c4 | 18 | #include <netdb.h> |
30a4f2a8 | 19 | #endif |
090089c4 | 20 | |
e1f7507e AJ |
21 | /* for RFC 2181 constants */ |
22 | #include "rfc2181.h" | |
23 | ||
489520a9 | 24 | /* for xstrncpy() - may need breaking out of there. */ |
30a4f2a8 | 25 | #include "util.h" |
090089c4 | 26 | |
e1f7507e | 27 | /** |
61beade2 AJ |
28 | * \retval nullptr An error occurred. |
29 | * \retval * The fully qualified name (FQDN) of the current host. | |
30 | * Pointer is only valid until the next call to the | |
31 | * gethost*() functions. | |
090089c4 | 32 | */ |
0ee4272b | 33 | const char * |
0673c0ba | 34 | getfullhostname(void) |
090089c4 | 35 | { |
0ee4272b | 36 | const struct hostent *hp = NULL; |
61beade2 | 37 | // TODO: make this dynamic so the duration limit is flexible |
e1f7507e | 38 | static char buf[RFC2181_MAXHOSTNAMELEN + 1]; |
090089c4 | 39 | |
e1f7507e | 40 | if (gethostname(buf, RFC2181_MAXHOSTNAMELEN) < 0) |
26ac0430 | 41 | return NULL; |
61beade2 | 42 | // TODO: convert this to a getaddrinfo() call |
3b678c10 | 43 | if ((hp = gethostbyname(buf)) != NULL) |
26ac0430 | 44 | xstrncpy(buf, hp->h_name, RFC2181_MAXHOSTNAMELEN); |
3b678c10 | 45 | return buf; |
090089c4 | 46 | } |
f53969cc | 47 |