NAME
Net::SSH::Perl::Packet - Packet layer of SSH protocol
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);
DESCRIPTION
Net::SSH::Perl::Packet implements the packet-layer piece of the SSH protocol. Messages between server and client are sent as binary data packets, which are encrypted (once the two sides have agreed on the encryption cipher, that is).
Packets are made up primarily of a packet type, which describes the type of message and data contained therein, and the data itself. In addition, each 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; and is verified by a 32-bit crc checksum.
Refer to the SSH RFC for more details on the packet protocol and the SSH protocol in general.
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. %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.
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.
Net::SSH::Perl::Packet->read($ssh)
Reads a packet from the ssh daemon, blocking if necessary, and returns that packet.
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.
$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.
$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.
Refer to the Net::SSH::Perl::Buffer documentation (the GET AND PUT METHODS section) for more details on those methods.
AUTHOR & COPYRIGHTS
Please see the Net::SSH::Perl manpage for author, copyright, and license information.