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
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.