Hello monks.
I recently started using the TPROXY (transparent proxy) kernel extensions that make it possible to bind to non-local IP address in Linux kernel 2.6.
A recent kernel with TPROXY support is in use and netfilter/iptables has been re-compiled with TPROXY support.
Do I need to recompile Perl as well?
In the following code, setting the IP address literal on line 16 to my local IP address works. But using a non-local address causes the connect on line 22 to die with the error:
connect: Invalid argument at test line 22.
#!/usr/bin/perl
use strict;
use Socket qw(:all);
use constant SOL_IP => 0;
use constant IP_FREEBIND => 15;
$|++; # no buffering
my $proto = getprotobyname('tcp');
socket(Socket_Handle, PF_INET, SOCK_STREAM, $proto) or die "socket: $!
+";
setsockopt( Socket_Handle, SOL_IP, IP_FREEBIND, 1) or die "setsockopt:
+ $!";
# set local address to a non-local address :)
my $laddr = inet_aton('10.8.31.5');
bind(Socket_Handle, sockaddr_in(0,$laddr)) or die "bind: $!";
# attempt to connect to remote webserver
my $port = getservbyname('http', 'tcp');
my $sin = sockaddr_in($port,inet_aton("www.google.com"));
connect(Socket_Handle,$sin) or die "connect: $!";;
sleep 2;
close (Socket_Handle) || die "close: $!";
exit;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.