Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

perl udp broadcast

by rosen4o (Initiate)
on Jul 09, 2010 at 06:10 UTC ( [id://848820]=perlquestion: print w/replies, xml ) Need Help??

rosen4o has asked for the wisdom of the Perl Monks concerning the following question:

Hi There, I'm truing to send udp broadcast packet from network interface. When I have default gateway then the packet is routed from this interface which is from gateway network. The other solution is when I add from interface to the packet. But I need to send packet from interface which doesn't have assigned ip address. Any idea how to do that? I'm using linux.

Replies are listed 'Best First'.
Re: perl udp broadcast
by Anonymous Monk on Jul 09, 2010 at 06:31 UTC
    need to send packet from interface which doesn't have assigned ip address

    You can't communicate without an IP (like talking without a mouth).

    ?node_id=3989;HIT=UDP%20broad;re=N

Re: perl udp broadcast
by Khen1950fx (Canon) on Jul 09, 2010 at 07:02 UTC
    Your English isn't very clear, but I think that you're looking for something like IO::Socket::INET. Here's an example of a server and a client by zentara that uses IO::Socket::INET.
Re: perl udp broadcast
by rowdog (Curate) on Jul 11, 2010 at 22:22 UTC

    Are you saying that you get your address and gateway from a DHCP server and that you would like to send a UDP packet to the broadcast address? If so, then sure, check out IO::Socket::INET.

    If you want to do the above, but get the packet routed past the gateway, well, most routers won't pass a broadcast packet along so you're probably out of luck unless you can configure your gateway to pass it along, which is generally a bad idea.

Re: perl udp broadcast
by rosen4o (Initiate) on Jul 12, 2010 at 15:22 UTC
    I want to make little broadcast config application. Clients will broadcast their ip addresses periodically server will listen for packets. The problem comes from there that I can't send broadcast packets without to have ip address on the network interface. Maybe Net::RawIP can help me???

      Sounds like a reverse DHCP. Since you don't have an IP address, you'll have to send at a lower level. I haven't used Perl for much below the layer of IP but if Net::RawIP doesn't work out for you Net::Frame and Net::Frame::Layer::Eth or Net::Write might be useful.

        Thanks I will try
Re: perl udp broadcast
by rosen4o (Initiate) on Jul 15, 2010 at 19:40 UTC
    This modules have many dependencies. If I use this code I can send packet if even doesn't have gateway. Is there any way to send it on specific interface without ip on it.
    $sock = new IO::Socket::INET( LocalAddr => '192.168.0.138', PeerAddr => '255.255.255.255', PeerPort => '9190', # Port the udp server listens on Proto => 'udp', Broadcast => 1 # Not sure if this is needed, I know the sockopt is ) || die "[ERROR] $!\n"; $sock->sockopt(SO_BROADCAST, 1); print $sock "test\n";

      UDP is based on IP, so you can't send an UDP packet without an IP. Or rather, you'll have to construct a raw packet and send it on the raw interface.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://848820]
Approved by rovf
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-18 17:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found