This is from a working legacy code base that has already been ported to and is still shared by several other hardware platforms so making a major change to this method is not a good solution. This is a new port to a ZCU111 ARM64. The Linux kernel has been built with multicast support (CONFIG_IP_MULTICAST=y).
This is a summary of the code:
const char *const MULTICAST_IP = "224.0.0.26";
const unsigned int BCAST_PORT = 35001;
struct ip_mreq mreq;
int optval = 1;
int optlen = sizeof(int);
int fd = socket(AF_INET,SOCK_DGRAM,0);
int flags = fcntl(fd,F_GETFL,0);
fcntl(fd,F_SETFL,flags|O_NONBLOCK);
setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,&optval,optlen);
bzero(&sock_addr,sizeof(sock_addr));
sock_addr.sin_family=AF_INET;
sock_addr.sin_addr.s_addr=htonl(INADDR_ANY);
sock_addr.sin_port=htons(BCAST_PORT);
bind(fd,reinterpret_cast<const sockaddr *>(&sock_addr),sizeof(struct sockaddr_in));
mreq.imr_multiaddr.s_addr = inet_addr(MULTICAST_IP);
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
if (setsockopt(fd,IPPROTO_IP,IP_ADD_MEMBERSHIP,&mreq,sizeof(mreq))<0) PRINTF_ERROR;
PRINTF_ERROR is used to print the FILE, LINE, func, strerror, and errno like this:
gps.cpp:93 (GetFileDescriptor) ERROR No such device 19
Changing IPPROTO_IP to IPPROTO_UDP causes the following error:
gps.cpp:93 (GetFileDescriptor) ERROR Protocol not available 92
I already looked at these solutions but not sure how they apply in this case. Any idea how to fix the 'No such device' error?