471,330 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

UDP broadcast over a specific interface

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

Jul 19 '07 #1
1 10422
On Jul 19, 7:09 am, Jean-Paul Calderone <exar...@divmod.comwrote:
On Thu, 19 Jul 2007 12:32:02 -0000, "Larry.Mart...@gmail.com" <larry.mart...@gmail.comwrote:
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?

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

Jul 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by pekspro | last post: by
8 posts views Thread by Frank Esser | last post: by
2 posts views Thread by Gunnar_Frenzel | last post: by
19 posts views Thread by dl | last post: by
2 posts views Thread by Mali Findik | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.