Well, as far as I know you can only broadcast to one interface at a time. So, you have to decide which subnet is the intended destination so the kernel knows which interface to use for it, either by inspecting all the available networks and guessing, or by having the user provide you with the subnet-specific broadcast address. You could inspect the routing table looking for the default gateway and use that network, but this would give unwanted results if you ran it *on* the gateway host because then you'd be broadcasting to the Internet. You could guess if you *were* the gateway based on whether any interface has a ".1" IP address, but then that fails for your virtual machine scenario where the workstation is a client on the wireless network but also a gateway for the VMs' network.

The other option is to create one socket bound to each subnet and then send the broadcast packet to each of them.

Or, who knows, there may be tricks I don't know about to get a single broadcast message out via multiple interfaces at once. IPv6 has an awful lot of features I haven't read up on.


In reply to Re^3: Broadcast when host machine contains virtual interface by NERDVANA
in thread Broadcast when host machine contains virtual interface by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.