summaryrefslogtreecommitdiff
path: root/src/lib/cross.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-11-05 16:55:39 +0000
committerCarl Hetherington <cth@carlh.net>2013-11-05 16:55:39 +0000
commit82caed54938683d8112615c8e65fa1456f1130ee (patch)
tree77b1008b42f4d6c9003be0af8de411db17fbedbb /src/lib/cross.cc
parentc3c16fef82ca70542e586d83418fb01c021dbe0e (diff)
Server broadcasts presence to subnet (untested).
Diffstat (limited to 'src/lib/cross.cc')
-rw-r--r--src/lib/cross.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/lib/cross.cc b/src/lib/cross.cc
index 4b0b440c5..94edb688b 100644
--- a/src/lib/cross.cc
+++ b/src/lib/cross.cc
@@ -35,6 +35,12 @@
#include <sys/sysctl.h>
#include <mach-o/dyld.h>
#endif
+#ifdef DCPOMATIC_POSIX
+#include <sys/types.h>
+#include <ifaddrs.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#endif
#include "exceptions.h"
using std::pair;
@@ -262,3 +268,28 @@ openssl_path ()
#endif
}
+
+list<string>
+network_interfaces ()
+{
+ list<string> interfaces;
+
+#ifdef DCPOMATIC_POSIX
+ struct ifaddrs* addresses = 0;
+
+ getifaddrs (&addresses);
+
+ for (struct ifaddrs* i = addresses; i; i = i->ifa_next) {
+ if (i->ifa_addr->sa_family == AF_INET) {
+ void* p = &((struct sockaddr_in *) i->ifa_addr)->sin_addr;
+ char b[INET_ADDRSTRLEN];
+ inet_ntop (AF_INET, p, b, INET_ADDRSTRLEN);
+ interfaces.push_back (b);
+ }
+ }
+
+ freeifaddrs (addresses);
+#endif
+
+ return interfaces;
+}