libpcap

Giorgos Keramidas keramida at ceid.upatras.gr
Wed May 8 02:24:01 EEST 2002


On 2002-05-05 18:48, V13 wrote:
> Exei kaneis idea ti ginetai me toys headers ton paketon, me tin libpcap, otan
> mazeyeis kinisi apo to device 'any' ?

Se FreeBSD to parakato, exei ta ejhs omorfa apotelesmata:

    #include <pcap.h>
    #include <stdio.h>

    #define	BUFLEN	(PCAP_ERRBUF_SIZE > 4096 ? PCAP_ERRBUF_SIZE : 4096)

    int
    main (void)
    {
	    pcap_t *p;
	    char ebuf[100];

	    p = pcap_open_live("any", 128, 0, 100, ebuf);
	    if (p == NULL)
		    printf("pcap_open_live(any) failed: %s\n", ebuf);
	    else
		    pcap_close(p);

	    p = pcap_open_live(NULL, 128, 0, 100, ebuf);
	    if (p == NULL)
		    printf("pcap_open_live(NULL) failed: %s\n", ebuf);
	    else
		    pcap_close(p);

	    return 0;
    }

Otan to trekso apo aplo user, apla pairno ton mpoulo, afou den exei
permissions gia /dev/bpf0.  Otan to trekso apo root:

    # ./foo
    pcap_open_live(any) failed: BIOCSETIF: any: Device not configured
    zsh: segmentation fault (core dumped)  ./foo

To proto failure einai kanonikotato, kai to pianei to (p == NULL)
check tou protou pcap_open_live.  To deutero check den prolabainei na
treksei kathos mesa sto pcap_open_live peftei to NULL pointer
dereference kai troei ta gnosta faults sth mapa.

%%%
# cc -o foo -ggdb foo.c -lpcap
# ./foo
pcap_open_live(any) failed: BIOCSETIF: any: Device not configured
zsh: segmentation fault (core dumped)  ./foo
# gdb foo foo.core
GNU gdb 4.18
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and
you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for
details.
This GDB was configured as "i386-unknown-freebsd"...
Core was generated by `foo'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /usr/lib/libpcap.so.2...done.
Reading symbols from /usr/lib/libc.so.5...done.
Reading symbols from /usr/libexec/ld-elf.so.1...done.
#0  0x280fb308 in strncpy () from /usr/lib/libc.so.5
(gdb) bt
#0  0x280fb308 in strncpy () from /usr/lib/libc.so.5
#1  0x28076a84 in pcap_open_live () from /usr/lib/libpcap.so.2
#2  0x80486aa in main () at foo.c:18
(gdb) quit
%%%

Giorgos Keramidas                       FreeBSD Documentation Project
keramida@{freebsd.org,ceid.upatras.gr}  http://www.FreeBSD.org/docproj/



More information about the Linux-greek-users mailing list