Debian11下Go调用pfring报no such device,C代码可正常运行
Go调用pf_ring在Debian11失败但Debian10正常,C代码可运行的问题
我尝试使用github.com/google/gopacket/pfring包在Go代码中调用pf_ring,该代码在Debian10上可正常运行,但在Debian11上无法工作。
Go代码及运行结果
package main import ( "github.com/google/gopacket/pfring" "log" ) func main() { _, err := pfring.NewRing("eno1@0", 1574, pfring.FlagPromisc|pfring.Flag(1<<14)) if err == nil { log.Printf("Success!") return } log.Fatalf("Failure: %s", err) }
运行输出:
# ./test-go 2023/01/24 10:12:25 Failure: pfring NewRing error: no such device
接口存在验证
显然eno1接口是存在的:
# pf_ringcfg --list-interfaces Name: eno1 Driver: i40e RSS: 12 [Supported by ZC] Name: enp3s0f1 Driver: i40e RSS: 12 [Supported by ZC] Name: enx0a229512eeb9 Driver: cdc_ether RSS: 1 [Linux Driver]
C代码及运行结果
奇怪的是,逻辑相同的C代码可以正常运行:
#include <errno.h> #include <string.h> #include <stdio.h> #include <pfring.h> int main() { pfring* ring = pfring_open("eno1@0", 1574, PF_RING_PROMISC | PF_RING_ZC_NOT_REPROGRAM_RSS); if (ring != NULL) { printf("Success!\n"); exit(0); } int e = errno; char* msg = strerror(e); printf("Failure %d: %s\n", e, msg); exit(1); }
运行结果:
# ./test-c Success!
请问有人知道原因吗?
内容的提问来源于stack exchange,提问作者Étienne Miret
相关产品推荐
相关产品推荐

