Skip to content

Commit e5805a1

Browse files
jason-simmonsAndroid (Google) Code Review
authored andcommitted
Merge "Set the SO_BROADCAST option if the master election endpoint is the broadcast address"
2 parents 9caa8db + db63260 commit e5805a1

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+
ALOGE("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)