Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Building a UDP Ethernet header

by VinsWorldcom (Prior)
on Sep 18, 2017 at 11:46 UTC ( [id://1199606]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Building a UDP Ethernet header
in thread Building a UDP Ethernet header

You can't just add Net::Frame::Layer::ETH to your code. You need to properly install Net::Frame suite with 'cpan' client or other means (e.g., perl Makefile.PL; make; make install). You'll probably also need Net::Frame::Simple and Net::Pcap if you intend to send packets.

Again, I go back to: "What are you trying to do?" There are much easier ways to send / receive UDP packets with Perl without crafting them from scratch. The only reasons *I* can think of for crafting raw packets is:

  • local network testing - which requires a very deep knowledge of protocols
  • something "nefarious"

UPDATE: Reading your Stack Overflow post, your local and remote IP addresses are not in the same network, nevermind subnet. Sending crafted packets across the Internet reeks of malicious intent. Please explain what you're trying to do or I can't in good conscience offer more advice.

Replies are listed 'Best First'.
Re^4: Building a UDP Ethernet header
by TorNZZ (Novice) on Sep 18, 2017 at 12:56 UTC
    I told you what i try to do simply need to control source mac-address on code i get. Yes there is other ways but i need to control the whole packet that's why i need this in that format.

      Based on my reading of your Stack Overflow posts (now deleted), you don't have a deep understanding of networking protocols, which makes coding for them all the more difficult. Your OP cites code from this site dated Jun 11, 2000, and as one of the comments on that node notes, there are surely more relevant, recent and working examples.

      First off, terminology:

      [ ETHERNET HEADER [ IP HEADER [ UDP HEADER [ DATA ] ] ] ] (frame) (packet) (datagram)

      Perl's IO::Socket::IP will handle IP and up (to the right) and your operating system, once you send() will handle ETHERNET Header. Unless you specify raw sockets (which you're trying to do); in which case you may need to code up the Ethernet layer yourself - mileage may vary depending on OS (e.g., *nix may handle this in some cases, Windows will definitely *not*).

      Creating a raw packet can be as simple as coding the whole thing in hex and pack()-ing it but you still need to send(). Unless you plan on using something like Net::Pcap, your program won't be able to send the packet your creating because you'll have coded a frame and the send() routine expects a packet.

      You didn't answer my question about what this is for. We know what you're trying to do ... WHY? Do you have UDP data to send to a remote host? Easy, change the PeerAddr and PeerPort parameters below to suite the remote destination address and port:

      #!/usr/bin/perl use strict; use warnings; use IO::Socket::IP; my $socket = IO::Socket::IP->new( Proto => "udp", PeerAddr => "remote.host.com", PeerPort => 12345 ) || die "Cannot create client\n"; while(1) { print "PROMPT> "; my $message = <STDIN>; chomp $message; if (($message !~ /^q(?:uit)?$/i) && ($message !~ /^e(?:xit)?$/i)) +{ $socket->send($message) } else { last } } close($socket);

      We don't even know what data you're trying to send? Is it SNMP, Syslog, TFTP, NTP or one of the *many* known UDP upper layer protocols / applications all of which have Perl modules to help (e.g., Net::SNMP, Net::Syslog, Net::TFTP, Net::SNTP::Client) and none of which require raw sockets or to "control the whole packet".

      A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-03-28 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found