Subject: | [PATCH] add support for no-auth and alternate server ports |
The attached patch adds some new features to Net-VNC:
1) Support for authorization type 1 ("None")
2) Support for ports other than 5900
3) Defaults to localhost if a hostname is not provided
I tried to observe your indentation format as best I could...
-- Chris
Subject: | vnc.patch |
--- VNC.pm-orig 2006-01-24 16:10:10.000000000 -0600
+++ VNC.pm 2006-01-24 16:15:28.000000000 -0600
@@ -5,15 +5,16 @@
use Crypt::DES;
use Image::Imlib2;
use IO::Socket::INET;
-__PACKAGE__->mk_accessors(qw(hostname password socket name width height));
+__PACKAGE__->mk_accessors(qw(hostname port password socket name width height));
our $VERSION = '0.30';
sub login {
my $self = shift;
my $hostname = $self->hostname;
+ my $port = $self->port;
my $socket = IO::Socket::INET->new(
- PeerAddr => $hostname,
- PeerPort => '5900',
+ PeerAddr => $hostname || 'localhost',
+ PeerPort => $port || '5900',
Proto => 'tcp',
Timeout => 15,
)
@@ -24,6 +25,10 @@
# warn "prot: $protocol_version";
+ if ($protocol_version lt 'RFB 003.008') {
+ die 'RFB protocols earlier than v3.8 are not currently supported';
+ }
+
# let's use the same version of the protocol
$socket->print($protocol_version);
@@ -45,40 +50,51 @@
push @security_types, $security_type;
}
- die "no vnc auth" unless grep { $_ == 2 } @security_types;
+ if (0 < grep { $_ == 2 } @security_types) {
- $socket->print( pack( "c", 2 ) );
+ $socket->print( pack( "c", 2 ) );
- $socket->read( my $challenge, 16 );
+ $socket->read( my $challenge, 16 );
- # warn "chal: " . unpack('h*', $challenge) . "\n";
+ # warn "chal: " . unpack('h*', $challenge) . "\n";
- my $key = $self->password;
- $key .= pack( 'c', 0 ) until ( length($key) % 8 ) == 0;
+ my $key = $self->password;
+ $key .= pack( 'c', 0 ) until ( length($key) % 8 ) == 0;
- my $realkey;
+ my $realkey;
- # warn unpack('b*', $key);
- foreach my $byte ( split //, $key ) {
- $realkey .= pack( "b8", scalar reverse unpack( "b8", $byte ) );
- }
+ # warn unpack('b*', $key);
+ foreach my $byte ( split //, $key ) {
+ $realkey .= pack( "b8", scalar reverse unpack( "b8", $byte ) );
+ }
- # warn unpack('b*', $realkey);
+ # warn unpack('b*', $realkey);
- my $cipher = Crypt::DES->new($realkey);
- my $response;
- my $i = 0;
- while ( $i < 16 ) {
- my $word = substr( $challenge, $i, 8 );
-
- # warn "$i: " . length($word);
- $response .= $cipher->encrypt($word);
- $i += 8;
- }
+ my $cipher = Crypt::DES->new($realkey);
+ my $response;
+ my $i = 0;
+ while ( $i < 16 ) {
+ my $word = substr( $challenge, $i, 8 );
+
+ # warn "$i: " . length($word);
+ $response .= $cipher->encrypt($word);
+ $i += 8;
+ }
+
+ # warn "resp: " . unpack('h*', $response) . "\n";
- # warn "resp: " . unpack('h*', $response) . "\n";
+ $socket->print($response);
- $socket->print($response);
+ } elsif (0 < grep { $_ == 1 } @security_types) {
+
+ # No authorization needed!
+ $socket->print( pack( "c", 1 ) );
+
+ } else {
+
+ die "no vnc auth";
+
+ }
$socket->read( my $security_result, 4 );
$security_result = unpack( "I", $security_result );
@@ -313,6 +329,8 @@
my $vnc = Net::VNC->new({hostname => $hostname, password => $password});
+Optionally, you can also specify a port, which defaults to 5900.
+
=head2 login
Logs into the remote computer: