Skip to content

Commit

Permalink
add findalldevs() - fix for issue pynetwork#17 - reviewed by dugsong
Browse files Browse the repository at this point in the history
git-svn-id: http://pypcap.googlecode.com/svn/trunk@90 0225ec8c-8f27-0410-80df-577ead3473a2
  • Loading branch information
bxsx committed Jul 13, 2010
1 parent d1f3543 commit 553d2aa
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pcap.pyx
Expand Up @@ -43,6 +43,10 @@ cdef extern from "pcap.h":
unsigned int caplen
ctypedef struct pcap_t:
int __xxx
ctypedef struct pcap_if_t # hack for win32
ctypedef struct pcap_if_t:
pcap_if_t *next
char *name

ctypedef void (*pcap_handler)(void *arg, pcap_pkthdr *hdr, char *pkt)

Expand All @@ -63,6 +67,8 @@ cdef extern from "pcap.h":
char *pcap_geterr(pcap_t *p)
void pcap_close(pcap_t *p)
int bpf_filter(bpf_insn *insns, char *buf, int len, int caplen)
int pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
void pcap_freealldevs(pcap_if_t *alldevs)

cdef extern from "pcap_ex.h":
# XXX - hrr, sync with libdnet and libevent
Expand Down Expand Up @@ -369,3 +375,22 @@ def lookupdev():
raise OSError, ebuf
return p

def findalldevs():
"""Return a list of capture devices."""
cdef pcap_if_t *devs, *curr
cdef char ebuf[256]

status = pcap_findalldevs(&devs, ebuf)
if status:
raise OSError(ebuf)
retval = []
if not devs:
return retval
curr = devs
while 1:
retval.append(curr.name)
if not curr.next:
break
curr = curr.next
pcap_freealldevs(devs)
return retval

0 comments on commit 553d2aa

Please sign in to comment.