Another way which you may want to go is to make use of the low-level libpcap packet capturing library through the combined usage of theNet::Pcap and NetPacket modules. This approach, while more involved, offers greater control over the router communication.

For example, the following snippet of code can be used to capture UDP packets from the local network:

use Net::PcapUtils; use NetPacket::IP; use NetPacket::UDP; use NetPacket::Ethernet qw/:types/; use strict; Net::PcapUtils::loop( sub { my ($arg, $header, $packet) = @_; my $ethernet = NetPacket::Ethernet->decode($packet); if ($ethernet->{'type'} == ETH_TYPE_IP) { my $ip = NetPacket::IP->decode($ethernet->{'data'}, $ether +net); my $udp = NetPacket::UDP->decode($ip->{'data'}); . . print $ip->{'src_ip'}, ":", $udp->{'src_port'}, " -> ", $ip->{'dest_ip'}, ":", $udp->{'dest_port'}, "\n"; } }, 'DEV' => 'eth0', # 'FILTER' => 'udp dst host 192.168.1.1' );

The commented line in the above code snippet is an example filter which can be passed the packet-capturing library to minimise unwanted 'overhead' packets also captured.

With regard to the initial UDP broadcast over the network, you will need to set the SO_BROADCAST option on the socket in order to request permission for the communication given the priviledged nature of this type of communication. For example:

use IO::Socket; use strict; my $sock = new IO::Socket::INET( 'PeerAddr' => '55.255.255.255' 'PeerPort' => '9', 'Proto' => 'udp' ); $sock->sockopt(SO_BROADCAST, 1);

Alternatively, depending upon your data requirements, the NetPacket group of modules referenced earlier can also be used to manually construct packets for transmission.

 


In reply to Re: UDP Broadcasts by rob_au
in thread UDP Broadcasts by jamesdmorris

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.