All of lore.kernel.org
 help / color / mirror / Atom feed
From: dmorris <dmorris@metavize.com>
To: Brad Chapman <kakadu_croc@yahoo.com>
Cc: Henrik Nordstrom <hno@marasystems.com>,
	netfilter-devel@lists.netfilter.org
Subject: Re: [PATCH?] Fix getorigdst() in ip_conntrack_core.c on 2.4.22-ac2
Date: Wed, 10 Sep 2003 15:29:40 -0700	[thread overview]
Message-ID: <3F5FA5D4.9030202@metavize.com> (raw)
In-Reply-To: <20030910212715.80212.qmail@web40906.mail.yahoo.com>


>Would this work, or would it be horribly worse? Where can I get an app which uses
>SO_ORIGINAL_DST to test this out?
>
>  
>

Try this:

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#include <linux/netfilter_ipv4.h>

int main ()
{
    int sock;
    int one = 1;
    struct sockaddr_in addr;
   
    if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))<0)
    {perror("socket()");exit(-1);}

    setsockopt(sock, SOL_SOCKET,SO_REUSEADDR,(char *)&one,sizeof(one));

    memset(&addr,0,sizeof(addr));
    addr.sin_port = htons(1234);
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = htonl(INADDR_ANY);
    if (bind(sock, (struct sockaddr*)&addr, sizeof(addr))<0)
    {perror("bind()");exit(-1);}
 
    if (listen(sock, 3) < 0)
    {perror("listen()");exit(-1);}
   
    while(1) {
        int addrlen = sizeof(addr);
        int fd = accept(sock,(struct sockaddr*)&addr,&addrlen);
       
        if (fd < 0)
        {perror("accept()");exit(-1);}
      
        printf("accepted.");
       
        if (getsockopt(fd,SOL_IP,SO_ORIGINAL_DST,&addr,&addrlen)<0)
        {perror("getsockopt()");exit(-1);}

        printf("original dest: 
%s:%i\n",inet_ntoa(addr.sin_addr),ntohs(addr.sin_port));

        close(fd);
    }
   
}





then do:
s iptables -t nat -A PREROUTING -p tcp --destination-port 7 -j REDIRECT 
--to-port 1234

then from some machine behind that machine
"telnet 128.2.1.2 7"
Trying 128.2.1.2...
Connected to 128.2.1.2.
Escape character is '^]'.
Connection closed by foreign host.

the machine running the code above should print:
accepted.original dest: 128.2.1.2:7


and from the localmachine
telnet localhost 1234

the code should say:
accepted.original dest: 127.0.0.1:1234

goodluck,

-dirk morris

  reply	other threads:[~2003-09-10 22:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-10 13:32 [PATCH?] Fix getorigdst() in ip_conntrack_core.c on 2.4.22-ac2 Brad Chapman
2003-09-10 19:56 ` Henrik Nordstrom
2003-09-10 21:27   ` Brad Chapman
2003-09-10 22:29     ` dmorris [this message]
2003-09-11  6:13     ` Henrik Nordstrom

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3F5FA5D4.9030202@metavize.com \
    --to=dmorris@metavize.com \
    --cc=hno@marasystems.com \
    --cc=kakadu_croc@yahoo.com \
    --cc=netfilter-devel@lists.netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.