[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Move tor_gethostname to lib/net
commit db1a420c4eab3fbb6dc02e9653bf21664b9bdf33
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Thu Jun 28 11:57:01 2018 -0400
Move tor_gethostname to lib/net
---
src/common/compat.c | 11 -----------
src/common/compat.h | 2 --
src/common/util.h | 1 -
src/lib/net/gethostname.c | 25 +++++++++++++++++++++++++
src/lib/net/gethostname.h | 14 ++++++++++++++
src/lib/net/include.am | 2 ++
src/or/config.c | 1 +
src/test/test_config.c | 1 +
8 files changed, 43 insertions(+), 14 deletions(-)
diff --git a/src/common/compat.c b/src/common/compat.c
index 1199fdae9..e71931aa1 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -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. */
diff --git a/src/common/compat.h b/src/common/compat.h
index e455dc8ef..13e20a4ac 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -111,8 +111,6 @@
/* ===== Net compatibility */
-MOCK_DECL(int,tor_gethostname,(char *name, size_t namelen));
-
/** Specified SOCKS5 status codes. */
typedef enum {
SOCKS5_SUCCEEDED = 0x00,
diff --git a/src/common/util.h b/src/common/util.h
index 8007aa05c..0f991f8c4 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -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
index 000000000..b6cc9b8e5
--- /dev/null
+++ b/src/lib/net/gethostname.c
@@ -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
index 000000000..d83c5fe09
--- /dev/null
+++ b/src/lib/net/gethostname.h
@@ -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
diff --git a/src/lib/net/include.am b/src/lib/net/include.am
index 90049c95d..6f34479db 100644
--- a/src/lib/net/include.am
+++ b/src/lib/net/include.am
@@ -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 \
diff --git a/src/or/config.c b/src/or/config.c
index a553e7edb..690025911 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -116,6 +116,7 @@
#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"
diff --git a/src/test/test_config.c b/src/test/test_config.c
index 4676cc897..0fadb6ebc 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -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)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits