diff --git a/src/shared/net/netraw.cpp b/src/shared/net/netraw.cpp index 0f41229a..03612e98 100644 --- a/src/shared/net/netraw.cpp +++ b/src/shared/net/netraw.cpp @@ -93,9 +93,9 @@ bool UDP::open(int port, bool share_port_for_multicasting, bool multicast_includ if(flags < 0) flags = 0; fcntl(fd, F_SETFL, flags | (blocking ? 0 : O_NONBLOCK)); + int yes = 1; if (share_port_for_multicasting) { - int reuse=1; - if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse,sizeof(reuse))!=0) { + if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&yes, sizeof(yes))!=0) { fprintf(stderr,"ERROR WHEN SETTING SO_REUSEADDR ON UDP SOCKET\n"); fflush(stderr); } @@ -106,8 +106,8 @@ bool UDP::open(int port, bool share_port_for_multicasting, bool multicast_includ } if (multicast_include_localhost) { - int yes = 1; // allow packets to be received on this host + yes = 1; if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const char*)&yes, sizeof(yes))!=0) { fprintf(stderr,"ERROR WHEN SETTING IP_MULTICAST_LOOP ON UDP SOCKET\n"); fflush(stderr); @@ -121,6 +121,14 @@ bool UDP::open(int port, bool share_port_for_multicasting, bool multicast_includ return false; } + yes = 1; + ret = setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &yes, sizeof(yes)); + if(ret != 0) + { + printf("ERROR %d WHEN SETTING SO_BROADCAST\n", ret); + return false; + } + // bind socket to port if nonzero if(port != 0){ sockaddr_in sockname;