gpt4 book ai didi

php - 带有 curl --interface 或 CURLOPT_INTERFACE 的 SO_BINDTODEVICE

转载 作者:太空狗 更新时间:2023-10-29 12:12:36 28 4
gpt4 key购买 nike

以非 root 用户身份运行此命令:

curl --interface tun0 http://google.com -v

SO_BINDTODEVICE tun0 failed with errno 1: Operation not permitted;will do regular bind

在 php 中设置 curl_setopt($ch, CURLOPT_INTERFACE "tun0") 也不起作用。但是,

ping -I tun0 google.com

工作正常,所以这只是 curl 的问题。它甚至可以与 root 的 curl 一起使用,但它确实应该适用于非 root 用户。

我有一个 openpvn 接口(interface) tun0 但同样的事情发生在 lo 接口(interface)上。

这发生在多个系统上,那么 --interface 选项是在 curl 中损坏了还是我应该以其他方式使用它?我是否应该为 curl 启用一些特殊功能才能使用该界面?

最佳答案

我认为您没有正确解释冗长的消息。

curl 的 --interface 选项要求它将套接字的本地端绑定(bind)到特定的 IP/网络接口(interface)。

绑定(bind)套接字是通过普通的 bind() 调用完成的。

除了 bind() 调用,linux 还提供SO_BINDTODEVICE setsockopt 选项,这是一种更好、更完整的接口(interface)绑定(bind)。然而,此调用需要 root 访问权限才能工作,大多数使用 libcurl 的应用程序都没有,然后它将失败并在详细输出中显示上述文本。

因此,即使存在该消息,套接字的本地绑定(bind)也能正常工作。它只是没有工作到 SO_BINDTODEVICE 级别。

关于php - 带有 curl --interface 或 CURLOPT_INTERFACE 的 SO_BINDTODEVICE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37199695/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com