diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-06-28 11:57:01 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-06-28 11:57:01 -0400 |
commit | db1a420c4eab3fbb6dc02e9653bf21664b9bdf33 (patch) | |
tree | f9a6b636a01988565ba1d2fbfef8087a21b9e11b /src/lib/net | |
parent | 8c6ff9fec2ed8b1eed6a4c35370f62f1bf24a158 (diff) | |
download | tor-db1a420c4eab3fbb6dc02e9653bf21664b9bdf33.tar.gz tor-db1a420c4eab3fbb6dc02e9653bf21664b9bdf33.zip |
Move tor_gethostname to lib/net
Diffstat (limited to 'src/lib/net')
-rw-r--r-- | src/lib/net/gethostname.c | 25 | ||||
-rw-r--r-- | src/lib/net/gethostname.h | 14 | ||||
-rw-r--r-- | src/lib/net/include.am | 2 |
3 files changed, 41 insertions, 0 deletions
diff --git a/src/lib/net/gethostname.c b/src/lib/net/gethostname.c new file mode 100644 index 0000000000..b6cc9b8e5f --- /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 0000000000..d83c5fe096 --- /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 90049c95d4..6f34479db2 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 \ |