Net::SS...:Packet(3)

πŸ“¦
version 2.144 Β· 4 versions
, in fedora 44

πŸ’– Net::SSH::Perl::Packet β€” the packet layer of the SSH protocol, bestie πŸ’–

okay so real talk: this page lives in the User Contributed Perl Documentation collection, and it's literally the blueprint for how SSH messages get wrapped up, sealed, and yeeted across the wire. come sit with me, we're learning this together 🫢


✨ NAME ✨

Net::SSH::Perl::Packet β€” it's giving packet layer of SSH protocol, and it ate πŸ’…


🌸 SYNOPSIS 🌸

use Net::SSH::Perl::Packet;

# Send a packet to an ssh daemon.
my $pack = Net::SSH::Perl::Packet->new($ssh, type => SSH_MSG_NONE);
$pack->send;

# Receive a packet.
my $pack = Net::SSH::Perl::Packet->read($ssh);

no cap, that's the whole vibe right there πŸ”₯


πŸ¦‹ DESCRIPTION πŸ¦‹

So Net::SSH::Perl::Packet implements the packet-layer piece of the SSH protocol. Messages between the server and the client get sent as binary data packets, and those packets are encrypted (once the two sides have agreed on the encryption cipher, that is β€” gotta agree first, it's only polite πŸ’).

Packets are made up primarily of a packet type, which describes the type of message and the data contained therein, plus the data itself. And on top of that, every single packet:

  • indicates its length in a 32-bit unsigned integer
  • contains padding to pad the length of the packet to a multiple of 8 bytes
  • is verified by a 32-bit crc checksum

basically every packet is dressed to the nines ✨

Refer to the SSH RFC for more details on the packet protocol and the SSH protocol in general. the RFC is the source material, we're just the group chat.

πŸŽ€ USAGE πŸŽ€

Net::SSH::Perl::Packet->new($ssh, %params)

Creates/starts a new packet in memory. $ssh is a Net::SSH::Perl object, which should already be connected to an ssh daemon (like, actually connected, don't be out here with a stray socket 😭). %params can contain the following keys:

  • type β€” the message type of this packet. This should be one of the values exported by Net::SSH::Perl::Constants from the msg tag; for example, SSH_MSG_NONE. iykyk.
  • data β€” a Net::SSH::Perl::Buffer object containing the data in this packet. Realistically, there aren't many times you'll need to supply this argument: when sending a packet, it will be created automatically; and when receiving a packet, the read method (see below πŸ‘‡) will create the buffer automatically, as well. so like... she's optional in practice, bestie.

Net::SSH::Perl::Packet->read($ssh)

Reads a packet from the ssh daemon and returns that packet. 🫢

This method will block until an entire packet has been read. The socket itself is non-blocking, but the method waits (using select) for data on the incoming socket, then processes that data when it comes in. If the data makes up a complete packet, the packet is returned to the caller. Otherwise read continues to try to read more data. it's patient, it's committed, it's the main character energy we deserve πŸ‘‘

Net::SSH::Perl::Packet->read_poll($ssh)

Checks the data that's been read from the sshd to see if that data comprises a complete packet. If so, that packet is returned. If not, returns "undef".

This method does not block. she does not wait for anyone πŸ’…

Net::SSH::Perl::Packet->read_expect($ssh, $type)

Reads the next packet from the daemon and dies if the packet type does not match $type. Otherwise returns the read packet. dramatic? yes. correct? also yes. πŸ’€

$packet->send([ $data ])

Sends a packet to the ssh daemon. $data is optional, and if supplied specifies the buffer to be sent in the packet (should be a Net::SSH::Perl::Buffer object). In addition, $data, if specified, must include the packed message type. ⚠️

If $data is not specified, send sends the buffer internal to the packet, which you've presumably filled by calling the put_* methods (see below πŸ‘‡).

$packet->type

Returns the message type of the packet $packet. short, sweet, iconic ✨

$packet->data

Returns the message buffer from the packet $packet; a Net::SSH::Perl::Buffer object. 🎁

Net::SSH::Perl::Buffer methods

Calling methods from the Net::SSH::Perl::Buffer class on your Net::SSH::Perl::Packet object will automatically invoke those methods on the buffer object internal to your packet object (which is created when your object is constructed). For example, if you executed the following code:

my $packet = Net::SSH::Perl::Packet->new($ssh, type => SSH_CMSG_USER);
$packet->put_str($user);

this would construct a new packet object $packet, then fill its internal buffer by calling the put_str method on it. like, the delegation is automatic, it just happens, slay πŸ¦‹

Refer to the Net::SSH::Perl::Buffer documentation (the GET AND PUT METHODS section) for more details on those methods. go read that one next, fr fr πŸ“š


πŸ‘‘ AUTHOR & COPYRIGHTS πŸ‘‘

Please see the Net::SSH::Perl manpage for author, copyright, and license information. all the legal girlypop details live over there πŸ’œ


and that's the whole page, bestie!! this one came from perl v5.42.0, dated 2026-01-17, filed under Net::SS...:Packet(3) β€” mwah, go encrypt something responsibly πŸ˜˜πŸ’–πŸŒΈ

πŸ“¦ where this page comes from