Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

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 = "192.168.9.127";
const char *mcast_group = "192.168.9.255";

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:192.168.9.127 Bcast:192.168.9.255 Mask:255.255.0.0
inet6 addr: fe80::428d:5cff:fe37:4ad1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
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.