Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C eBPF BPF_数组查找_C_Ebpf - Fatal编程技术网

C eBPF BPF_数组查找

C eBPF BPF_数组查找,c,ebpf,C,Ebpf,我正在尝试用eBPF和XDP构建一个数据包计数器。我需要一种方法来跟踪收到的数据包总数。因为我使用的是XDP,所以我使用BPF_数组,并在每次收到数据包时递增它。问题是我似乎无法使用提供的lookup()函数访问存储的值 下面是我如何创建BPF_数组的 BPF_ARRAY(counter, u64, 1); 下面是我如何尝试访问和使用存储的值。output.avg的类型为u64 int cindex = 0; counter.increment(&cindex); long curre

我正在尝试用eBPF和XDP构建一个数据包计数器。我需要一种方法来跟踪收到的数据包总数。因为我使用的是XDP,所以我使用BPF_数组,并在每次收到数据包时递增它。问题是我似乎无法使用提供的lookup()函数访问存储的值

下面是我如何创建BPF_数组的

BPF_ARRAY(counter, u64, 1);
下面是我如何尝试访问和使用存储的值。output.avg的类型为u64

int cindex = 0;
counter.increment(&cindex);
long current_count = counter.lookup(&cindex);
output.avg = current_count;
BPF给我这个警告,编译失败

warning: incompatible pointer to integer conversion initializing 'long' with
      an expression of type 'u64 *' (aka 'unsigned long long *') [-Wint-conversion]
                        long current_count = counter.lookup(&cindex);

我想出了解决错误的办法。我是C语言的新手,所以指针让我有点困惑

int cindex = 0;
counter.increment(cindex);
unsigned long long *current_count = counter.lookup(&cindex);

if(current_count != NULL){          
    output.avg = *current_count;    
}

我不知道库的情况,但不会
u64 current\u count=*counter.lookup(&cindex)工作?警告告诉您问题所在:
counter.lookup()
返回指针,而不是整数。尝试将
current\u count
声明为指针,而不仅仅是
long
?@veryconfusedrobot-对
计数器没有诊断。增量(&cindex)