This data is accessible using a getsockopt() call, and works perfect for TCP traffic (for UDP traffic there is some minor issues..)
The following fragment should give you the correct destination address both for DNAT/REDIRECT:ed connections and connections made directly to the server. sockaddr_in dst_addr; socklen_t slen = sizeof(dst_addr); getsockname(fd, (struct sockaddr *)&dst_addr, &slen); getsockopt(fd, SOL_IP, SO_ORIGINAL_DST, &dst_addr, &slen) Regards Henrik Nordström MARA Systems AB, Sweden On Wednesday 06 March 2002 16:08, Igor Vrdoljak wrote: > I'm using netfilter (PREROUTING chain) on my router for redirecting > all the trafic passing through designated to certain port to a > local port on my router. > > I'm interested in getting the original dest. address (adress before > DNAT) from my server (which listens on local port on the router). > > I see there is a /proc/net/ip_conntrack file which shows > connections active on the machine, but I wonder is there easier way > of getting that information other than parsing that file? > > Which would be the easyest way to do this?