udp服务器响应,UDP服务是否必须从连接的IP地址进行响应?

我在一个TFTP服务器上碰到这个。我的服务器有两个IP地址面对同一个网络。因为UDP是无连接的,在这种情况下,可能会出现IP地址没有按预期设置的问题。我的顺序是:客户机在特定的IP地址发送初始数据包

服务器从传入的数据包中读取客户端的源地址,并发送一个响应。

然而,在响应中,服务器的“源地址”是根据路由表设置的,它被设置为其他IP地址。在

无法控制服务器的“源”IP地址,因为操作系统没有告诉我们请求通过哪个IP地址。在

客户机从“其他”IP地址获得响应,并拒绝它。在

在我的例子中,解决方案是专门将TFTP服务器绑定到我想要监听的IP地址,而不是绑定到所有接口。在

我发现了一些可能与Linux man page for ^{}(TFTP服务器)相关的文本。这里是:Unfortunately, on multi-homed systems, it is impossible for tftpd to

determine the address on which a packet was received. As a result, tftpd

uses two different mechanisms to guess the best source address to use for

replies. If the socket that inetd(8) passed to tftpd is bound to a par‐

ticular address, tftpd uses that address for replies. Otherwise, tftpd

uses ‘‘UDP connect’’ to let the kernel choose the reply address based on

the destination of the replies and the routing tables. This means that

most setups will work transparently, while in cases where the reply

address must be fixed, the virtual hosting feature of inetd(8) can be

used to ensure that replies go out from the correct address. These con‐

siderations are important, because most tftp clients will reject reply

packets that appear to come from an unexpected address.

请参阅this answer,这表明在Linux上,可以读取传入UDP数据包的本地地址,并为传出数据包设置本地地址。在C语言中是可能的;但是我不确定Python。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值