Hello Andrey,
I think there is a mismatch between FNET_IP4_ADDR_IS_MULTICAST macro and FNET_ETH_MULTICAST_IP4_TO_MAC macros, at least when FNET_CFG_CPU_LITTLE_ENDIAN = 1, as in our case, since we are working with K60 (fnet_mk60n512_config.h).
Let's say we have a multicast address = 224.1.120.121 = E0,01,78,79
if we make this call to setsockopt:
mreq.imr_multiaddr.s_addr = FNET_IP4_ADDR_INIT(224, 1, 120, 121);
mreq.imr_interface.s_addr = FNET_HTONL(INADDR_ANY);
setsockopt(socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mreq, sizeof(mreq));
then it will be successful, but afterwards nothing received by fnet_ip_input_low because FNET_ETH_MULTICAST_IP4_TO_MAC reverses the bits.
if we reverse bytes and change the code into:
mreq.imr_multiaddr.s_addr = FNET_HTONL(FNET_IP4_ADDR_INIT(224, 1, 120, 121));
mreq.imr_interface.s_addr = FNET_HTONL(INADDR_ANY);
setsockopt(socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mreq, sizeof(mreq));
then the call will fail because of FNET_IP4_ADDR_IS_MULTICAST.
The workaround that we have found is to change the FNET_ETH_MULTICAST_IP4_TO_MAC call:
from: FNET_ETH_MULTICAST_IP4_TO_MAC(multicast_addr, mac_addr);
into: FNET_ETH_MULTICAST_IP4_TO_MAC(FNET_NTOHL(multicast_addr), mac_addr);
what am I doing wrong?
What would be a clean solution to the problem?
Thank you!