/Users/cpanrun/depot/main/contrib-patched/perl/CPAN/src/IO-Socket-Socks/blib/lib/IO/Socket/Socks.pm


NAME

IO::Socket::Socks


SYNOPSIS

Provides a way to open a connection to a SOCKS v5 proxy and use the object just like an IO::Socket.


DESCRIPTION

IO::Socket::Socks connects to a SOCKS v5 proxy, tells it to open a connection to a remote host/port when the object is created. The object you receive can be used directly as a socket for sending and receiving data from the remote host.


EXAMPLES

Client

use IO::Socket::Socks;

my $socks = new IO::Socket::Socks(ProxyAddr=>``proxy host'', ProxyPort=>``proxy port'', ConnectAddr=>``remote host'', ConnectPort=>``remote port'', );

print $socks ``foo\n'';

$socks->close();

Server

use IO::Socket::Socks;

my $socks_server = new IO::Socket::Socks(ProxyAddr=>``localhost'', ProxyPort=>``8000'', Listen=>1, UserAuth=>\&auth, RequireAuth=>1 );

my $select = new IO::Select($socks_server);


while(1)
{
    if ($select->can_read())
    {
        my $client = $socks_server->accept();
        if (!defined($client))
        {
            print "ERROR: $SOCKS_ERROR\n";
            next;
        }
        my $command = $client->command();
        if ($command->[0] == 1)  # CONNECT
        {
            # Handle the CONNECT
            $client->command_reply(0, addr, port);
        }

        ...
        #read from the client and send to the CONNECT address
        ...
        $client->close();
    }
}

sub auth { my $user = shift; my $pass = shift;

    return 1 if (($user eq "foo") && ($pass eq "bar"));
    return 0;
}


METHODS

new( %cfg )

Creates a new IO::Socket::Socks object. It takes the following config hash:

  ProxyAddr => Hostname of the proxy
  ProxyPort => Port of the proxy

  ConnectAddr => Hostname of the remote machine
  ConnectPort => Port of the remote machine
  AuthType => What kind of authentication to support:
                none       - no authentication (default)
                userpass  - Username/Password
  RequireAuth => Do not send, or accept, ANON as a valid
                 auth mechanism.
  UserAuth => Function that takes ($user,$pass) and returns
              1 if they are allowed, 0 otherwise.
  Username => If AuthType is set to userpass, then you must
              provide a username.
  Password => If AuthType is set to userpass, then you must
              provide a password.

  SocksDebug => This will cause all of the SOCKS traffic to
                be presented on the command line in a form
                similar to the tables in the RFCs.
  Listen => 0 or 1.  Listen on the ProxyAddr and ProxyPort
            for incoming connections.

accept( )

Accept an incoming connection and return a new IO::Socket::Socks object that represents that connection. You must call command() on this to find out what the incoming connection wants you to do, and then call command_reply() to send back the reply.

command( )

After you call accept() the client has sent the command they want you to process. This function returns a reference to an array with the following format:

  [ COMMAND, HOST, PORT ]

command_reply( REPLY CODE, HOST, PORT )

After you call command() the client needs to be told what the result is. The REPLY CODE is as follows (integer value):

  0: Success
  1: General Failure
  2: Connection Not Allowed
  3: Network Unreachable
  4: Host Unreachable
  5: Connection Refused
  6: TTL Expired
  7: Command Not Supported
  8: Address Not Supported

HOST and PORT are the resulting host and port that you use for the command.


VARIABLES

$SOCKS_ERROR

This scalar behaves like $! in that if undef is returned, this variable should contain a string reason for the error.


AUTHOR

Ryan Eatmon


COPYRIGHT

This module is free software, you can redistribute it and/or modify it under the same terms as Perl itself.

 /Users/cpanrun/depot/main/contrib-patched/perl/CPAN/src/IO-Socket-Socks/blib/lib/IO/Socket/Socks.pm