From 82caed54938683d8112615c8e65fa1456f1130ee Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 5 Nov 2013 16:55:39 +0000 Subject: Server broadcasts presence to subnet (untested). --- src/lib/cross.cc | 31 +++++++++++++++++++++++++++++++ src/lib/cross.h | 1 + src/lib/server.cc | 25 +++++++++++++++++++++++++ src/lib/util.h | 2 ++ 4 files changed, 59 insertions(+) (limited to 'src/lib') 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 #include #endif +#ifdef DCPOMATIC_POSIX +#include +#include +#include +#include +#endif #include "exceptions.h" using std::pair; @@ -262,3 +268,28 @@ openssl_path () #endif } + +list +network_interfaces () +{ + list 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); extern std::list > mount_info (); extern boost::filesystem::path openssl_path (); +extern std::list 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 interfaces = network_interfaces (); + for (list::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 (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; } -- cgit v1.2.3