1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +03:00

fix host emulation on macOS (#5633)

This commit is contained in:
david gauchard
2019-01-19 03:19:17 +01:00
committed by GitHub
parent b666435282
commit bd11d026e8
10 changed files with 48 additions and 19 deletions

View File

@ -37,6 +37,7 @@
#include <fcntl.h>
#include <errno.h>
#include <assert.h>
#include <net/if.h>
int mockUDPSocket ()
{
@ -87,7 +88,12 @@ bool mockUDPListen (int sock, uint32_t dstaddr, uint16_t port, uint32_t mcast)
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
if (global_ipv4_netfmt)
{
#if __APPLE__
int idx = if_nametoindex(host_interface);
if (setsockopt(sock, IPPROTO_TCP, IP_BOUND_IF, &idx, sizeof(idx)) == -1)
#else
if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, host_interface, strlen(host_interface)) == -1)
#endif
fprintf(stderr, MOCK "UDP multicast: can't setup bind/output on interface %s: %s\n", host_interface, strerror(errno));
if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, &mreq.imr_interface, sizeof(struct in_addr)) == -1)
fprintf(stderr, MOCK "UDP multicast: can't setup bind/input on interface %s: %s\n", host_interface, strerror(errno));