]> git.ipfire.org Git - thirdparty/squid.git/blob - lib/getfullhostname.c
cleanup; avoid compiler warning
[thirdparty/squid.git] / lib / getfullhostname.c
1
2 /*
3 * $Id: getfullhostname.c,v 1.10 1996/10/19 08:21:54 wessels Exp $
4 *
5 * DEBUG:
6 * AUTHOR: Harvest Derived
7 *
8 * SQUID Internet Object Cache http://www.nlanr.net/Squid/
9 * --------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from the
12 * Internet community. Development is led by Duane Wessels of the
13 * National Laboratory for Applied Network Research and funded by
14 * the National Science Foundation.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 *
30 */
31
32
33 /*
34 * Copyright (c) 1994, 1995. All rights reserved.
35 *
36 * The Harvest software was developed by the Internet Research Task
37 * Force Research Group on Resource Discovery (IRTF-RD):
38 *
39 * Mic Bowman of Transarc Corporation.
40 * Peter Danzig of the University of Southern California.
41 * Darren R. Hardy of the University of Colorado at Boulder.
42 * Udi Manber of the University of Arizona.
43 * Michael F. Schwartz of the University of Colorado at Boulder.
44 * Duane Wessels of the University of Colorado at Boulder.
45 *
46 * This copyright notice applies to software in the Harvest
47 * ``src/'' directory only. Users should consult the individual
48 * copyright notices in the ``components/'' subdirectories for
49 * copyright information about other software bundled with the
50 * Harvest source code distribution.
51 *
52 * TERMS OF USE
53 *
54 * The Harvest software may be used and re-distributed without
55 * charge, provided that the software origin and research team are
56 * cited in any use of the system. Most commonly this is
57 * accomplished by including a link to the Harvest Home Page
58 * (http://harvest.cs.colorado.edu/) from the query page of any
59 * Broker you deploy, as well as in the query result pages. These
60 * links are generated automatically by the standard Broker
61 * software distribution.
62 *
63 * The Harvest software is provided ``as is'', without express or
64 * implied warranty, and with no support nor obligation to assist
65 * in its use, correction, modification or enhancement. We assume
66 * no liability with respect to the infringement of copyrights,
67 * trade secrets, or any patents, and are not responsible for
68 * consequential damages. Proper use of the Harvest software is
69 * entirely the responsibility of the user.
70 *
71 * DERIVATIVE WORKS
72 *
73 * Users may make derivative works from the Harvest software, subject
74 * to the following constraints:
75 *
76 * - You must include the above copyright notice and these
77 * accompanying paragraphs in all forms of derivative works,
78 * and any documentation and other materials related to such
79 * distribution and use acknowledge that the software was
80 * developed at the above institutions.
81 *
82 * - You must notify IRTF-RD regarding your distribution of
83 * the derivative work.
84 *
85 * - You must clearly notify users that your are distributing
86 * a modified version and not the original Harvest software.
87 *
88 * - Any derivative product is also subject to these copyright
89 * and use restrictions.
90 *
91 * Note that the Harvest software is NOT in the public domain. We
92 * retain copyright, as specified above.
93 *
94 * HISTORY OF FREE SOFTWARE STATUS
95 *
96 * Originally we required sites to license the software in cases
97 * where they were going to build commercial products/services
98 * around Harvest. In June 1995 we changed this policy. We now
99 * allow people to use the core Harvest software (the code found in
100 * the Harvest ``src/'' directory) for free. We made this change
101 * in the interest of encouraging the widest possible deployment of
102 * the technology. The Harvest software is really a reference
103 * implementation of a set of protocols and formats, some of which
104 * we intend to standardize. We encourage commercial
105 * re-implementations of code complying to this set of standards.
106 */
107
108 #include "config.h"
109
110 #if HAVE_STDIO_H
111 #include <stdio.h>
112 #endif
113 #if HAVE_STDLIB_H
114 #include <stdlib.h>
115 #endif
116 #if HAVE_STRING_H
117 #include <string.h>
118 #endif
119 #if HAVE_SYS_PARAM_H
120 #include <sys/param.h>
121 #endif
122 #if HAVE_SYS_TYPES_H
123 #include <sys/types.h>
124 #endif
125 #if HAVE_SYS_SOCKET_H
126 #include <sys/socket.h>
127 #endif
128 #if HAVE_NETINET_IN_H
129 #include <netinet/in.h>
130 #endif
131 #if HAVE_ARPA_INET_H
132 #include <arpa/inet.h>
133 #endif
134 #if HAVE_NETDB_H && !defined(_SQUID_NETDB_H_) /* protect on NEXTSTEP */
135 #define _SQUID_NETDB_H_
136 #include <netdb.h>
137 #endif
138 #if HAVE_UNISTD_H
139 #include <unistd.h>
140 #endif
141
142 #include "ansiproto.h"
143 #include "util.h"
144
145 /*
146 * getfullhostname() - Returns the fully qualified name of the current
147 * host, or NULL on error. Pointer is only valid until the next call
148 * to the gethost*() functions.
149 */
150 char *
151 getfullhostname(void)
152 {
153 struct hostent *hp = NULL;
154 static char buf[SQUIDHOSTNAMELEN + 1];
155
156 if (gethostname(buf, SQUIDHOSTNAMELEN) < 0)
157 return NULL;
158 if ((hp = gethostbyname(buf)) != NULL)
159 strncpy(buf, hp->h_name, SQUIDHOSTNAMELEN);
160 return buf;
161 }