PF_RING用户态编译问题

时间:2017-10-13 08:43:55

标签: c linux pf-ring

我试图读取incomming以太网数据包使用PF_RING。这是我的示例代码。即使我已经成功安装了pf_ring,编译器也会出现如下错误。

/ home / entc24 / workspace / PFRing / Debug /../ main.c:32:未定义引用pfring_open' /home/entc24/workspace/PFRing/Debug/../main.c:36: undefined reference to pfring_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);
}

0 个答案:

没有答案