I am trying to make a Repeater for UDP, where a "Main" has a "Repeater" who has a "Station".
In the Repeater, I have a connection to the SSID of the Main and make an AP ssid named Repeater. Both MAIN and REPEATER show up as valid SSID and when connected via a PC, they give a valid Ip each within its defined service range, 192.168.4.x for MAIN and 192.168.10.x for the Repeater.
In the Repeater I want to received Multicast messages on separate tasks, one for the AP section and one for the STA section, each one creating its socket and making it multicast aware. I create and bind socket like this (for the time being manual ip setting)
Code: Select all
// Bind the socket to any address
saddr.sin_family = PF_INET;
saddr.sin_port = htons(port);
// saddr.sin_addr.s_addr = htonl(INADDR_ANY);
if(ap)
inet_aton("192.168.10.1", &saddr.sin_addr.s_addr);
else
inet_aton("192.168.4.1", &saddr.sin_addr.s_addr);
// saddr.sin_addr.s_addr = ip_info.ip.addr;
err = bind(sock, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
if (err < 0) {
ESP_LOGE(TAG, "Failed to bind socket. Error %d %s", errno,strerror(errno));
goto err;
}
Code: Select all
struct in_addr localInterface;
tcpip_adapter_ip_info_t if_info;
if(ap)
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &if_info);
else
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &if_info);
ESP_LOGI(TAG,"Adapter Ip %d:%d:%d:%d",IP2STR(&if_info.ip));
localInterface.s_addr =(in_addr_t) if_info.ip.addr;
if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF,(char *)&localInterface,sizeof(localInterface)) < 0)
{
ESP_LOGE(TAG,"Setting local interface %d %s\n",errno,strerror(errno));
close(sock);
return 1;
}
My question is if this is possible, that is, to have a task for receiving multicast messages for AP and STA or multicast will be sent to all interfaces, no matter how you set the socket of each task receiver interface.
When setting the socket and use the ANY_ADDR I do get messages in both tasks from the MAIN, which is not the intention. The STA receiver should get a message but not the AP receiver, which does.
Any help will be appreciated.