我有一个编程任务,需要使用 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[] )
{
//...
}
我如何获取编译该程序所需要的库文件?
答案1
对于 Ubuntu 12.04、12.10、13.10、14.04 及更高版本,打开终端并输入:
sudo apt-get install libpcap0.8-dev
答案2
您可以安装它们。尝试使用命令
sudo apt-get install pcap*
我猜你需要开发库。我的电脑列表上有:
xxxxx@xxxxx ~ $ sudo apt-get install pcap*
[sudo] password for darkstar:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libchipcard-dev' for regex 'pcap*'
Note, selecting 'libchipcard-pcsc-card-perl' for regex 'pcap*'
Note, selecting 'libpcapnav0' for regex 'pcap*'
Note, selecting 'python-ipcalc' for regex 'pcap*'
Note, selecting 'libchipcard-tools' for regex 'pcap*'
Note, selecting 'sipcalc' for regex 'pcap*'
Note, selecting 'pcal' for regex 'pcap*'
Note, selecting 'pcaputils' for regex 'pcap*'
Note, selecting 'libdate-pcalc-perl' for regex 'pcap*'
Note, selecting 'libpcap0.7-dev' for regex 'pcap*'
Note, selecting 'lua5.1-coxpcall' for regex 'pcap*'
Note, selecting 'libmlpcap-ocaml-dev' for regex 'pcap*'
Note, selecting 'libmlpcap-ocaml' for regex 'pcap*'
Note, selecting 'libpcap0.8' for regex 'pcap*'
Note, selecting 'libmlpcap-ocaml-7zxa8' for regex 'pcap*'
Note, selecting 'python-pcapy' for regex 'pcap*'
Note, selecting 'libpcap0.8-dbg' for regex 'pcap*'
Note, selecting 'libmlpcap-ocaml-dev-7zxa8' for regex 'pcap*'
Note, selecting 'pcalendar' for regex 'pcap*'
Note, selecting 'libghc-pcap-prof' for regex 'pcap*'
Note, selecting 'python2.7-libpcap' for regex 'pcap*'
Note, selecting 'libpcap0.8-dev' for regex 'pcap*'
Note, selecting 'libchipcard6' for regex 'pcap*'
Note, selecting 'ulogd-pcap' for regex 'pcap*'
Note, selecting 'apcalc-common' for regex 'pcap*'
Note, selecting 'libghc-pcap-prof-0.4.5.2-a3d5c' for regex 'pcap*'
Note, selecting 'libghc-pcap-dev-0.4.5.2-a3d5c' for regex 'pcap*'
Note, selecting 'liblua5.1-coxpcall0' for regex 'pcap*'
Note, selecting 'apcalc-dev' for regex 'pcap*'
Note, selecting 'libghc-pcap-dev' for regex 'pcap*'
Note, selecting 'libpcapnav0-dev' for regex 'pcap*'
Note, selecting 'libchipcard-data' for regex 'pcap*'
Note, selecting 'python2.7-pypcap' for regex 'pcap*'
Note, selecting 'apcalc' for regex 'pcap*'
Note, selecting 'libnet-pcap-perl' for regex 'pcap*'
Note, selecting 'udpcast' for regex 'pcap*'
Note, selecting 'libpoe-component-pcap-perl' for regex 'pcap*'
Note, selecting 'pcapfix' for regex 'pcap*'
Note, selecting 'libchipcard-libgwenhywfar60-plugins' for regex 'pcap*'
Note, selecting 'lua-coxpcall' for regex 'pcap*'
Note, selecting 'python-pypcap' for regex 'pcap*'
Note, selecting 'libpcap-dev' for regex 'pcap*'
Note, selecting 'libghc-pcap-doc' for regex 'pcap*'
Note, selecting 'python-libpcap' for regex 'pcap*'
Note, selecting 'python2.7-pcapy' for regex 'pcap*'
Note, selecting 'ulogd2-pcap' for regex 'pcap*'
Note, selecting 'ipcalc' for regex 'pcap*'
Note, selecting 'libchipcardd0' for regex 'pcap*'
Note, selecting 'dispcalgui' for regex 'pcap*'
Note, selecting 'python2.7-ipcalc' for regex 'pcap*'
Note, selecting 'libghc-pcap-dev' instead of 'libghc-pcap-dev-0.4.5.2-a3d5c'
Note, selecting 'libghc-pcap-prof' instead of 'libghc-pcap-prof-0.4.5.2-a3d5c'
Note, selecting 'libmlpcap-ocaml' instead of 'libmlpcap-ocaml-7zxa8'
Note, selecting 'libmlpcap-ocaml-dev' instead of 'libmlpcap-ocaml-dev-7zxa8'
Note, selecting 'libpcsc-perl' instead of 'libchipcard-pcsc-card-perl'
Note, selecting 'lua-coxpcall' instead of 'lua5.1-coxpcall'
Note, selecting 'python-ipcalc' instead of 'python2.7-ipcalc'
Note, selecting 'python-libpcap' instead of 'python2.7-libpcap'
Note, selecting 'python-pcapy' instead of 'python2.7-pcapy'
Note, selecting 'python-pypcap' instead of 'python2.7-pypcap'
尝试逐个添加依赖项
答案3
在“Trusty Tahr”中,以下内容对我有用:
λ ~ cat /etc/issue Ubuntu 14.04.2 LTS λ ~ sudo apt-get install libpcap-dev