C++ iptables redirection forming separate packets

后端 未结 1 1652
猫巷女王i
猫巷女王i 2021-01-07 03:46

I have all traffic from port 50 redirected to 5050 using

iptables -t nat -A POSTROUTING -p udp --dport 50 -j REDIRECT --to-port 5050

I lis

1条回答
  •  囚心锁ツ
    2021-01-07 04:00

    Linux netfilter defines a socket option called SO_ORIGINAL_DST in .

    First you need to enable port forwarding in your system, using one of these commands:

    sysctl net.ipv4.ip_forward=1
    echo 1 > /proc/sys/net/ipv4/ip_forward
    

    Then you can use this:

    struct sockaddr_in addr;
    socklen_t addr_sz = sizeof(addr);
    getsockopt(fd, IPPROTO_IP, SO_ORIGINAL_DST, &addr, &addr_sz);
    

    I cannot find SO_ORIGINAL_DST in any Linux manpage. You may have luck finding formal documentation on the netfilter site.

    0 讨论(0)
提交回复
热议问题