在 Erlang 中检测 UDP 无法访问的端口
我正在寻找一种方法来检测 Erlang 中传出 UDP 数据包的“端口无法访问”错误,这样我就可以急切地向应用程序报告传输层错误。即,我想捕获 ICMP 类型 3 数据包,以向更高层报告数据包尚未到达目的地。
目前我知道两种方法:
- 使用未记录的
gen_udp:connect/3
。然而,这似乎需要为每个新的目标对地址:端口打开一个新的套接字。优点是这不需要任何特权。 - 使用 gen_icmp ,它需要 setuid 帮助程序或打开原始套接字的功能。
我还缺少其他变体吗?
I am looking for a way to detect "port unreachable" errors for outgoing UDP packets in Erlang, so I can eagerly report transport layer errors to the application. I.e, I want to capture ICMP type 3 packets to report to the higher layers that packet have not reached the destination.
Currently I know about two approaches:
- Use undocumented
gen_udp:connect/3
. However, it seems like this requires opening a new socket for every new destination pair address:port. The advantage is that this does not require any privileges. - Use gen_icmp which requires either setuid helper or capabilities to open raw sockets.
Are there any other variants I am missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
procket 可能就是您正在寻找的东西,但我自己从未使用过它。它是对低级套接字 API 的绑定,因此它允许您使用底层 API 支持的所有协议。我只是引用它的自述文件,所以请持保留态度。
procket might be what you're looking for, but I've never used it myself. It's a binding to the low-level socket API, therefore it allows you to use all the protocols the underlying API supports. I'm just quoting its README, so please take it with a pinch of salt.