Skip to content

Commit 2da0bbc

Browse files
committed
DO NOT MERGE - Set the SO_BROADCAST option if the master election endpoint is the broadcast address
Change-Id: I76aa9df717ee5ca32859e21c7e25635b44739c75
1 parent 194f6bc commit 2da0bbc

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

services/common_time/common_time_server.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,16 @@ bool CommonTimeServer::setupSocket_l() {
487487
goto bailout;
488488
}
489489
} else
490-
if (ntohl(ipv4_addr->sin_addr.s_addr) != 0xFFFFFFFF) {
490+
if (ntohl(ipv4_addr->sin_addr.s_addr) == 0xFFFFFFFF) {
491+
// If the master election address is the broadcast address, then enable
492+
// the broadcast socket option
493+
const int one = 1;
494+
rc = setsockopt(mSocket, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one));
495+
if (rc == -1) {
496+
LOGE("Failed to enable broadcast (errno = %d)", errno);
497+
goto bailout;
498+
}
499+
} else {
491500
// If the master election address is neither broadcast, nor multicast,
492501
// then we are misconfigured. The config API layer should prevent this
493502
// from ever happening.

0 commit comments

Comments
 (0)