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 @@
#include <sys/types.h>
#include <unistd.h>
#include <limits.h>
#ifdef _WIN32
#define InetPtonA inet_pton
WINSOCK_API_LINKAGE INT WSAAPI InetPtonA(INT Family, LPCSTR pStringBuf, PVOID pAddr);
#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 {
std::string
ip_utils::getHostname()
{
char hostname[HOST_NAME_MAX];
if (gethostname(hostname, HOST_NAME_MAX))
return {};
return hostname;
}
std::vector<IpAddr>
ip_utils::getAddrList(const std::string &name, pj_uint16_t family)
{
......@@ -247,10 +266,10 @@ ip_utils::getLocalNameservers()
{
std::vector<IpAddr> res;
#if defined __ANDROID__ || defined _WIN32 || TARGET_OS_IPHONE
#ifdef _MSC_VER
#pragma message (__FILE__ "(" STR2(__LINE__) ") : -NOTE- " "Not implemented")
#else
#warning "Not implemented"
#ifdef _MSC_VER
#pragma message (__FILE__ "(" STR2(__LINE__) ") : -NOTE- " "Not implemented")
#else
#warning "Not implemented"
#endif
#else
if (not (_res.options & RES_INIT))
......
......@@ -235,6 +235,8 @@ namespace ip_utils {
static const char *const DEFAULT_INTERFACE = "default";
std::string getHostname();
/**
* Return the generic "any host" IP address of the specified family.
* 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