Skip to content

Commit dd336d7

Browse files
authored
Add broadcast flag for syslog output (#3171)
1 parent 7a04d0f commit dd336d7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/output_udp.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <string.h>
2121
#include <stdio.h>
2222
#include <stdlib.h>
23+
#include <errno.h>
2324

2425
#include <limits.h>
2526
// _POSIX_HOST_NAME_MAX is broken in gcc-13 at least on MacOS
@@ -117,8 +118,14 @@ static int datagram_client_open(datagram_client_t *client, const char *host, con
117118
return -1;
118119
}
119120

120-
//int broadcast = 1;
121-
//int ret = setsockopt(client->sock, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast));
121+
// Enable SO_BROADCAST for all tested platforms, so far Linux and MacOS only
122+
#if defined(__linux__) || defined(__APPLE__)
123+
int broadcast = 1;
124+
int ret = setsockopt(client->sock, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast));
125+
if (ret) {
126+
print_logf(LOG_ERROR, __func__, "Failed to set broadcast flag (%d)\n", errno);
127+
}
128+
#endif
122129

123130
return 0;
124131
}

0 commit comments

Comments
 (0)