mirror of
https://github.com/espressif/openthread.git
synced 2026-09-07 17:50:09 +00:00
[simulation] allow specify local host (#9925)
This commit adds a argument `-L`/`--local-host` to simulation platform to specify the source IP address for packets simulating 15.4 frames. This allows the simulation packets being transmitted over different network interfaces, so that the simulation can run on different hosts. This can be used to enable multiple emulation devices(e.g. Android Virtual Device) communicating to each other over emulated Thread radio. The argument accepts either an IPv4 address or a network interface name. In the latter case, the first found IPv4 address on that interface will be used will be used.
This commit is contained in:
@@ -36,6 +36,8 @@
|
||||
#define UTILS_SOCKET_LOCAL_HOST_ADDR "127.0.0.1"
|
||||
#define UTILS_SOCKET_GROUP_ADDR "224.0.0.116"
|
||||
|
||||
const char *gLocalHost = UTILS_SOCKET_LOCAL_HOST_ADDR;
|
||||
|
||||
void utilsAddFdToFdSet(int aFd, fd_set *aFdSet, int *aMaxFd)
|
||||
{
|
||||
otEXPECT(aFd >= 0);
|
||||
@@ -75,7 +77,7 @@ void utilsInitSocket(utilsSocket *aSocket, uint16_t aPortBase)
|
||||
memset(&sockaddr, 0, sizeof(sockaddr));
|
||||
sockaddr.sin_family = AF_INET;
|
||||
sockaddr.sin_port = htons(aSocket->mPort);
|
||||
sockaddr.sin_addr.s_addr = inet_addr(UTILS_SOCKET_LOCAL_HOST_ADDR);
|
||||
sockaddr.sin_addr.s_addr = inet_addr(gLocalHost);
|
||||
|
||||
rval = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, &sockaddr.sin_addr, sizeof(sockaddr.sin_addr));
|
||||
otEXPECT_ACTION(rval != -1, perror("setsockopt(TxFd, IP_MULTICAST_IF)"));
|
||||
@@ -103,7 +105,7 @@ void utilsInitSocket(utilsSocket *aSocket, uint16_t aPortBase)
|
||||
memset(&mreq, 0, sizeof(mreq));
|
||||
inet_pton(AF_INET, UTILS_SOCKET_GROUP_ADDR, &mreq.imr_multiaddr);
|
||||
|
||||
mreq.imr_address.s_addr = inet_addr(UTILS_SOCKET_LOCAL_HOST_ADDR);
|
||||
mreq.imr_address.s_addr = inet_addr(gLocalHost);
|
||||
|
||||
rval = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, &mreq.imr_address, sizeof(mreq.imr_address));
|
||||
otEXPECT_ACTION(rval != -1, perror("setsockopt(RxFd, IP_MULTICAST_IF)"));
|
||||
|
||||
Reference in New Issue
Block a user