473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Get original destination IP and port with Linux 2.4 iptables redirect?

Sorry to repost this but I still haven't figured it out and there
weren't any responses.
---
Say I use iptables to redirect tcp connections to my perl proxy
servers. How then do I get the original destination IP address and tcp
port?

On FreeBSD I just use ipfw and fwd and then following works:
$daddr=$client->sockhost;
$dport=$client->sockport;

And then my various proxies work transparently.

But on Linux I'm supposed to use some FD options:
e.g.
getsockopt(fd, SOL_IP, SO_ORIGINAL_DST, &dst_addr, &slen)

What's a good way to do this with perl? Working examples would be very
helpful.

I've tried perl's getsockopt but replacing OPTNAME with
SO_ORIGINAL_DST doesn't work - it's not defined.

perl -f getsockopt
getsockopt SOCKET,LEVEL,OPTNAME

I've tried specifying a numerical 80 for OPTNAME but not sure how to
get the address etc.

Thanks,
Link.
Jul 19 '05 #1
1 6055

Lincoln Yeoh <ju****@tm.net.my> wrote:
Say I use iptables to redirect tcp connections to my perl proxy
servers. How then do I get the original destination IP address and tcp
port?

On FreeBSD I just use ipfw and fwd and then following works:
$daddr=$client->sockhost;
$dport=$client->sockport;

And then my various proxies work transparently.

But on Linux I'm supposed to use some FD options:
e.g.
getsockopt(fd, SOL_IP, SO_ORIGINAL_DST, &dst_addr, &slen)

What's a good way to do this with perl? Working examples would be very
helpful.

I've tried perl's getsockopt but replacing OPTNAME with
SO_ORIGINAL_DST doesn't work - it's not defined.

perl -f getsockopt
getsockopt SOCKET,LEVEL,OPTNAME

I've tried specifying a numerical 80 for OPTNAME but not sure how to
get the address etc.


The call in Perl is the same as C, except that return values are
returned instead of being passed by reference. So

use Socket qw/inet_ntoa/;

my $packed_addr = getsockopt $SOCK, SOL_IP, SO_ORIGINAL_DST;
my $addr = inet_ntoa $packed_addr;

(untested) should work. To get the values of the constants you will
need to poke around in your headers... on my machine, SOL_IP is
defined to be 0 in <bits/in.h> and SO_ORIGINAL_DST to be 80 in
<linux/netfilter_ipv4/ip_nat.h>. You could try throwing those headers
at h2ph, just for a laugh :), or you could just put use constant
statements at the top of your program.

Ben

--
EAT
KIDS (...er, whoops...)
FOR be*@morrow.me.uk
99p
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the...
0
by: Douglas Soares de Andrade | last post by:
Hi ! Is there a module to do the interaction between python and iptables ? I want to make a app to interect with iptables (new chain, erase chain, list chain, generate rules and so on). ...
2
by: rbt | last post by:
I don't fully understand sockets, I just know enough to be dangerous. The below is not detected by nmap, but is affected by iptables or ipsec. Can anyone explain why that is? s =...
4
by: Dustin | last post by:
I am trying to connect a camera through my router to put up onto a website. The camera (even after a firmware update) starts to get funny when i try to watch the video feed from above the router...
9
by: MNQ | last post by:
Hi All I want to use my parallel port of my PC to control some external devices. I am writing a program in ANSI C using the PacificC compiler. What I need to know is how to access the parallel...
1
by: Sean Wolfe | last post by:
I have this wierd bizarrre problem that I'm experienceing with the Response.Redirect() method. I have a site where the users are on a particular page in SSL. When they post the data back, and...
0
by: looker | last post by:
Hello everyone!, I currently have debian box I want to patch iptables to support time match with the latest version of kernel 2.6.24.2 ( at the time of writing ). I download - Kernel 2.6.24.2 -...
1
by: rada.lambretha | last post by:
Configuring Linux as a Firewall * Making installation choices * Introducing iptables * Using iptables commands * Simplifying things with firewall GUIs * Adding proxy functionality As...
1
by: tvnaidu | last post by:
I have Redhat Linux machine with single ethernet interface, I need to test Iptables, Is one ethernet good enough to test iptables?. Currently I can do ssh, ftp into redhat machine, also if I want...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.