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

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

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

struct sockaddr_in server;
setuid(0);
system("/sbin/ifconfig wlan0 down");
system("/sbin/ifconfig wlan0 address 10.0.0.1 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;
bzero(&server,sizeof(server));	
server.sin_family = AF_INET;
inet_aton("10.255.255.255",&server.sin_addr.s_addr);
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?

-Ari



More information about the maemo-users mailing list