]> Dogcows Code - chaz/yoink/commitdiff
better broadcast support
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Thu, 13 May 2010 16:51:13 +0000 (10:51 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Thu, 13 May 2010 16:51:13 +0000 (10:51 -0600)
src/Main.cc
src/Moof/Socket.hh

index c6df957010d16fc2cd65dfc6a43fdc1e4ca68752..4d88a709e69bb39a71e739a574823e254ff2f0ac 100644 (file)
@@ -280,7 +280,7 @@ void goodbye()
 
 int main(int argc, char* argv[])
 {
-       Mf::ResolverTask task("4950", "255.255.255.255", SOCK_DGRAM);
+       Mf::ResolverTask task("4950", "compy", SOCK_DGRAM);
        task.run();
 
        int i = task.wait();
@@ -335,27 +335,26 @@ int main(int argc, char* argv[])
        Mf::logInfo << "packet size: " << packet.size() << std::endl;
 
 
-       Mf::SocketAddress addr("634", "lappy");
-       Mf::logInfo << "local addr: " << addr.name() << std::endl;
+       Mf::SocketAddress addr = Mf::SocketAddress::broadcast("4950");
+       //Mf::logInfo << "local addr: " << addr.name() << std::endl;
 
-       for (it = task.addresses().begin(); it != task.addresses().end(); ++it)
-       {
+       //for (it = task.addresses().begin(); it != task.addresses().end(); ++it)
+       //{
                int bcast = 0;
 
-               Mf::SocketAddress addr = *it;
+               //Mf::SocketAddress addr = *it;
                Mf::Socket sock(addr);
 
                sock.get(SO_BROADCAST, bcast);
                Mf::logInfo << "bcast: " << bcast << std::endl;
 
-               sock.set(SO_REUSEADDR, 1);
                sock.set(SO_BROADCAST, 1);
 
                sock.get(SO_BROADCAST, bcast);
                Mf::logInfo << "bcast: " << bcast << std::endl;
 
                sock.write(packet);
-       }
+       //}
 
 
        return 0;
index f1604663b038c37ff408061ca50db4d914ccd38a..6b0fa88fa6bbe7a72c52eef4773687f217c4a351 100644 (file)
@@ -90,7 +90,16 @@ public:
 
        static SocketAddress broadcast(const std::string& service)
        {
-               return SocketAddress(service, "255.255.255.255", SOCK_DGRAM);
+               std::istringstream stream(service);
+               unsigned short port;
+               stream >> port;
+
+               struct sockaddr_in addr;
+               addr.sin_family = AF_INET;
+               addr.sin_port = htons(port);
+               addr.sin_addr.s_addr = INADDR_BROADCAST;
+               memset(&addr.sin_zero, 0, sizeof(addr.sin_zero));
+               return SocketAddress((sockaddr*)&addr, sizeof(addr), SOCK_DGRAM);
        }
 
 
This page took 0.028262 seconds and 4 git commands to generate.