[maemo-users] [maemo-users] Sending to broadcast address

From: Ari Paavilainen arip at iki.fi
Date: Wed Dec 7 09:14:35 EET 2005

I try to send data to broadcast address with following code:

struct sockaddr_in server;
system("/sbin/ifconfig wlan0 down");
system("/sbin/ifconfig wlan0 address up");
system("/sbin/iwconfig wlan0 mode Ad-Hoc essid masum");
sock = socket(AF_INET, SOCK_DGRAM, 0);
setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, "wlan0", 6);
int i=1;
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &i, sizeof(int));
port = 6666;
server.sin_family = AF_INET;
server.sin_port = htons(port);
sendto(sock, "Hello from 770!", 16, 0, (struct sockaddr*)&server, sizeof(server));
close (sock);

I have omitted error checking but no function call returns error code.
Only signs of error are that there is no packet in receiving side, and
when I check ifconfig there is one or two TX errors after I run the
code. When I change the IP address to real address, sending works, and
I can receive broadcast packets with the device. What's wrong?


More information about the maemo-users mailing list