0

我正在尝试使用 PF_RING 读取传入的以太网数据包。这是我的示例代码。即使我成功安装了 pf_ring,编译器也会给出如下错误。

/home/entc24/workspace/PFRing/Debug/../main.c:32:未定义对pfring_open' /home/entc24/workspace/PFRing/Debug/../main.c:36: undefined reference topfring_recv 的引用

我在这里做错了什么?

#include <pfring.h>
#include <stdio.h>
#include <net/ethernet.h>
#include <stdlib.h>


#define MSS 1500
#define ITR 1000
#define promisc 0


int main(){
    FILE *logfile;
    logfile=fopen("log.txt","w");
        if(logfile==NULL)
        {
            printf("Unable to create log.txt file.");
        }
    printf("Starting...\n");


    const char *device_name = "zc:eth0";
    int packet_size = 0;
    char *packet_buffer = (char*)malloc(MSS);
    struct pfring_pkthdr hdr;
    pfring *pfr =  pfring_open(device_name, promisc, 0);

    int iterator =0;
    while(iterator<ITR){
    packet_size =  pfring_recv(pfr, packet_buffer, MSS, &hdr,1);
    print_ethernet_header(packet_buffer,MSS,logfile);
    iterator++;
    }

    return 0;
}



void print_ethernet_header(unsigned char* Buffer, int Size,FILE* logfile)
{
    struct ethhdr *eth = (struct ethhdr *)Buffer;

    fprintf(logfile , "\n");
    fprintf(logfile , "Ethernet Header\n");
    fprintf(logfile , "   |-Destination Address : %.2X-%.2X-%.2X-%.2X-%.2X-%.2X \n", eth->h_dest[0] , eth->h_dest[1] , eth->h_dest[2] , eth->h_dest[3] , eth->h_dest[4] , eth->h_dest[5] );
    fprintf(logfile , "   |-Source Address      : %.2X-%.2X-%.2X-%.2X-%.2X-%.2X \n", eth->h_source[0] , eth->h_source[1] , eth->h_source[2] , eth->h_source[3] , eth->h_source[4] , eth->h_source[5] );
    fprintf(logfile , "   |-Protocol            : %u \n",(unsigned short)eth->h_proto);
}
4

0 回答 0