Copyright ©

Mongoose OS Forum

ATTENTION! This forum has moved to:

Do not post any new messages.

Error 22 on broadcast udp port options on linux

While it works on Windows, I get error 22 on setsockopt on linux (Debian) when trying to open a Udp Broadcast Listener.

The code is (almost) the same as the udp example on github (I added the interface and group and made mgr a pointer).
The mcast_group is the broadcast shown on ifconfig.
What I am doing wrong?

mgr = new mg_mgr();
struct ip_mreq group;
const char *_interface = "";
const char *mcast_group = "";

mg_mgr_init(mgr, this);
    char listen[256];
    snprintf(listen, sizeof(listen), "udp://%d", _port);
    nc = mg_bind(mgr, listen, ev_handler);

if (nc == NULL)         
    return errno;

group.imr_multiaddr.s_addr = inet_addr(mcast_group);
group.imr_interface.s_addr = inet_addr(_interface);
if (setsockopt(nc->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&group,sizeof(group)) < 0)      
    return errno;  <<<<< ERROR 22

The interface is :

eth0 Link encap:Ethernet HWaddr 40:8d:5c:37:4a:d1
inet addr: Bcast: Mask:
inet6 addr: fe80::428d:5cff:fe37:4ad1/64 Scope:Link
RX packets:21784192 errors:0 dropped:6240974 overruns:0 frame:0
TX packets:17612932 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3029348889 (2.8 GiB) TX bytes:4332283237 (4.0 GiB)

Sign In or Register to comment.