Choosing target network for UDP broadcast

If I send a UDP packet containing 'foo' like this:

  socket = UDPSocket.new
  socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
  socket.send('foo', 0, '<broadcast>', 40001)

then wireshark tells me it gets sent from 192.168.x.y. However, my
server is listening on localhost:40001. How can I choose the source
address from which (and the interface via which) the socket will send
its packet?

···

--
Posted via http://www.ruby-forum.com/.

Hm, no UDP specialist here but can't you bind to the proper address
and then send the broadcast?

Kind regards

robert

···

On Fri, Feb 3, 2012 at 11:36 AM, Ivo Wever <wever@axini.com> wrote:

If I send a UDP packet containing 'foo' like this:

socket = UDPSocket.new
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
socket.send('foo', 0, '<broadcast>', 40001)

then wireshark tells me it gets sent from 192.168.x.y. However, my
server is listening on localhost:40001. How can I choose the source
address from which (and the interface via which) the socket will send
its packet?

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Use #bind - Class: Socket (Ruby 1.9.3)

···

On Fri, Feb 3, 2012 at 10:36 AM, Ivo Wever <wever@axini.com> wrote:

If I send a UDP packet containing 'foo' like this:

socket = UDPSocket.new
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
socket.send('foo', 0, '<broadcast>', 40001)

then wireshark tells me it gets sent from 192.168.x.y. However, my
server is listening on localhost:40001. How can I choose the source
address from which (and the interface via which) the socket will send
its packet?

Oops. Wrong link. This is the right one:

···

On Fri, Feb 3, 2012 at 1:47 PM, Sean O'Halpin <sean.ohalpin@gmail.com> wrote:

On Fri, Feb 3, 2012 at 10:36 AM, Ivo Wever <wever@axini.com> wrote:

If I send a UDP packet containing 'foo' like this:

socket = UDPSocket.new
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
socket.send('foo', 0, '<broadcast>', 40001)

then wireshark tells me it gets sent from 192.168.x.y. However, my
server is listening on localhost:40001. How can I choose the source
address from which (and the interface via which) the socket will send
its packet?

Use #bind - Class: Socket (Ruby 1.9.3)