如何在 Ubuntu 上获取 pcap 库?

Joh*_*ohn 4 compiling c libraries 12.04

我有一个需要使用 pcap 库的编程任务。

#define _BSD_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pcap.h> // <-- missing include
#include <netinet/ip.h>
#include <netinet/tcp.h>

void logpacket( unsigned char* payload, struct ip* ipheader, struct tcphdr* tcpheader )
{
    //...
}



int main(int argc, char* argv[] )
{
    //...
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能获得编译这个程序所需的库文件?

kar*_*rel 8

对于 Ubuntu 12.04、12.10、13.10、14.04 及更高版本,打开终端并键入:

sudo apt-get install libpcap0.8-dev  
Run Code Online (Sandbox Code Playgroud)