Hello,

I am writing a small Perl/TK app, which communicates with other instances of itself on a LAN (think a sort of Instant Messaging application).

This snippet of code works under FreeBSD, but not under Linux:

#!/usr/bin/perl -w use IO::Socket; use strict; my($sock, $server_host, $msg, $port, $ipaddr, $hishost, $MAXLEN, $PORTNO, $TIMEOUT); $MAXLEN = 1024; $PORTNO = 5151; $server_host = '192.168.0.255'; $msg = "test"; $sock = IO::Socket::INET->new(Proto => 'udp', PeerPort => $PORTNO, PeerAddr => $server_host) or die "Creating socket: $!\n"; $sock->sockopt(SO_BROADCAST, 1); # $sock->sockopt(SO_DONTROUTE, 1); $sock->send($msg) or die "send: $!";
Running under FreeBSD works (as verified with a tcpdump process), running under Linux gives a:

Creating socket: Permission denied
I was given the two options to set on the socket (via 'sockopt') by a C programmer - the 'SO_DONTROUTE' doesn't seem to be necessary. Turning it on does not make it work under Linux. The 'SO_BROADCAST' is 100% necessary for it to work at all under FreeBSD.

Yes, I really want to use UDP broadcasts. Suggestions I use unicast addresses will be cheerfully ignored :-)

Oh, and although it would be totally unsuitable for my application, I did try running it as root. It made no difference.


In reply to UDP broadcast using IO::Socket under Linux by Tardis

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.