Skip to content
Snippets Groups Projects
Commit c29ca026 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

ip_utils: add getHostname()

Add method to retreive the hostname,
to fill the default device name.

Change-Id: I5aafe8d0413caa13c4fdf720f6f3ce8b0577d238
parent 070bc0e2
Branches
Tags
No related merge requests found
...@@ -28,14 +28,33 @@ ...@@ -28,14 +28,33 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h>
#ifdef _WIN32 #ifdef _WIN32
#define InetPtonA inet_pton #define InetPtonA inet_pton
WINSOCK_API_LINKAGE INT WSAAPI InetPtonA(INT Family, LPCSTR pStringBuf, PVOID pAddr); WINSOCK_API_LINKAGE INT WSAAPI InetPtonA(INT Family, LPCSTR pStringBuf, PVOID pAddr);
#endif #endif
#ifndef HOST_NAME_MAX
#ifdef MAX_COMPUTERNAME_LENGTH
#define HOST_NAME_MAX MAX_COMPUTERNAME_LENGTH
#else
// Max 255 chars as per RFC 1035
#define HOST_NAME_MAX 255
#endif
#endif
namespace ring { namespace ring {
std::string
ip_utils::getHostname()
{
char hostname[HOST_NAME_MAX];
if (gethostname(hostname, HOST_NAME_MAX))
return {};
return hostname;
}
std::vector<IpAddr> std::vector<IpAddr>
ip_utils::getAddrList(const std::string &name, pj_uint16_t family) ip_utils::getAddrList(const std::string &name, pj_uint16_t family)
{ {
......
...@@ -235,6 +235,8 @@ namespace ip_utils { ...@@ -235,6 +235,8 @@ namespace ip_utils {
static const char *const DEFAULT_INTERFACE = "default"; static const char *const DEFAULT_INTERFACE = "default";
std::string getHostname();
/** /**
* Return the generic "any host" IP address of the specified family. * Return the generic "any host" IP address of the specified family.
* If family is unspecified, default to pj_AF_INET6() (IPv6). * If family is unspecified, default to pj_AF_INET6() (IPv6).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment