Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

localIP: try resolving local hostname first #130

Merged
merged 2 commits into from
Sep 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/jaegertracing/net/IPAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include "jaegertracing/net/IPAddress.h"
#include "jaegertracing/platform/Hostname.h"

#include <ifaddrs.h>
#include <sys/types.h>
Expand All @@ -36,6 +37,12 @@ struct IfAddrDeleter : public std::function<void(ifaddrs*)> {

IPAddress IPAddress::localIP(int family)
{
try {
return versionFromString(platform::hostname(), 0, family);
} catch (...) {
// Fall back to returning the first matching interface
}

return localIP([family](const ifaddrs* ifAddr) {
return ifAddr->ifa_addr != nullptr &&
ifAddr->ifa_addr->sa_family == family;
Expand Down