The code below handles both client and server sockets.

This breaks down if someone subclasses IO::Socket::INET, but it would require some serious mucking to support that.

use Socket qw( ); use IO::Socket::INET qw( ); my @config = ( ProxyAddr => 'localhost', ProxyPort => 1080, SocksVersion => 5, SocksDebug => 1, ); *CORE::GLOBAL::connect = sub(*$) { my ($socket, $name) = @_; if (eval { $socket->isa('IO::Socket::Socks') }) { return CORE::connect($socket, $name); } my ($port, $host) = sockaddr_in($name); $host = inet_ntoa($host); $_[0] = IO::Socket::Socks->new( @config, ConnectAddr => $host, ConnectPort => $port, ); return $_[0] && 1; }; { my $old_inet_new = \&IO::Socket::INET::new; my $new_inet_new = sub { my $class = shift; if ($class->isa('IO::Socket::Socks')) { return $class->$old_inet_new(@_); } else { my %args = @_; my $addr = delete($args{PeerHost}); $addr = delete($args{PeerAddr}) if exists($args{PeerAddr}) +; my $port = delete($args{PeerPort}); ($addr, $port) = IO::Socket::INET::sock_info($addr, $port, + undef) or die; $args{ConnectAddr} = $addr if defined($addr); $args{ConnectPort} = $port if defined($port); return IO::Socket::Socks->new(@config, %args); } }; no warnings 'redefine'; *IO::Socket::INET::new = $new_inet_net; }

Untested.


In reply to Re: Typeglob substitution in objects based typeglob by ikegami
in thread Typeglob substitution in objects based typeglob by OlegG

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.