UDP broadcast over a specific interface

L

Larry.Martell

I am trying to send UDP broadcast packets over a specific interface
and I
am having trouble specifying the interface:

host='192.168.28.255'
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('',0))
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF,
socket.inet_aton(host))

socket.error: (49, "Can't assign requested address")

What am I doing wrong? How can I force my broadcast packets to go out
a specific interface?

TIA!
-larry
 
L

Larry.Martell

IP_MULTICAST_IF is for multicast UDP, which doesn't have anything to do
with broadcast UDP.

Try just doing this, instead:

host='192.168.28.255'
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((host,0))
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

You shouldn't need to mess with anything beyond that.

Thanks! This works perfectly.

-larry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top