views:

42

answers:

1

I have a PC with two network cards connected to different networks (multi homed network setup). I want to send UDP broadcast frames on both networks. The senders IP address of the frames must be the IP address of the adapter, that is used to send the frame. The destination address should be the LIMITED BROADCAST address.

The customer application should not run with administrative rights (UAC is not acceptible).

How can I send these UDP frames to the LIMITED BROADCAST address (255.255.255.255)? How could I send these frames to the NETWORK BROADCAST address (x.y.z.255)?

I know how to do this with raw sockets. But raw sockets can only be used with administrative rights.

A: 

Can't you just open two normal UDP sockets and bind one to each of the interface addresses and then simply send to the broadcast addresses ?

This will, as far as I know, deal with the sending on both networks and it will ensure that the packets sent will have the correct ip address. It wont work if you bind a single socket to INADDR_ANY which, of course, WILL work if there's only a single network adapter in the machine. To create a complete solution it's probably best to iterate over the available addresses and create a socket for each, bind to each and send from each.

Len Holgate
No. Binding a socket affects which received packets are accepted by this socket. Sent packets are routed according the IP routing rules. I can iterate the adapters and the IP addresses bound to these adapters and send a network broadcast per each IP address. But this does not send to the LIMITED BROADCAST address.
harper
Are you sure? When you issue a SendTo the socket is implicitly bound to the local socket that is used to send from so that the recipient can reply. You can see this in action as you can't do a RecvFrom without binding or previously sending on the socket... If you have two interfaces that could both route to the same destination then the OS selects one if you haven't bound. You can bind before issuing a SendTo to select the local address.
Len Holgate
Ah, I see. You're right! In Windows 7 the bind() call affects receive AND TRANSMIT of frames. This is a difference to the Windows XP behavior, where frames have been send with any arbitrary adapter address to all adapters. You need RAW sockets with Windows XP to send an appropriate source addresses. But Windows 7 sends LIMITED BROADCASTS to the adapter the socket is bound to.Thanks alot,Harper
harper
No worries.....
Len Holgate