我用以下的方式安装libpcap,
./configure
make
make install
并且用下面的代码测试:
#include <stdio.h> #include <stdlib.h> #include <pcap.h> int main( int argc, char** argv ) { char *dev, errbuf[PCAP_ERRBUF_SIZE]; dev = pcap_lookupdev( errbuf ); if ( dev == NULL ) { fprintf( stderr, "couldn't find default device: %s\n", errbuf ); return ( 2 ); } printf( "Device: %s\n", dev ); return ( 0 ); }
可是在编译的时候出现:
lx@ubuntu:~/c/test$ gcc -o test24 test24.c -lpcap/usr/local/lib/libpcap.so: undefined reference to `pcap_parse'
如是我google下 这样就 “sudo apt-get install libpcap-dev”没有错误了 只是我不知道原因,在看看的。