在Ubuntu安裝測試libpcap(Install the libpcap in Ubuntu 11.04)

來源:互聯網
上載者:User

1.Download the tar of libpcap

in site: http://www.tcpdump.org/

My File is libpcap-1.2.1.tar.gz.

tar -zxvf libpcap-1.3.0.tar.gz 

2.Now, We get the folder libpcap-1.3.0

cd libpcap-1.3.0

3.we need install flex
sudo apt-get install flex

if don't do this step will:

configure: error: Your operating system 's lex is insufficient to compile libpcap.  flex is a lex replacement that has many advantages,
including being able to compile libpcap.  For more information, see http:
//www.gnu.org/software/flex/flex.html .

4. Configure

./configure


5.Install byacc

sudo apt-get install byacc

if not do this step will :
yacc -d grammar.y
make: yacc: Command not found
make: *** [grammar.c] Error 127

6. make

7. sudo make install

8. Test.

vim testlibpcap.c

#include<stdio.h>#include<stdlib.h>#include<pcap.h>#include<errno.h>#include<sys/socket.h>#include<netinet/in.h>#include<arpa/inet.h> int main(int argc,char *argv[]){    char *dev;    char errbuf[PCAP_ERRBUF_SIZE];    dev = pcap_lookupdev(errbuf);    if(dev ==NULL)    {        printf("%s\n",errbuf);        exit(1);    }    printf("裝置名稱:%s\n",dev);    return 0;}
gcc  testlibpcap.c -o testlibpcap -lpcap -Wall

9 ln a link for libpcap

sudo ln -s /usr/lib/libpcap.1.X.X /usr/lib/libpcap.1

if don't do this step, 10th step will:

error while loading shared libraries: libpcap.so.1: cannot open shared object file: No such file or directory

10 Run it!

sudo ./testlibpcap

If it show:

裝置名稱:XXX

Congratulation for  your success !

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.