Thread: FreeBSD redirect messes up IP

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    12

    FreeBSD redirect messes up IP

    Hi. I'm working on porting over some proxy code to FreeBSD. The problem is that the port is redirected using PF. When this happens, the code that linux uses to figure out what the original target address was doesn't work on BSD. It returns with the current target. Now, there's supposed to be a way to figure out what the original address was. The only notes I can find shows that it has something to do with pfioc_natlook and/or ioctl. Anyone have any idea how to do this?

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    12
    Nevermind. I found an answer.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by trinli View Post
    Nevermind. I found an answer.
    And I suppose it doesn't matter to anyone else, so you don't need to tell us what the answer is?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    12
    Sorry, I was gathering my notes into something that might be useful. It was actually fairly simple.

    sorta pseudo code follows:

    #include <net/pfvar.h>

    define a struct of type pfioc_natlook (called var here) and fill in the info you know.
    saddr.v4.s_addr - source address
    sport - source port
    daddr.v4.s_addr - destination address
    dport - destination port
    etc... (refer to the struct definition in pfvar.h for the full list)

    fd = open /dev/pf
    ioctl(fd, DIOCNATLOOK, &var);
    addr = var.rdaddr.v4.s_addr;

    The rdaddr is the redirect address. Also, port is available in the same way.
    Last edited by trinli; 04-07-2009 at 10:17 AM. Reason: added clarification

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting 32 bit binary IP to decimal IP (vice-versa)
    By Mankthetank19 in forum C Programming
    Replies: 15
    Last Post: 12-28-2009, 07:17 PM
  2. Replies: 6
    Last Post: 06-08-2006, 04:11 PM
  3. freebsd and redhat dual boot.
    By xddxogm3 in forum Linux Programming
    Replies: 1
    Last Post: 05-09-2004, 06:06 PM

Tags for this Thread