gpt4 book ai didi

networking - 创建PNET数据链接 channel 时出现Rust错误 “PermissionDenied: Operation Not Permitted”

转载 作者:行者123 更新时间:2023-12-03 11:42:22 30 4
gpt4 key购买 nike

pnet's main doc page上的“以太网回显服务器”示例中使用的示例数据链路 channel 创建代码包括以下代码段:

// Create a new channel, dealing with layer 2 packets
let (mut tx, mut rx) = match datalink::channel(&interface, Default::default()) {
Ok(Ethernet(tx, rx)) => (tx, rx),
Ok(_) => panic!("Unhandled channel type"),
Err(e) => panic!("An error occurred when creating the datalink channel: {}", e)
};
这在我的CentOS7上不起作用,抛出错误: thread 'main' panicked at 'An error occurred when creating the datalink channel: Os { code: 1, kind: PermissionDenied, message: "Operation not permitted" }', src/bin/main.rs:83:27使用上面的内容或更简单地重新创建:
use pnet::datalink;
fn main() {
for i in datalink::interfaces() {
println!("{}", i.name);
match datalink::channel(&i, Default::default()) {
Ok(_) => println!("OK"),
Err(_) => println!("ERR")
}
}
}

最佳答案

pnet试图打开需要root权限或CAP_NET_RAW功能的raw socket。这会导致“操作不允许”错误。以root身份运行可解决此问题。

关于networking - 创建PNET数据链接 channel 时出现Rust错误 “PermissionDenied: Operation Not Permitted”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66087169/

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