summaryrefslogtreecommitdiff
path: root/src/lib
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
parentc3c16fef82ca70542e586d83418fb01c021dbe0e (diff)
Server broadcasts presence to subnet (untested).
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/cross.cc31
-rw-r--r--src/lib/cross.h1
-rw-r--r--src/lib/server.cc25
-rw-r--r--src/lib/util.h2
4 files changed, 59 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;
+}
diff --git a/src/lib/cross.h b/src/lib/cross.h
index 1fe34edbe..c853e8537 100644
--- a/src/lib/cross.h
+++ b/src/lib/cross.h
@@ -30,6 +30,7 @@ extern std::string cpu_info ();
extern void run_ffprobe (boost::filesystem::path, boost::filesystem::path, boost::shared_ptr<Log>);
extern std::list<std::pair<std::string, std::string> > mount_info ();
extern boost::filesystem::path openssl_path ();
+extern std::list<std::string> network_interfaces ();
#ifdef DCPOMATIC_OSX
extern boost::filesystem::path app_contents ();
#endif
diff --git a/src/lib/server.cc b/src/lib/server.cc
index 0212dbbed..3ba7cc632 100644
--- a/src/lib/server.cc
+++ b/src/lib/server.cc
@@ -36,6 +36,7 @@
#include "image.h"
#include "dcp_video_frame.h"
#include "config.h"
+#include "cross.h"
#include "i18n.h"
@@ -43,6 +44,7 @@ using std::string;
using std::stringstream;
using std::multimap;
using std::vector;
+using std::list;
using boost::shared_ptr;
using boost::algorithm::is_any_of;
using boost::algorithm::split;
@@ -176,6 +178,29 @@ Server::run (int num_threads)
}
boost::asio::io_service io_service;
+
+ /* Broadcast our presence on our interfaces */
+ list<string> interfaces = network_interfaces ();
+ for (list<string>::iterator i = interfaces.begin(); i != interfaces.end(); ++i) {
+ boost::system::error_code error;
+
+ boost::asio::ip::udp::socket socket (io_service);
+ socket.open (boost::asio::ip::udp::v4(), error);
+ if (error) {
+ break;
+ }
+
+ socket.set_option (boost::asio::ip::udp::socket::reuse_address (true));
+ socket.set_option (boost::asio::socket_base::broadcast (true));
+
+ boost::asio::ip::udp::endpoint end_point (boost::asio::ip::address_v4::broadcast(), Config::instance()->server_port ());
+
+ string const data = DCPOMATIC_HELLO;
+ socket.send_to (boost::asio::buffer (data.c_str(), data.size() + 1), end_point);
+ socket.close (error);
+ }
+
+ /* Wait to be given things to do */
boost::asio::ip::tcp::acceptor acceptor (io_service, boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), Config::instance()->server_port ()));
while (1) {
shared_ptr<Socket> socket (new Socket);
diff --git a/src/lib/util.h b/src/lib/util.h
index 70cb3bb0c..351c4c4d9 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -51,6 +51,8 @@ extern "C" {
/** The maximum number of audio channels that we can cope with */
#define MAX_AUDIO_CHANNELS 6
+#define DCPOMATIC_HELLO "Boys, you gotta learn not to talk to nuns that way"
+
namespace libdcp {
class Signer;
}