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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |