+/*
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
-/* $Id: getfullhostname.c,v 1.4 1996/04/14 03:25:23 wessels Exp $ */
+#include "squid.h"
+#include "getfullhostname.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+#if HAVE_UNISTD_H
+/* for gethostname() function */
+#include <unistd.h>
+#endif
+#if HAVE_NETDB_H
+/* for gethostbyname() */
#include <netdb.h>
-#include "util.h"
+#endif
+/* for RFC 2181 constants */
+#include "rfc2181.h"
-/*
- * getfullhostname() - Returns the fully qualified name of the current
- * host, or NULL on error. Pointer is only valid until the next call
- * to the gethost*() functions.
+/* for xstrncpy() - may need breaking out of there. */
+#include "util.h"
+
+/**
+ \retval NULL An error occured.
+ \retval * The fully qualified name (FQDN) of the current host.
+ * Pointer is only valid until the next call to the gethost*() functions.
+ *
+ \todo Make this a squid String result so the duration limit is flexible.
*/
-char *getfullhostname()
+const char *
+getfullhostname(void)
{
- struct hostent *hp = NULL;
- static char buf[SQUIDHOSTNAMELEN + 1];
- extern int gethostname(); /* UNIX system call */
+ const struct hostent *hp = NULL;
+ static char buf[RFC2181_MAXHOSTNAMELEN + 1];
- if (gethostname(buf, SQUIDHOSTNAMELEN) < 0)
- return (NULL);
- if ((hp = gethostbyname(buf)) == NULL)
- return (buf);
- return (hp->h_name);
+ if (gethostname(buf, RFC2181_MAXHOSTNAMELEN) < 0)
+ return NULL;
+ /** \todo convert this to a getaddrinfo() call */
+ if ((hp = gethostbyname(buf)) != NULL)
+ xstrncpy(buf, hp->h_name, RFC2181_MAXHOSTNAMELEN);
+ return buf;
}
+