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();
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;
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);
}