Server broadcasts presence to subnet (untested).
authorCarl Hetherington <cth@carlh.net>
Tue, 5 Nov 2013 16:55:39 +0000 (16:55 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 5 Nov 2013 16:55:39 +0000 (16:55 +0000)
src/lib/cross.cc
src/lib/cross.h
src/lib/server.cc
src/lib/util.h

index 4b0b440c5baa58360c8cb86ec2b5ba6367b9e8f4..94edb688b5791e9408a0dab369873bfe4d036321 100644 (file)
 #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;
+}
index 1fe34edbe0760d9e86f00c47a6689c61acf073a0..c853e85375df02ef93f4e8cfa819ed7a9bf15014 100644 (file)
@@ -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
index 0212dbbedd8547fe1b3f6da04e7b14fd9764edf3..3ba7cc632f04288951b7e220646f14de67f19850 100644 (file)
@@ -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);
index 70cb3bb0c9ec820973996c7573d3e4353b1f1bfa..351c4c4d93da445aded791b960ecc640a49b6657 100644 (file)
@@ -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;
 }