Dave Rolsky > Net-SSH-Perl-1.25 > Net::SSH::Perl::Packet



Annotate this POD


New  25
Open  34
Stalled  1
View/Report Bugs
Source   Latest Release: Net-SSH-Perl-2.01


Net::SSH::Perl::Packet - Packet layer of SSH protocol


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

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

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


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.


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:


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.


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.

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


Returns the message type of the packet $packet.


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);

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.


Please see the Net::SSH::Perl manpage for author, copyright, and license information.

syntax highlighting: