Winsock/BSD 套接字 - 接受目标 IP 与本地 IP 不同的 TCP 连接 [英] Winsock / BSD Sockets - Accept TCP connections with destination IP different from local IP

查看:62
本文介绍了Winsock/BSD 套接字 - 接受目标 IP 与本地 IP 不同的 TCP 连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 LAN 上的一些传出 TCP 流量(最终也是 UDP)转发到本地(透明)代理服务器,然后再将它们发送到 Internet.数据包似乎已正确转发,我可以在 Wireshark 中看到 SYN.

I am forwarding some outgoing TCP traffic on LAN (eventually UDP as well) to a local (transparent) proxy server before sending them out on the internet. The packets are forwared correctly it seems, I can see the SYN's in Wireshark.

问题是绑定到端口 X 的 accept() 不接受与目标端口 X 和目标 IP 似乎与代理服务器自己的 IP 不同的连接,这是我所期望的.

The problem is that accept() bound to a port X doesn't accept a connection with destination port X and a destination IP different from the proxy server's own IP it seems, which was something I expected.

在 Winsock 或 Linux 套接字中有没有办法解决这个问题?我怎样才能实现 accept() 或类似的?

Is there a way around this in Winsock or in Linux sockets? How can I achieve the accept() or similar?

推荐答案

Linux 套接字具有选项 IP_TRANSPARENT.请参阅 linux 手册页 ip:

Linux sockets have the option IP_TRANSPARENT. See the linux man page ip:

IP_TRANSPARENT(自 Linux 2.6.24 起)

IP_TRANSPARENT (since Linux 2.6.24)

设置此布尔选项可启用透明代理这个插座.此套接字选项允许调用应用程序绑定到非本地 IP 地址并同时操作作为客户端和服务器,以外部地址作为本地端点....

Setting this boolean option enables transparent proxying on this socket. This socket option allows the calling application to bind to a nonlocal IP address and operate both as a client and a server with the foreign address as the local endpoint. ...

据我所知,该选项不适用于 Windows 套接字.

As far as I know the option is not available for windows sockets.

这篇关于Winsock/BSD 套接字 - 接受目标 IP 与本地 IP 不同的 TCP 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆