Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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 => "", 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'.
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2018-08-14 23:04 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (155 votes). Check out past polls.