From 69817232ff5b363a9f98696548ecd9c99c7a80e2 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Sat, 2 Jun 2018 20:08:33 +0200 Subject: [PATCH] Set SO_BROADCAST socket option for UDP sockets. --- drivers/unix/socket_helpers.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/unix/socket_helpers.h b/drivers/unix/socket_helpers.h index 5ef9ad3088e..5b42c13eae1 100644 --- a/drivers/unix/socket_helpers.h +++ b/drivers/unix/socket_helpers.h @@ -124,6 +124,13 @@ static int _socket_create(IP::Type &p_type, int type, int protocol) { WARN_PRINT("Unable to set/unset IPv4 address mapping over IPv6"); } } + if (protocol == IPPROTO_UDP && p_type != IP::TYPE_IPV6) { + // Enable broadcasting for UDP sockets if it's not IPv6 only (IPv6 has no broadcast option). + int broadcast = 1; + if (setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, (char *)&broadcast, sizeof(broadcast)) != 0) { + WARN_PRINT("Error when enabling broadcasting"); + } + } return sockfd; }