mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-13 05:53:06 +01:00
bind mc udp receiver to mc address
This commit is contained in:
@@ -49,13 +49,7 @@ void GwUdpReader::createAndBind(){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
struct ip_mreq mc;
|
struct ip_mreq mc;
|
||||||
String mcAddr=config->getString(GwConfigDefinitions::udprMC);
|
mc.imr_multiaddr=listenA.sin_addr;
|
||||||
if (inet_pton(AF_INET,mcAddr.c_str(),&mc.imr_multiaddr) != 1){
|
|
||||||
LOG_ERROR("UDPR: invalid multicast addr %s",mcAddr.c_str());
|
|
||||||
::close(fd);
|
|
||||||
fd=-1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (type == T_MCALL || type == T_MCAP){
|
if (type == T_MCALL || type == T_MCAP){
|
||||||
mc.imr_interface=apAddr;
|
mc.imr_interface=apAddr;
|
||||||
int res=setsockopt(fd,IPPROTO_IP,IP_ADD_MEMBERSHIP,&mc,sizeof(mc));
|
int res=setsockopt(fd,IPPROTO_IP,IP_ADD_MEMBERSHIP,&mc,sizeof(mc));
|
||||||
@@ -63,7 +57,7 @@ void GwUdpReader::createAndBind(){
|
|||||||
LOG_ERROR("UDPR: unable to add MC membership for AP:%d",errno);
|
LOG_ERROR("UDPR: unable to add MC membership for AP:%d",errno);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
LOG_INFO("UDPR: membership for %s for AP",mcAddr.c_str());
|
LOG_INFO("UDPR: membership for for AP");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!currentStationIp.isEmpty() && (type == T_MCALL || type == T_MCSTA))
|
if (!currentStationIp.isEmpty() && (type == T_MCALL || type == T_MCSTA))
|
||||||
@@ -75,7 +69,7 @@ void GwUdpReader::createAndBind(){
|
|||||||
LOG_ERROR("UDPR: unable to add MC membership for STA:%d", errno);
|
LOG_ERROR("UDPR: unable to add MC membership for STA:%d", errno);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
LOG_INFO("UDPR: membership for %s for STA %s",mcAddr.c_str(),currentStationIp.c_str());
|
LOG_INFO("UDPR: membership for STA %s",currentStationIp.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,15 +82,27 @@ void GwUdpReader::begin()
|
|||||||
port=config->getInt(GwConfigDefinitions::udprPort);
|
port=config->getInt(GwConfigDefinitions::udprPort);
|
||||||
listenA.sin_family=AF_INET;
|
listenA.sin_family=AF_INET;
|
||||||
listenA.sin_port=htons(port);
|
listenA.sin_port=htons(port);
|
||||||
if (type != T_STA){
|
listenA.sin_addr.s_addr=htonl(INADDR_ANY); //default
|
||||||
listenA.sin_addr.s_addr=htonl(INADDR_ANY);
|
|
||||||
}
|
|
||||||
String ap=WiFi.softAPIP().toString();
|
String ap=WiFi.softAPIP().toString();
|
||||||
if (inet_pton(AF_INET, ap.c_str(), &apAddr) != 1)
|
if (inet_pton(AF_INET, ap.c_str(), &apAddr) != 1)
|
||||||
{
|
{
|
||||||
LOG_ERROR("UDPR: invalid ap ip address %s", ap.c_str());
|
LOG_ERROR("UDPR: invalid ap ip address %s", ap.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (type == T_MCALL || type == T_MCAP || type == T_MCSTA){
|
||||||
|
String mcAddr=config->getString(GwConfigDefinitions::udprMC);
|
||||||
|
if (inet_pton(AF_INET, mcAddr.c_str(), &listenA.sin_addr) != 1)
|
||||||
|
{
|
||||||
|
LOG_ERROR("UDPR: invalid mc address %s", mcAddr.c_str());
|
||||||
|
close(fd);
|
||||||
|
fd = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LOG_INFO("UDPR: using multicast address %s",mcAddr.c_str());
|
||||||
|
}
|
||||||
|
if (type == T_AP){
|
||||||
|
listenA.sin_addr=apAddr;
|
||||||
|
}
|
||||||
String sta;
|
String sta;
|
||||||
if (WiFi.isConnected()) sta=WiFi.localIP().toString();
|
if (WiFi.isConnected()) sta=WiFi.localIP().toString();
|
||||||
setStationAdd(sta);
|
setStationAdd(sta);
|
||||||
|
|||||||
Reference in New Issue
Block a user