Hi,<br><i><br></i>I want to write a full transparency proxy too. <br><br>Squid and haproxy are so complicated that i can't quickly understand how tproxy works.<br>And I am new to iptables.<br>If there is a sample peace of code which is simple, I think it would be helpful.<br>
<br>I wrote some code which failed at initiating connections with a foreign address as a source.<br>The reason is timeout while attempting connection.<br>Where am I wrong?<br><br clear="all">Thanks.<br><br><br>My code:<br>
<br>#define NON_LOCAL_IP "192.168.111.23"<br>#define NON_LOCAL_PORT 2000<br><br>int sockfd = socket(AF_INET, SOCK_STREAM, 0);<br><br>memset (&non_local_addr, 0, sizeof(non_local_addr));<br>non_local_addr.sin_family = AF_INET;<br>
dst_addr.sin_addr.s_addr = inet_addr(NON_LOCAL_IP);<br>inet_pton(AF_INET, NON_LOCAL_IP, &non_local_addr.sin_addr);<br>non_local_addr.sin_port = htons(NON_LOCAL_PORT);<br><br>setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optvalue, sizeof(optvalue));<br>
setsockopt(sockfd, SOL_IP, IP_TRANSPARENT, &optvalue, sizeof(optvalue));<br>bind(sockfd, (struct sockaddr *)&non_local_addr, sizeof(non_local_addr));<br><br>memset(&dst_addr, 0, sizeof(dst_addr));<br>dst_addr.sin_family = AF_INET;<br>
dst_addr.sin_addr.s_addr = inet_addr("192.168.1.1");<br>dst_addr.sin_port = htons(80);<br> <br>connect(sockfd, (struct sockaddr *) &dst_addr, sizeof(dst_addr)); // ETIMEOUT<br><br><br>