]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Move tor_gethostname to lib/net
authorNick Mathewson <nickm@torproject.org>
Thu, 28 Jun 2018 15:57:01 +0000 (11:57 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 28 Jun 2018 15:57:01 +0000 (11:57 -0400)
src/common/compat.c
src/common/compat.h
src/common/util.h
src/lib/net/gethostname.c [new file with mode: 0644]
src/lib/net/gethostname.h [new file with mode: 0644]
src/lib/net/include.am
src/or/config.c
src/test/test_config.c

index 1199fdae9b0623c6b8dd6eb7beee90b247ba37c0..e71931aa12716e39096cc4acea155bfca9869186 100644 (file)
@@ -257,17 +257,6 @@ set_max_file_descriptors(rlim_t limit, int *max_out)
   return 0;
 }
 
-/** Get name of current host and write it to <b>name</b> array, whose
- * length is specified by <b>namelen</b> argument. Return 0 upon
- * successful completion; otherwise return return -1. (Currently,
- * this function is merely a mockable wrapper for POSIX gethostname().)
- */
-MOCK_IMPL(int,
-tor_gethostname,(char *name, size_t namelen))
-{
-   return gethostname(name,namelen);
-}
-
 /** Hold the result of our call to <b>uname</b>. */
 static char uname_result[256];
 /** True iff uname_result is set. */
index e455dc8ef2839af344350a24b141ba741ae36c57..13e20a4ac22eb15d0496a860e10cfd4fa6e361e2 100644 (file)
 
 /* ===== Net compatibility */
 
-MOCK_DECL(int,tor_gethostname,(char *name, size_t namelen));
-
 /** Specified SOCKS5 status codes. */
 typedef enum {
   SOCKS5_SUCCEEDED                  = 0x00,
index 8007aa05c7cc3ac3bea4ee9afc3966bbe831d959..0f991f8c46d6fe16357b070ceadc2fd8dbb8dc2e 100644 (file)
@@ -72,7 +72,6 @@ int64_t clamp_double_to_int64(double number);
 
 /* String manipulation */
 
-
 /* Time helpers */
 long tv_udiff(const struct timeval *start, const struct timeval *end);
 long tv_mdiff(const struct timeval *start, const struct timeval *end);
diff --git a/src/lib/net/gethostname.c b/src/lib/net/gethostname.c
new file mode 100644 (file)
index 0000000..b6cc9b8
--- /dev/null
@@ -0,0 +1,25 @@
+/* Copyright (c) 2003-2004, Roger Dingledine
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#include "orconfig.h"
+#include "lib/net/gethostname.h"
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef _WIN32
+#include <winsock2.h>
+#endif
+
+/** Get name of current host and write it to <b>name</b> array, whose
+ * length is specified by <b>namelen</b> argument. Return 0 upon
+ * successful completion; otherwise return return -1. (Currently,
+ * this function is merely a mockable wrapper for POSIX gethostname().)
+ */
+MOCK_IMPL(int,
+tor_gethostname,(char *name, size_t namelen))
+{
+   return gethostname(name,namelen);
+}
diff --git a/src/lib/net/gethostname.h b/src/lib/net/gethostname.h
new file mode 100644 (file)
index 0000000..d83c5fe
--- /dev/null
@@ -0,0 +1,14 @@
+/* Copyright (c) 2003-2004, Roger Dingledine
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef TOR_GETHOSTNAME_H
+#define TOR_GETHOSTNAME_H
+
+#include "lib/testsupport/testsupport.h"
+#include <stddef.h>
+
+MOCK_DECL(int,tor_gethostname,(char *name, size_t namelen));
+
+#endif
index 90049c95d4edc8f63c1d641f7e5a6d9d1b17cdd0..6f34479db2229c4477173658972b6fa254f8baf5 100644 (file)
@@ -8,6 +8,7 @@ endif
 src_lib_libtor_net_a_SOURCES =                 \
        src/lib/net/address.c                   \
        src/lib/net/alertsock.c                 \
+       src/lib/net/gethostname.c               \
        src/lib/net/ipv4.c                      \
        src/lib/net/ipv6.c                      \
        src/lib/net/resolve.c                   \
@@ -21,6 +22,7 @@ src_lib_libtor_net_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
 noinst_HEADERS +=                              \
        src/lib/net/address.h                   \
        src/lib/net/alertsock.h                 \
+       src/lib/net/gethostname.h               \
        src/lib/net/ipv4.h                      \
        src/lib/net/ipv6.h                      \
        src/lib/net/nettypes.h                  \
index a553e7edbd0af2d97a1ef72c3aa5fbd7d42049f1..690025911d849b5458214c6a7f334ec399195ad7 100644 (file)
 #include "lib/process/restrict.h"
 #include "lib/process/setuid.h"
 #include "lib/process/subprocess.h"
+#include "lib/net/gethostname.h"
 
 #include "lib/encoding/keyval.h"
 #include "lib/fs/conffile.h"
index 4676cc89743d6dc9945a6ad0742d85dead052bdd..0fadb6ebcb862bfb4e84c379d9cb6a9f710cc505 100644 (file)
@@ -49,6 +49,7 @@
 #include "or/routerinfo_st.h"
 
 #include "lib/fs/conffile.h"
+#include "lib/net/gethostname.h"
 
 static void
 test_config_addressmap(void *arg)