Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^5: Building a UDP Ethernet header

by VinsWorldcom (Parson)
on Sep 18, 2017 at 14:08 UTC ( #1199616=note: print w/replies, xml ) Need Help??


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

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".

Replies are listed 'Best First'.
Re^6: Building a UDP Ethernet header
by TorNZZ (Novice) on Sep 18, 2017 at 16:19 UTC
    Yes you are right but this not helped much you still ask questions more than what you answer so.... Anyway thanks for helping.
      "...you still ask questions..."

      Because this is how design works?

      «The Crux of the Biscuit is the Apostrophe»

      perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1199616]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2018-05-24 14:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?