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


In reply to Re^5: Building a UDP Ethernet header by VinsWorldcom
in thread Building a UDP Ethernet header by TorNZZ

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.