1
/***************************************************************************
3
* Project ___| | | | _ \| |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
8
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
10
* This software is licensed as described in the file COPYING, which
11
* you should have received as part of this distribution. The terms
12
* are also available at http://curl.haxx.se/docs/copyright.html.
14
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
* copies of the Software, and permit persons to whom the Software is
16
* furnished to do so, under the terms of the COPYING file.
18
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
* KIND, either express or implied.
21
***************************************************************************/
29
#include "curl_gethostname.h"
32
* Curl_gethostname() is a wrapper around gethostname() which allows
33
* overriding the host name that the function would normally return.
34
* This capability is used by the test suite to verify exact matching
35
* of NTLM authentication, which exercises libcurl's MD4 and DES code.
37
* For libcurl debug enabled builds host name overriding takes place
38
* when environment variable CURL_GETHOSTNAME is set, using the value
39
* held by the variable to override returned host name.
41
* For libcurl shared library release builds the test suite preloads
42
* another shared library named libhostname using the LD_PRELOAD
43
* mechanism which intercepts, and might override, the gethostname()
44
* function call. In this case a given platform must support the
45
* LD_PRELOAD mechanism and additionally have environment variable
46
* CURL_GETHOSTNAME set in order to override the returned host name.
48
* For libcurl static library release builds no overriding takes place.
51
int Curl_gethostname(char *name, GETHOSTNAME_TYPE_ARG2 namelen) {
53
#ifndef HAVE_GETHOSTNAME
55
/* Allow compilation and return failure when unavailable */
64
/* Override host name when environment variable CURL_GETHOSTNAME is set */
65
const char *force_hostname = getenv("CURL_GETHOSTNAME");
67
strncpy(name, force_hostname, namelen);
68
name[namelen-1] = '\0';
72
#endif /* DEBUGBUILD */
74
/* The call to system's gethostname() might get intercepted by the
75
libhostname library when libcurl is built as a non-debug shared
76
library when running the test suite. */
77
return gethostname(name, namelen);