0

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?

SergeyA
  • 61,605
  • 5
  • 78
  • 137
jacknad
  • 13,483
  • 40
  • 124
  • 194

1 Answers1

2

I do not claim credit for this answer (found it online), but in the interest of keeping shared knowledge, will post the solution here.

The problem seems to be essentially a broken route for multicast group, and it can be fixed with following command:

route add -net 224.0.0.0 netmask 224.0.0.0 eth0
SergeyA
  • 61,605
  • 5
  • 78
  • 137