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

Commit ccd9019

Browse files
tudorisaachier
authored andcommitted
localIP: try resolving local hostname first (#130)
* localIP: try resolving local hostname first Fixes #129. Signed-off-by: Tudor Bosman <[email protected]> * catch everything Signed-off-by: Tudor Bosman <[email protected]>
1 parent 7e9a135 commit ccd9019

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/jaegertracing/net/IPAddress.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include "jaegertracing/net/IPAddress.h"
18+
#include "jaegertracing/platform/Hostname.h"
1819

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

3738
IPAddress IPAddress::localIP(int family)
3839
{
40+
try {
41+
return versionFromString(platform::hostname(), 0, family);
42+
} catch (...) {
43+
// Fall back to returning the first matching interface
44+
}
45+
3946
return localIP([family](const ifaddrs* ifAddr) {
4047
return ifAddr->ifa_addr != nullptr &&
4148
ifAddr->ifa_addr->sa_family == family;

0 commit comments

Comments
 (0)