To test an application I want to send UDP broadcast packets that look like they are are generated from mutliple computers.
I've setup a number of IPs for an interface
ifconfig eth0:1 10.10.10.221
ifconfig eth0:2 10.10.10.222
ifconfig eth0:3 10.10.10.223 etc
In code I want to send udp broadcast data from each interface (address)
In C I have an array interface_ips containing the IP addresses 10.10.10.221 etc, then in code I do this :
Code:
int broadcast=1;
struct sockaddr_in sendaddr[32];
// Now we have a table of ip addresses we need to open a sending socket for each "interface" (address)
for (i=0;i<NUM_SENDING_IPS;i++)
{
if((sockfd[i] = socket(PF_INET,SOCK_DGRAM,0)) == -1)
{
perror("sockfd");
exit(1);
}
if((setsockopt(sockfd[i],SOL_SOCKET,SO_BROADCAST,&broadcast,sizeof broadcast)) == -1)
{
perror("setsockopt - SO_SOCKET ");
exit(1);
}
// Fill in an array of this structure
sendaddr[i].sin_family = AF_INET;
sendaddr[i].sin_port = htons(PORT);
sendaddr[i].sin_addr.s_addr = inet_addr(interface_ips[i]);
memset(sendaddr[i].sin_zero,'\0',sizeof(sendaddr[i].sin_zero));
}
Later in the code I send a packet to each socket
Code:
// for now send same packet to each interface (silence)
for (i=0;i<NUM_SENDING_IPS;i++)
{
numbytes = sendto(sockfd[i], audio, sizeof(audio), 0, (struct sockaddr *)&sendaddr[i], sizeof(sendaddr[i]));
if (numbytes<=0)
{
perror("sendto error");
exit(1);
}
}
If I run the receiving code on the same machine I get data, but the data never hits the LAN ?
Anyone know my mistake/magic setting. I've tried fiddling with ifconfig and broadcast addresses but it does not seem to help.
Thanks,
Jon