Re: SO_ORIGINAL_DST returning bogus port number

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Monday 2010-04-19 22:09, Jan Engelhardt wrote:

>
>On Monday 2010-04-19 21:36, Jeff Saremi wrote:
>>
>>Setup:
>>
>>iptables -A INPUT -p tcp -i eth0 -j ACCEPT
>>iptables -t nat -A PREROUTING -i eth0 -p tcp -j REDIRECT --to-port 9000
>>
>>Code:
>>
>>    cli_fd = accept(fd, (struct sockaddr *) &cli_addr, &cli_len);
>>    dst_len = sizeof(dst_addr);
>>    if(getsockopt(cli_fd, IPPROTO_IP, SO_ORIGINAL_DST, &dst_addr, &dst_len)
>>!= 0)
>>        printf("getsockopt() returned error");
>>    else
>>        printf("original destination address: %s:%d\n",
>>inet_ntoa(dst_addr.sin_addr), dst_addr.sin_port);
>
>You have to use
>
>else {
>	char buf[16];
>	inet_ntop(AF_INET, &dst_addr.sin_addr, dst, sizeof(dst));
                                               ^ buf, not dst

>	printf("%s:%hu\n", buf, ntohs(dst_addr.sin_port));
>}
>--
>To unsubscribe from this list: send the line "unsubscribe netfilter" in
>the body of a message to majordomo@xxxxxxxxxxxxxxx
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

--
To unsubscribe from this list: send the line "unsubscribe netfilter" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Netfilter Development]     [Linux Kernel Networking Development]     [Netem]     [Berkeley Packet Filter]     [Linux Kernel Development]     [Advanced Routing & Traffice Control]     [Bugtraq]

  Powered by Linux