Giter VIP home page Giter VIP logo

pypcap's People

Contributors

bxsx avatar kosma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pypcap's Issues

[patch] Add dumpfile support

There is currently no support for saving a capture file with pypac. The 
attached patch adds the support for the pcap_dump_open, pcap_dump_close, and 
pcap_dump API functions internally, and exposes to python the setdumpfile(self, 
filename) function to set up the packet dumper. Once enabled, any packet that 
passes the filter will be logged to the dumpfile.

Not included is a way to selectively dump individual packets from python, as 
that would require re-architecting things in such a way as to make pcap_pkthdrs 
available to python to pass to pcap_dump(). Not impossible, but it would change 
the semantics a bit.

Original issue reported on code.google.com by [email protected] on 8 Dec 2011 at 5:25

Attachments:

Building under Windows gets error

d:\projects\pypcap>mingw32-make
python setup.py config --with-pcap=c:\\wpdpack
running config
found {'libraries': ['wpcap', 'iphlpapi'], 'library_dirs': ['c:\\wpdpack\\lib'],
 'extra_compile_args': ['-DWIN32', '-DWPCAP'], 'include_dirs': ['c:\\wpdpack\\in
clude/pcap']}
python setup.py build
running build
running build_ext
building 'pcap' extension
c:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -Ic:\wpdpack\include/pcap -Ic:\P
ython26\include -Ic:\Python26\PC -c pcap.c -o build\temp.win32-2.6\Release\pcap.
o -DWIN32 -DWPCAP
In file included from pcap.c:30:0:
c:\wpdpack\include/pcap/pcap.h:41:27: fatal error: pcap-stdinc.h: No such file o
r directory
compilation terminated.
error: command 'gcc' failed with exit status 1
mingw32-make: *** [all] Error 1


I think problem with wrong 'include_dirs': ['c:\\wpdpack\\include/pcap']

Original issue reported on code.google.com by [email protected] on 15 Sep 2010 at 1:12

no pcap.h file in distribution

What steps will reproduce the problem?
1. python setup.py install

What is the expected output? What do you see instead?

Clean build

 python setup.py install
running install
running build
running build_ext
building 'pcap' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes
-fPIC -I/home/williams/include/python2.5 -c pcap.c -o
build/temp.linux-i686-2.5/pcap.o
pcap.c:8:18: error: pcap.h: No such file or directory
In file included from pcap.c:9:
pcap_ex.h:6: error: expected ‘)’ before ‘*’ token
pcap_ex.h:9: error: expected ‘)’ before ‘*’ token
pcap_ex.h:10: error: expected ‘)’ before ‘*’ token
pcap_ex.h:11: error: expected ‘)’ before ‘*’ token
pcap_ex.h:12: error: expected ‘)’ before ‘*’ token
pcap_ex.h:13: error: expected ‘)’ before ‘*’ token
pcap_ex.h:15: warning: ‘struct bpf_program’ declared inside parameter list
pcap_ex.h:15: warning: its scope is only this definition or declaration,
which is probably not what you want
...
pcap.c:2255: warning: suggest explicit braces to avoid ambiguous ‘else’
error: command 'gcc' failed with exit status 1


What version of the product are you using? On what operating system?

pypcap-1.1
Python 2.5
CentOS 5


Please provide any additional information below.

Tried "libpcap-0.9.4-12.el5python setup.py install" after "python setup.py
config" didn't work.

libpcap-0.9.4-12.el5 installed, but no /usr/include/pcap.h

Original issue reported on code.google.com by [email protected] on 9 Sep 2008 at 3:47

Exposing pcap_sendpacket

Maybe this is outside the scope of this project, but have you considered 
providing a Python interface to pcap_sendpacket()? This would allow Python 
apps running on Windows an easy way to send raw ethernet frames. Thanks.


Original issue reported on code.google.com by [email protected] on 1 Feb 2010 at 7:28

pypcap depends from pcap-int.h which is internal pcap stuff and shouldn't be included (breaking build on some systems)

>>> Emerging (1 of 1) dev-python/pypcap-1.1.1::gentoo
 * pypcap-1.1.1.tar.gz SHA256 SHA512 WHIRLPOOL size ;-) ...                                                                                                        
[ ok ]
>>> Unpacking source...
>>> Unpacking pypcap-1.1.1.tar.gz to 
/var/tmp/portage/dev-python/pypcap-1.1.1/work
>>> Source unpacked in /var/tmp/portage/dev-python/pypcap-1.1.1/work
>>> Preparing source in 
/var/tmp/portage/dev-python/pypcap-1.1.1/work/pypcap-1.1.1 ...
>>> Source prepared.
>>> Configuring source in 
/var/tmp/portage/dev-python/pypcap-1.1.1/work/pypcap-1.1.1 ...
>>> Source configured.
>>> Compiling source in 
/var/tmp/portage/dev-python/pypcap-1.1.1/work/pypcap-1.1.1 ...
 * python2_7: running distutils-r1_run_phase python_compile
/usr/bin/python2.7 setup.py build
^[[AFound pcap headers in /usr/include/pcap/pcap.h
Found libraries in /usr/lib/libpcap.so
found pcap_setnonblock
found pcap_compile_nopcap function
found pcap_file function
running build
running build_ext
building 'pcap' extension
creating 
/var/tmp/portage/dev-python/pypcap-1.1.1/work/pypcap-1.1.1-python2_7/temp.linux-
x86_64-2.7
x86_64-pc-linux-gnu-gcc -O2 -march=corei7-avx -pipe -fno-strict-aliasing -fPIC 
-DHAVE_PCAP_INT_H=1 -DHAVE_PCAP_SETNONBLOCK=1 -DHAVE_PCAP_COMPILE_NOPCAP=1 
-DHAVE_PCAP_FILE=1 -I/usr/include/pcap -I/usr/include/python2.7 -c pcap.c -o 
/var/tmp/portage/dev-python/pypcap-1.1.1/work/pypcap-1.1.1-python2_7/temp.linux-
x86_64-2.7/pcap.o
pcap.c: In function ‘__pyx_pf_4pcap_3bpf_2filter’:
pcap.c:1395:3: warning: passing argument 2 of ‘PyObject_AsCharBuffer’ from 
incompatible pointer type [enabled by default]
In file included from /usr/include/python2.7/Python.h:133:0,
                 from pcap.c:16:
/usr/include/python2.7/abstract.h:476:22: note: expected ‘const char **’ 
but argument is of type ‘char **’
pcap.c:1395:3: warning: passing argument 3 of ‘PyObject_AsCharBuffer’ from 
incompatible pointer type [enabled by default]
In file included from /usr/include/python2.7/Python.h:133:0,
                 from pcap.c:16:
/usr/include/python2.7/abstract.h:476:22: note: expected ‘Py_ssize_t *’ but 
argument is of type ‘int *’
pcap.c: In function ‘__pyx_pf_4pcap_4pcap_16dispatch’:
pcap.c:3135:3: warning: passing argument 3 of ‘pcap_dispatch’ from 
incompatible pointer type [enabled by default]
In file included from pcap.c:343:0:
/usr/include/pcap/pcap.h:373:5: note: expected ‘pcap_handler’ but argument 
is of type ‘void (*)(void *, struct pcap_pkthdr *, char *)’
pcap.c: In function ‘__pyx_pf_4pcap_4pcap_18loop’:
pcap.c:3364:5: warning: passing argument 3 of ‘pcap_ex_next’ from 
incompatible pointer type [enabled by default]
In file included from pcap.c:344:0:
pcap_ex.h:13:7: note: expected ‘u_char **’ but argument is of type ‘char 
**’
pcap.c: In function ‘__pyx_pf_4pcap_4pcap_28__next__’:
pcap.c:3976:5: warning: passing argument 3 of ‘pcap_ex_next’ from 
incompatible pointer type [enabled by default]
In file included from pcap.c:344:0:
pcap_ex.h:13:7: note: expected ‘u_char **’ but argument is of type ‘char 
**’
x86_64-pc-linux-gnu-gcc -O2 -march=corei7-avx -pipe -fno-strict-aliasing -fPIC 
-DHAVE_PCAP_INT_H=1 -DHAVE_PCAP_SETNONBLOCK=1 -DHAVE_PCAP_COMPILE_NOPCAP=1 
-DHAVE_PCAP_FILE=1 -I/usr/include/pcap -I/usr/include/python2.7 -c pcap_ex.c -o 
/var/tmp/portage/dev-python/pypcap-1.1.1/work/pypcap-1.1.1-python2_7/temp.linux-
x86_64-2.7/pcap_ex.o
pcap_ex.c:18:23: fatal error: pcap-int.h: No such file or directory
compilation terminated.
error: command 'x86_64-pc-linux-gnu-gcc' failed with exit status 1


Original issue reported on code.google.com by [email protected] on 25 Nov 2014 at 3:55

timeout doesn't work

Here is an easy code to reproduce a task (obviously if there will not be
host 1.1.1.1)

import pcap
descr = pcap.pcap("eth0", timeout_ms=10000)
descr.setfilter("host 1.1.1.1")
descr.next()

bugfixed attached

Original issue reported on code.google.com by [email protected] on 9 Oct 2009 at 3:10

Attachments:

error: dereferencing pointer to incomplete type in solaris x86

제 솔라리스 10 x86 환경에서 컴파일 해보는데.. 

bash-3.2$ wget http://pypcap.googlecode.com/files/pypcap-1.1.tar.gz
--11:26:03--  http://pypcap.googlecode.com/files/pypcap-1.1.tar.gz
           => `pypcap-1.1.tar.gz'
Resolving pypcap.googlecode.com... 66.102.1.82
Connecting to pypcap.googlecode.com|66.102.1.82|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 22,951 (22K) [application/x-gzip]

100%[====================================>] 22,951        48.56K/s             

11:26:05 (48.49 KB/s) - `pypcap-1.1.tar.gz' saved [22951/22951]

bash-3.2$ gtar zxvf pypcap-1.1.tar.gz
bash-3.2$ pwd
/export/home/sandy/pypcap-1.1
bash-3.2$ ls -al
총 270
drwxr-xr-x   3 sandy    other        512  3월 10일  11:26 .
drwxr-xr-x  52 sandy    other       4096  3월 10일  11:26 ..
-rw-r--r--   1 sandy    other        508 2005년 10월 16일 CHANGES
-rw-r--r--   1 sandy    other       1431 2005년 10월 16일 LICENSE
-rw-r--r--   1 sandy    other        615 2005년 10월 16일 Makefile
-rw-r--r--   1 sandy    other        371 2005년 10월 16일 README
drwxr-xr-x   3 root     root         512  3월 10일  11:26 build
-rw-r--r--   1 sandy    other      98124 2005년 10월 16일 pcap.c
-rw-r--r--   1 sandy    other      11982 2005년 10월 16일 pcap.pyx
-rw-r--r--   1 sandy    other       6162 2005년 10월 16일 pcap_ex.c
-rw-r--r--   1 sandy    other        629 2005년  8월 29일 pcap_ex.h
-rw-r--r--   1 sandy    other       4002 2005년 10월 16일 setup.py
-rw-r--r--   1 sandy    other        468 2005년  1월 26일 test.pcap
-rwxr-xr-x   1 sandy    other       1431 2005년  9월 11일 test.py
-rwxr-xr-x   1 sandy    other        914 2005년  1월 26일 testsniff.py

bash-3.2$ cd py*
bash-3.2$ sudo python setup.py install
running install
running build
running build_ext
building 'pcap' extension
creating build
creating build/temp.solaris-2.10-i86pc-2.5
gcc -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC
-I/usr/local/include/python2.5 -c pcap.c -o
build/temp.solaris-2.10-i86pc-2.5/pcap.o
pcap.c: In function `__pyx_f_4pcap_3bpf___dealloc__':
pcap.c:320: warning: label `__pyx_L1' defined but not used
pcap.c: In function `__pyx_f_4pcap_4pcap_dispatch':
pcap.c:1039: warning: passing arg 3 of `pcap_dispatch' from incompatible
pointer type
pcap.c: In function `__pyx_f_4pcap_4pcap_loop':
pcap.c:1142: warning: passing arg 3 of `pcap_ex_next' from incompatible
pointer type
pcap.c:1134: warning: label `__pyx_L2' defined but not used
pcap.c: In function `__pyx_f_4pcap_4pcap___iter__':
pcap.c:1305: warning: label `__pyx_L1' defined but not used
pcap.c: In function `__pyx_f_4pcap_4pcap___next__':
pcap.c:1338: warning: passing arg 3 of `pcap_ex_next' from incompatible
pointer type
pcap.c:1330: warning: label `__pyx_L2' defined but not used
pcap.c:1382: warning: label `__pyx_L3' defined but not used
pcap.c: In function `__pyx_f_4pcap_4pcap___dealloc__':
pcap.c:1433: warning: label `__pyx_L1' defined but not used
pcap.c: In function `__pyx_tp_new_4pcap_bpf':
pcap.c:1567: warning: unused variable `p'
pcap.c: In function `__pyx_tp_dealloc_4pcap_bpf':
pcap.c:1572: warning: unused variable `p'
pcap.c: In function `__pyx_tp_traverse_4pcap_bpf':
pcap.c:1586: warning: unused variable `e'
pcap.c:1587: warning: unused variable `p'
pcap.c: In function `__pyx_tp_clear_4pcap_bpf':
pcap.c:1592: warning: unused variable `p'
pcap.c: In function `__pyx_tp_new_4pcap_pcap':
pcap.c:1719: warning: unused variable `p'
pcap.c: In function `__pyx_tp_dealloc_4pcap_pcap':
pcap.c:1724: warning: unused variable `p'
pcap.c: In function `__pyx_tp_traverse_4pcap_pcap':
pcap.c:1738: warning: unused variable `e'
pcap.c:1739: warning: unused variable `p'
pcap.c: In function `__pyx_tp_clear_4pcap_pcap':
pcap.c:1744: warning: unused variable `p'
pcap.c: In function `__Pyx_GetStarArgs':
pcap.c:2253: warning: suggest explicit braces to avoid ambiguous `else'
pcap.c:2255: warning: suggest explicit braces to avoid ambiguous `else'
pcap.c: At top level:
pcap.c:14: warning: '__Pyx_UnpackItem' declared `static' but never defined
pcap.c:15: warning: '__Pyx_EndUnpack' declared `static' but never defined
pcap.c:16: warning: '__Pyx_PrintItem' declared `static' but never defined
pcap.c:17: warning: '__Pyx_PrintNewline' declared `static' but never defined
pcap.c:19: warning: '__Pyx_ReRaise' declared `static' but never defined
pcap.c:22: warning: '__Pyx_ArgTypeTest' declared `static' but never defined
pcap.c:23: warning: '__Pyx_TypeTest' declared `static' but never defined
pcap.c:27: warning: '__Pyx_ImportType' declared `static' but never defined
pcap.c:28: warning: '__Pyx_SetVtable' declared `static' but never defined
pcap.c:29: warning: '__Pyx_GetVtable' declared `static' but never defined
pcap.c:30: warning: '__Pyx_CreateClass' declared `static' but never defined
gcc -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC
-I/usr/local/include/python2.5 -c pcap_ex.c -o
build/temp.solaris-2.10-i86pc-2.5/pcap_ex.o
pcap_ex.c:22:20: config.h: 해당 파일이나 디렉토리가 없음
pcap_ex.c: In function `pcap_ex_fileno':
pcap_ex.c:165: error: dereferencing pointer to incomplete type
pcap_ex.c: In function `pcap_ex_next':
pcap_ex.c:253: error: dereferencing pointer to incomplete type
pcap_ex.c: In function `pcap_ex_compile_nopcap':
pcap_ex.c:285: warning: implicit declaration of function `mktemp'
error: command 'gcc' failed with exit status 1



 음 문제가 뭘까요?

 21
    22  #include "config.h"
    23


 int
   156  pcap_ex_fileno(pcap_t *pcap)
   157  {
   158  #ifdef _WIN32
   159          /* XXX - how to handle savefiles? */
   160          return ((int)pcap_getevent(pcap));
   161  #else
   162  # ifdef HAVE_PCAP_FILE
   163          FILE *f = pcap_file(pcap);
   164  # else
   165          FILE *f = pcap->sf.rfile;
   166  # endif
   167          if (f != NULL)
   168                  return (fileno(f));
   169          return (pcap_fileno(pcap));
   170  #endif /* !_WIN32 */
   171  }


   226  /* return codes: 1 = pkt, 0 = timeout, -1 = error, -2 = EOF */
   227  int
   228  pcap_ex_next(pcap_t *pcap, struct pcap_pkthdr **hdr, u_char **pkt)
   229  {
   230  #ifdef _WIN32
   231          if (__pcap_ex_gotsig) {
   232                  __pcap_ex_gotsig = 0;
   233                  return (-1);
   234          }
   235          return (pcap_next_ex(pcap, hdr, pkt));
   236  #else
   237          static u_char *__pkt;
   238          static struct pcap_pkthdr __hdr;
   239          struct timeval tv = { 1, 0 };
   240          fd_set rfds;
   241          int fd, n;
   242
   243          fd = pcap_fileno(pcap);
   244          for (;;) {
   245                  if (__pcap_ex_gotsig) {
   246                          __pcap_ex_gotsig = 0;
   247                          return (-1);
   248                  }
   249                  if ((__pkt = (u_char *)pcap_next(pcap, &__hdr)) ==
NULL) {
   250  #ifdef HAVE_PCAP_FILE
   251                          if (pcap_file(pcap) != NULL)
   252  #else
   253                          if (pcap->sf.rfile != NULL)
   254  #endif
   255                                  return (-2);
   256                          FD_ZERO(&rfds);
   257                          FD_SET(fd, &rfds);
   258                          n = select(fd + 1, &rfds, NULL, NULL, &tv);
   259                          if (n <= 0)
   260                                  return (n);
   261                  } else
   262                          break;
   263          }
   264          *pkt = __pkt;
   265          *hdr = &__hdr;
   266
   267          return (1);
   268  #endif
   269  }
   270


271  int
   272  pcap_ex_compile_nopcap(int snaplen, int dlt, struct bpf_program
*fp, char *str,
   273      int optimize, unsigned int netmask)
   274  {
   275  #ifdef HAVE_PCAP_COMPILE_NOPCAP
   276          return (pcap_compile_nopcap(snaplen, dlt, fp, str,
optimize, netmask));
   277  #else
   278          FILE *f;
   279          struct pcap_file_header hdr;
   280          pcap_t *pc;
   281          char path[] = "/tmp/.pypcapXXXXXX.pcap";
   282          char ebuf[PCAP_ERRBUF_SIZE];
   283          int ret = -1;
   284
   285          mktemp(path);
   286          if ((f = fopen(path, "w")) != NULL) {
   287                  hdr.magic = 0xa1b2c3d4;
   288                  hdr.version_major = PCAP_VERSION_MAJOR;
   289                  hdr.version_minor = PCAP_VERSION_MINOR;
   290                  hdr.thiszone = 0;
   291                  hdr.snaplen = snaplen;
   292                  hdr.sigfigs = 0;
   293                  hdr.linktype = dlt;
   294                  fwrite(&hdr, sizeof(hdr), 1, f);
   295                  fclose(f);
   296
   297                  if ((pc = pcap_open_offline(path, ebuf)) != NULL) {
   298                          ret = pcap_compile(pc, fp, str, optimize,
netmask);
   299                          pcap_close(pc);
   300                  }
   301                  unlink(path);
   302          }
   303          return (ret);
   304  #endif
   305  }



제 환경입니다.
bash-3.2$ uname -a
SunOS gagemel 5.10 Generic_118844-20 i86pc i386 i86pc
bash-3.2$ python
Python 2.5 (r25:51908, Sep 20 2006, 03:11:51) 
[GCC 3.4.6] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Original issue reported on code.google.com by [email protected] on 10 Mar 2007 at 11:59

error mingw-32 make on windows

C:\Users\hp\Downloads\WpdPack_4_1_2\WpdPack\include/pcap/pcap.h:303:6: note: ex
ected 'const u_char *' but argument is of type 'u_char *'
writing build\temp.win32-2.7\Release\pcap.def
c:\Rtools\gcc-4.6.3\bin\gcc.exe -shared -s build\temp.win32-2.7\Release\pcap.o
uild\temp.win32-2.7\Release\pcap_ex.o build\temp.win32-2.7\Release\pcap.def -LC
\Users\hp\Downloads\WpdPack_4_1_2\WpdPack\lib -LC:\Python27\libs -LC:\Python27
Cbuild -lwpcap -liphlpapi -lpython27 -lmsvcr90 -o build\lib.win32-2.7\pcap.pyd
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-
ingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-mingw_helpers.o): In function
decode_pointer': /data/gannet/ripley/Sources/mingw-test3/src/mingw-w64/stable/v2.x/mingw-w64-crt crt/mingw_helpers.c:22: multiple definition of_decode_pointer'
C:\Python27\libs/libmsvcr90.a(dmmebs00281.o):(.text+0x0): first defined here
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-
ingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-mingw_helpers.o): In function
encode_pointer': /data/gannet/ripley/Sources/mingw-test3/src/mingw-w64/stable/v2.x/mingw-w64-crt crt/mingw_helpers.c:28: multiple definition of_encode_pointer'
C:\Python27\libs/libmsvcr90.a(dmmebs00291.o):(.text+0x0): first defined here
collect2: ld returned 1 exit status
error: command 'c:\Rtools\gcc-4.6.3\bin\gcc.exe' failed with exit status 1

Problems with timeout_ms at least on Windows 7

When I captures packets in iteration mode (for ts, pkt in pc:) or through loop 
I have long delays before recieving packets. This is particularly evident when 
computer gets small amount of packets (if you set filter or network contains 
small amount of computers).

I did some research. I think problem is related to timeout_ms (to_ms for 
winpcap pcap_open_live). As far as I understand a value of 0 means no time out; 
on at least some platforms, this means that you may wait until a sufficient 
number of packets arrive before seeing any packets, so you should use a 
non-zero timeout (http://www.tcpdump.org/pcap.htm). Winpcap documentation is 
not very clear at this point.

I tried to delete lines
  elif n == 0:
    break
for loop and __next__ functions.
And all works fine.

I think this is the right approach - not break loop if timeout is reached. 
Otherwise, you can get problems with timeout_ms values different from 0.

My OS - Windows 7. I uses lastes code from svn.

Original issue reported on code.google.com by [email protected] on 5 Oct 2010 at 4:25

Update dependency

What steps will reproduce the problem?
1. Install non-dev OS (e.g. Ubuntu)
2. Try to build this package.

What is the expected output? What do you see instead?
Expect: Clean build
See: Failed build (many warnings + missing headers that kill you)

What version of the product are you using? On what operating system?
Jan 27

Please provide any additional information below.
Please add python-dev as a dependency that is checked for or at least stated.

Original issue reported on code.google.com by [email protected] on 18 Mar 2007 at 2:27

Stop pypcap from capturing and writing network traffic to a file

I'm capturing network traffic with pypcap and writing it to a file with dpkt. Problem is I can't delete the file as I get an error saying it's still in use by another process.

seconds = 15
starttime = datetime.datetime.now()

pc = pcap.pcap()
file = open('file.pcap', 'wb')
pcapfile dpkt.pcap.Writer(file)

for timestamp, packet in pc:
    currenttime = datetime.datetime.now()
    timedelta = currenttime - starttime
    if timedelta.seconds > seconds:
        break

    pcapfile.writepkt(packet,timestamp)

file.close

time.sleep(10)

os.remove(file.pcap) = file in use by another process error

I'm currently overwriting the pcap file the next time I capture traffic. Doing this overwrites the file data most of the time, but occasionally it doesn't work and I end up with a large pcap file encompassing two sets of network capture data.

How do you close the pcapy/dpkt process handle?

Also does anyone know a better way to stop pcapy capturing traffic after 15 seconds?

Thanks

can't install pypcap on CentOS 5 with python 2.5

What steps will reproduce the problem?
1. python setup.py config

What is the expected output? What do you see instead?

 python setup.py config
running config
setup.py:63: DeprecationWarning: raising a string exception is deprecated
  raise "couldn't find pcap build or installation directory"
Traceback (most recent call last):
  File "setup.py", line 101, in <module>
    ext_modules = [ pcap ])
  File "/home/williams/lib/python2.5/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/home/williams/lib/python2.5/distutils/dist.py", line 974, in
run_commands
    self.run_command(cmd)
  File "/home/williams/lib/python2.5/distutils/dist.py", line 994, in
run_command
    cmd_obj.run()
  File "setup.py", line 67, in run
    cPickle.dump(self._pcap_config([ self.with_pcap ]),
  File "setup.py", line 63, in _pcap_config
    raise "couldn't find pcap build or installation directory"
couldn't find pcap build or installation directory


What version of the product are you using? On what operating system?

pypcap-1.1
Python 2.5.1

% uname -r
2.6.18-92.1.10.el5

% cat /etc/redhat-release 
CentOS release 5.2 (Final)

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 9 Sep 2008 at 3:27

AttributeError: 'pcap.pcap' object has no attribute 'inject'

What steps will reproduce the problem?
running oftests on linux with python2.7 is giving this error :

Traceback (most recent call last):
  File "/usr/local/bin/oftest/tests/basic.py", line 94, in runTest
    self.dataplane.send(of_port, str(pkt))
  File "/usr/local/bin/oftest/src/python/oftest/dataplane.py", line 250, in send
    bytes = self.ports[port_number].send(packet)
  File "/usr/local/bin/oftest/src/python/oftest/dataplane.py", line 132, in send
    return self.pcap.inject(packet, len(packet))
AttributeError: 'pcap.pcap' object has no attribute 'inject'


i am using python2.7 with pycap1.1
how can i fix this ?? can someone help here .


thanks 

Original issue reported on code.google.com by [email protected] on 7 Oct 2013 at 2:34

Cant Install pypcap on ubuntu 7.10


What version of the product are you using? On what operating system?
Hi im trying to install pypcap on ubuntu server 7.10.... 

Im trying Python2.5 and Python2.6, I have the next output when I try to
install it:

root@agente1:~/Rishi/pypcap-1.1# python -V
Python 2.6.1
root@agente1:~/Rishi/pypcap-1.1# python setup.py install
running install
running build
running build_ext
building 'pcap' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall
-Wstrict-prototypes -fPIC -I/usr/local/include/python2.6 -c pcap_ex.c -o
build/temp.linux-i686-2.6/pcap_ex.o
pcap_ex.c:22:20: error: config.h: No such file or directory
pcap_ex.c: In function ‘pcap_ex_fileno’:
pcap_ex.c:165: error: dereferencing pointer to incomplete type
pcap_ex.c: In function ‘pcap_ex_next’:
pcap_ex.c:253: error: dereferencing pointer to incomplete type
pcap_ex.c: In function ‘pcap_ex_compile_nopcap’:
pcap_ex.c:285: warning: implicit declaration of function ‘mktemp’
error: command 'gcc' failed with exit status 1


And Using Python2.5

root@agente1:~/Rishi/pypcap-1.1# python2.5 setup.py install
running install
running build
running build_ext
building 'pcap' extension
creating build
creating build/temp.linux-i686-2.5
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O2 -Wall -Wstrict-prototypes
-fPIC -I/usr/include/python2.5 -c pcap.c -o build/temp.linux-i686-2.5/pcap.o
pcap.c: In function ‘__pyx_f_4pcap_3bpf_filter’:
pcap.c:280: warning: pointer targets in passing argument 2 of ‘bpf_filter’
differ in signedness
pcap.c: In function ‘__pyx_f_4pcap_3bpf___dealloc__’:
pcap.c:320: warning: label ‘__pyx_L1’ defined but not used
pcap.c: In function ‘__pyx_f_4pcap_4pcap_dispatch’:
pcap.c:1039: warning: passing argument 3 of ‘pcap_dispatch’ from
incompatible pointer type
pcap.c: In function ‘__pyx_f_4pcap_4pcap_loop’:
pcap.c:1142: warning: passing argument 3 of ‘pcap_ex_next’ from
incompatible pointer type
pcap.c:1134: warning: label ‘__pyx_L2’ defined but not used
pcap.c: In function ‘__pyx_f_4pcap_4pcap___iter__’:
pcap.c:1305: warning: label ‘__pyx_L1’ defined but not used
pcap.c: In function ‘__pyx_f_4pcap_4pcap___next__’:
pcap.c:1338: warning: passing argument 3 of ‘pcap_ex_next’ from
incompatible pointer type
pcap.c:1382: warning: label ‘__pyx_L3’ defined but not used
pcap.c:1330: warning: label ‘__pyx_L2’ defined but not used
pcap.c: In function ‘__pyx_f_4pcap_4pcap___dealloc__’:
pcap.c:1433: warning: label ‘__pyx_L1’ defined but not used
pcap.c: In function ‘__pyx_tp_new_4pcap_bpf’:
pcap.c:1567: warning: unused variable ‘p’
pcap.c: In function ‘__pyx_tp_dealloc_4pcap_bpf’:
pcap.c:1572: warning: unused variable ‘p’
pcap.c: In function ‘__pyx_tp_traverse_4pcap_bpf’:
pcap.c:1587: warning: unused variable ‘p’
pcap.c:1586: warning: unused variable ‘e’
pcap.c: In function ‘__pyx_tp_clear_4pcap_bpf’:
pcap.c:1592: warning: unused variable ‘p’
pcap.c: In function ‘__pyx_tp_new_4pcap_pcap’:
pcap.c:1719: warning: unused variable ‘p’
pcap.c: In function ‘__pyx_tp_dealloc_4pcap_pcap’:
pcap.c:1724: warning: unused variable ‘p’
pcap.c: In function ‘__pyx_tp_traverse_4pcap_pcap’:
pcap.c:1739: warning: unused variable ‘p’
pcap.c:1738: warning: unused variable ‘e’
pcap.c: In function ‘__pyx_tp_clear_4pcap_pcap’:
pcap.c:1744: warning: unused variable ‘p’
pcap.c: In function ‘__Pyx_GetStarArgs’:
pcap.c:2253: warning: suggest explicit braces to avoid ambiguous ‘else’
pcap.c:2255: warning: suggest explicit braces to avoid ambiguous ‘else’
pcap.c: At top level:
pcap.c:14: warning: ‘__Pyx_UnpackItem’ declared ‘static’ but never 
defined
pcap.c:15: warning: ‘__Pyx_EndUnpack’ declared ‘static’ but never 
defined
pcap.c:16: warning: ‘__Pyx_PrintItem’ declared ‘static’ but never 
defined
pcap.c:17: warning: ‘__Pyx_PrintNewline’ declared ‘static’ but never 
defined
pcap.c:19: warning: ‘__Pyx_ReRaise’ declared ‘static’ but never defined
pcap.c:22: warning: ‘__Pyx_ArgTypeTest’ declared ‘static’ but never 
defined
pcap.c:23: warning: ‘__Pyx_TypeTest’ declared ‘static’ but never defined
pcap.c:27: warning: ‘__Pyx_ImportType’ declared ‘static’ but never 
defined
pcap.c:28: warning: ‘__Pyx_SetVtable’ declared ‘static’ but never 
defined
pcap.c:29: warning: ‘__Pyx_GetVtable’ declared ‘static’ but never 
defined
pcap.c:30: warning: ‘__Pyx_CreateClass’ declared ‘static’ but never 
defined
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O2 -Wall -Wstrict-prototypes
-fPIC -I/usr/include/python2.5 -c pcap_ex.c -o
build/temp.linux-i686-2.5/pcap_ex.o
pcap_ex.c:22:20: error: config.h: No such file or directory
pcap_ex.c: In function ‘pcap_ex_fileno’:
pcap_ex.c:165: error: dereferencing pointer to incomplete type
pcap_ex.c: In function ‘pcap_ex_next’:
pcap_ex.c:253: error: dereferencing pointer to incomplete type
pcap_ex.c: In function ‘pcap_ex_compile_nopcap’:
pcap_ex.c:285: warning: implicit declaration of function ‘mktemp’
error: command 'gcc' failed with exit status 1

Nows What????

Well I foung .deb of pypcap and installed on my system, but it dont works

root@agente1:~/Rishi/pypcap-1.1# dpkg --list | grep libpcap
ii  libpcap0.7                   0.7.2-7                               
System interface for user-level packet captu
ii  libpcap0.8                   0.9.7-1build1                         
System interface for user-level packet captu
ii  libpcap0.8-dev               0.9.7-1build1                         
Development library and header files for lib
ii  python-pypcap                1.1.2+debian-1                        
object-oriented Python interface for libpcap


Does anybody knows what happend?
How Can I resolve thsi problem?

I hope somebody help me please....

thanks so much

regards
Armin Garcia

Original issue reported on code.google.com by [email protected] on 9 Mar 2009 at 5:15

timeout_ms less than 1 second is not supported

What steps will reproduce the problem?
1. Set timeout_ms to less than 1 second
2. Run a capture on an interface with no traffic
3. Record the timings of the returned calls

This is pypcap 1.1 from svn (revision 102).

I traced the bug to the following line in pcap_ex.c:
#else
    static u_char *__pkt;
    static struct pcap_pkthdr __hdr;
    struct timeval tv = { 1, 0 };
    fd_set rfds;
    int fd, n;

The timeval struct in the select call is set to 1 second timeout, regardless of 
the timeout_ms value passed in. I attached a patch that changes the struct to:
struct timeval tv = { 0, 1000 };
i.e. a timeout of 1 ms. Sub ms timeout probably doesn't make sense anyway.

I think that's the right way to resolve that, unless I missed something.

Original issue reported on code.google.com by [email protected] on 2 Mar 2012 at 9:52

Attachments:

setup should also check for libpcap.so



What version of the product are you using? On what operating system?

Setup failed to build on our linux system from source, with a "can't find 
pcap" error.


The following change to setup fixed the building problem:

                        for lib in (('pcap', 'libpcap.a'),
                                    ('pcap', 'libpcap.dylib'),
                                    ('pcap', 'libpcap.so'),
                                    ('wpcap', 'wpcap.lib')):

Original issue reported on code.google.com by [email protected] on 20 Apr 2009 at 3:36

libpcap thread safety with pythoncom

I've encountered a thread safety problem with pcap after importing the
pythoncom module in a separate thread. The code below exemplifies this
behavior. Here, the Debug Thread is locked in the pcap.pcap method, so you
never see the "PCap call successful" printout. On the other hand, if the
pythoncom module is imported in the Debug Thread (uncomment the import
statement at line 14 and comment out line 2), the code executes with no
problem. Anyone have any ideas?

Im currently running:
python 2.5.2
pcap-1.1.win32-py2.5
pywin32-210.win32-py2.5
WinPcap 4.0.2


-------------------------------------
import pcap
import pythoncom
import threading
import imp

def main():
t = threading.Thread(name="Debug Thread", target=_launchpcap)
t.start()
t.join()
print "Debug Thread complete!"

def _launchpcap():
print "Debug Thread starting..."
ins = pcap.pcap(name="eth1", snaplen=1600, promisc=1, timeout_ms=500)
print "PCap call successful!"


if __name__ == "__main__":
main()

Original issue reported on code.google.com by [email protected] on 7 May 2009 at 4:27

Can't import pcap because Symbol not found: _bpf_filter

What steps will reproduce the problem?
1. import pcap
2.
3.

What is the expected output? What do you see instead?
Return to the REPL

What version of the product are you using? On what operating system?
Python 2.6, Snow Leopard

Please provide any additional information below.
When I import pcap:
>>> import pcap
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(./pcap.so, 2): Symbol not found: _bpf_filter
  Referenced from: /Library/Python/2.6/site-packages/pcap.so
  Expected in: flat namespace
 in /Library/Python/2.6/site-packages/pcap.so


Original issue reported on code.google.com by [email protected] on 19 Dec 2009 at 8:34

  • Merged into: #13

error: no suitable device found

Hi,
I am trying to do live capturing of packets but i am getting the error:
  pc = pcap.pcap()     # construct pcap object
  File "pcap.pyx", line 189, in pcap.pcap.__init__ (pcap.c:1689)
  OSError: no suitable device found

I think i have to set the network device
how can i do it???

Thanks,
itay

Original issue reported on code.google.com by [email protected] on 25 Apr 2015 at 12:58

run-time error

>>> import pcap
Traceback (most recent call last):
    File "<stdin>", line 1 in ?
ImportError: /usr/lib64/python2.4/site-packages/pcap.so: undefined symbol:
pcap_dispatch

I'm using pypcap 1.1 and made the changes from issues 14 and 22 so it would
build on a 64-bit setup.



Original issue reported on code.google.com by [email protected] on 20 Oct 2009 at 6:22

Pypcap on Mac OS X and Python 2.7

How to install Pypcap under mac os x and python 2.7? When I run python setup.py 
install I got the following error:
llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common 
-fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG 
-Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall 
-Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe 
-I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c 
pcap_ex.c -o build/temp.macosx-10.7-intel-2.7/pcap_ex.o
pcap_ex.c: In function ‘pcap_ex_fileno’:
pcap_ex.c:165: error: dereferencing pointer to incomplete type
pcap_ex.c: In function ‘pcap_ex_next’:
pcap_ex.c:253: error: dereferencing pointer to incomplete type
pcap_ex.c: In function ‘pcap_ex_fileno’:
pcap_ex.c:165: error: dereferencing pointer to incomplete type
pcap_ex.c: In function ‘pcap_ex_next’:
pcap_ex.c:253: error: dereferencing pointer to incomplete type
lipo: can't open input file: /var/tmp//ccv9vsmB.out (No such file or directory)
error: command 'llvm-gcc-4.2' failed with exit status 1

Original issue reported on code.google.com by [email protected] on 11 May 2012 at 9:28

The pcap.pcap() will blocked when it run in thread with twisted and wxPython

import threading
import pcap

import wx
from twisted.internet import wxreactor
wxreactor.install()
from twisted.internet import reactor

def run():
    import pcap
    p = pcap.pcap() # we blocked here!
    print 'Created pcap'
    for ts, package in p:
        print ts, len(package)

reactor.callInThread(run)
reactor.run()

This piece of code reproduce the problem. 

Original issue reported on code.google.com by [email protected] on 28 May 2009 at 5:34

"couldn't find pcap build or installation directory"

I have installed python-pyrex and libpcap-dev.
I have tried running "make" and "sudo python setup.py config".
I keep getting the following error while trying to install pypcap1.1:
"""
make
python setup.py config 
running config
Traceback (most recent call last):
  File "setup.py", line 101, in <module>
    ext_modules = [ pcap ])
  File "/usr/lib/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "setup.py", line 67, in run
    cPickle.dump(self._pcap_config([ self.with_pcap ]),
  File "setup.py", line 63, in _pcap_config
    raise "couldn't find pcap build or installation directory"
TypeError: exceptions must be old-style classes or derived from BaseException, 
not str
make: *** [all] Error 1
"""

I am trying to install pypcap1.1 using python 2.7.2 and Ubuntu 11.10.

Original issue reported on code.google.com by [email protected] on 17 May 2012 at 2:30

readpkts will return the data occupy the same memory address

What steps will reproduce the problem?
1. prepare a capture packet,the pkt in file more than one.
2. p=pcap.pcap(file);pkts=readpkts();print(pkts)
3. you will find the each of pkts buffer ptr point to the same address

What is the expected output? What do you see instead?
expect all the pkts buffer is not the same.but got the result as this:
[(1276937965.531224, <read-only buffer ptr 0x00F7004A, size 81 at 0x00C94E20>),
(1276937972.8316729, <read-only buffer ptr 0x00F7004A, size 124 at 0x00C94F20>),
 (1276937973.2153289, <read-only buffer ptr 0x00F7004A, size 122 at 0x00C94F40>)
, (1276937973.2716949, <read-only buffer ptr 0x00F7004A, size 118 at 0x00C94F60>
), (1276937973.3154581, <read-only buffer ptr 0x00F7004A, size 155 at 0x00C94F80
>), (1276937973.3189869, <read-only buffer ptr 0x00F7004A, size 163 at 0x00C94FA
0>), (1276937973.331707, <read-only buffer ptr 0x00F7004A, size 143 at 0x00C94FC
0>), (1276937973.333725, <read-only buffer ptr 0x00F7004A, size 113 at 0x00C94FE
0>), (1276937973.3350179, <read-only buffer ptr 0x00F7004A, size 120 at 0x00C990
20>), (1276937973.338382, <read-only buffer ptr 0x00F7004A, size 123 at 0x00C990
40>)]

What version of the product are you using? On what operating system?
python 2.6 and the lastest pypcap

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 21 Jun 2010 at 3:31

No pypcap binaries for python 2.6

There is no pycapc windows binaries for python 2.6

I tried to compile it myself : look like winpcap sources are needed
I tried to compile winpcap myself : look like Windows "driver SDK" is needed
For what I remember, "driver SDK" is not free, and I not willing to use it
illegally nor buy it.

Original issue reported on code.google.com by [email protected] on 31 Dec 2008 at 10:19

Exception errors with python 2.5

What steps will reproduce the problem?

1. Build pypcap-1.1 from source using Ubuntu and python 2.5

$ sudo python setup.py config
$ sudo pyhton setup.py build
$ sudo python setup.py install

2. Do anything that generates an exception

I've had the same issues building from source on OS X using MacPython 2.5,
but the .dmg on this site works fine so I assume this a build issue somehow.

What is the expected output? What do you see instead?

ubuntu-vm:~ 640: uname -a                  
Linux ubuntu-vm 2.6.20-15-generic #2 SMP Sun Apr 15 07:36:31 UTC 2007 i686
GNU/Linux

ubnntu-vm:~/honeynet/test_data 645: python                                

Python 2.5.1c1 (release25-maint, Apr 12 2007, 21:00:25) 
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pcap
>>> p = pcap.pcap("not a file")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pcap.pyx", line 180, in pcap.pcap.__init__
TypeError: exceptions must be strings, classes, or instances, not type
>>> p = pcap.pcap("pcap.20050922")
>>> count = 0
>>> for ts, buf in p:
...     count += 1
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pcap.pyx", line 346, in pcap.pcap.__next__
TypeError: exceptions must be strings, classes, or instances, not type
>>> 


What version of the product are you using? On what operating system?

1.1 on OS X and Ubuntu 7. Python 2.5 (as above) with pyrexc 0.9.4.1

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 21 Apr 2007 at 2:43

2.5 dmg not installable on Leoopard (10.5.2)

What steps will reproduce the problem?
1. install pypcap-1.1-fat.dmg on Leopard 10.5.2
2. when the installer reaches the "Select A Destination" screen it will say the 
System Python 2.5 is 
required.
3.

What is the expected output? What do you see instead?
I expect the installation to complete, but it fails.


What version of the product are you using? On what operating system?
OSX Leopard 10.5.2; System Python 2.5.1.


Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 31 Mar 2008 at 1:04

how to use pcap module

i use pcap and dpkt module to capture http packets and analysis it,but i don't 
known how to use the pcap module.
1. what is setfilter()  return 
2. how to set a BPF argument
3. what is pcap.pcap() return,is it iterateble
4.is there document about how to use pypcap module

code:
>>> import dpkt, pcap
>>> pc = pcap.pcap()
>>> pc.setfilter(‘icmp’)
>>> for ts, pkt in pc:
…     print `dpkt.ethernet.Ethernet(pkt)`
…

Original issue reported on code.google.com by [email protected] on 18 Mar 2011 at 12:58

No pypcap binaries for python 3.0

There is no pycapc windows binaries for python 3.0

I tried to compile it myself : look like winpcap sources are needed
I tried to compile winpcap myself : look like Windows "driver SDK" is needed
For what I remember, "driver SDK" is not free, and I not willing to use it
illegally nor buy it.

(same as Issue 11, but different issue because python 2.6 probably only
need just a new compilation/packaging, while python may require some changes)

Original issue reported on code.google.com by [email protected] on 31 Dec 2008 at 10:21

is dumping packets to a file supported ?

I'm trying to write out some packets read from a .pcap file
into a new file.

It's not clear to me how to do this. The relevant part of the help text for 
pcap.pcap I see is:

 |  name      -- name of a network interface or dumpfile to open,
 |               or None to open the first available up interface
 |  snaplen   -- maximum number of bytes to capture for each packet
 |  promisc   -- boolean to specify promiscuous mode sniffing
 |  immediate -- disable buffering, if possible
 |  dumpfile  -- name of a dumpfile to open, if necessary
 |  dumptype  -- only open a dumpfile and specify its type

but unfortunately, it does not specify what value should be passed to the 
dumptype argument.

I tried:

  pcout = pcap.pcap(dumpfile="out.pcap")

and I got:

  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "pcap.pyx", line 194, in pcap.pcap.__init__
  OSError: no suitable device found

which looks to me like it's trying to open a network device for live capture.
I also tried:

  pcout = pcap.pcap(dumpfile="out.pcap", dumptype="pcap")

which gives:

  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "pcap.pyx", line 188, in pcap.pcap.__init__
  OSError: Internal error pcap_open_dead.

Looking through 
http://code.google.com/p/pypcap/source/browse/tags/PYPCAP_1_1/pcap.pyx I don't 
see any occurrences of pcap_dump_open() so I'm wondering whether dumping of 
packets to a file is actually implemented.

What version of the product are you using? On what operating system?

  pypcap 1.1.2+debian-2ubuntu1, Ubuntu 10.04

Original issue reported on code.google.com by [email protected] on 10 Feb 2011 at 10:16

Errot message: "TypeError: raise: exception class must be a subclass of BaseException " raised while executing test.py

What steps will reproduce the problem?
1. After I complete installing the package, 
2. and run the test script (test.py) attached within the installed directory. 
3. The error message:TypeError: raise: exception class must be a subclass of 
BaseException, occurs while running test phase: test_pcap_dispatch

What is the expected output? What do you see instead?
Expected output: No error message
What I have seen: TypeError: raise: exception class must be a subclass of 
BaseException "


What version of the product are you using? On what operating system?
1. pypcap 1.1
2. python 2.6.5 (on Ubuntu 10.4 with 64bit)
3. Recompile pcap.c with pyrex 0.9.9

Thanks for the help,
Best,
David Chiu


Original issue reported on code.google.com by [email protected] on 11 Dec 2011 at 5:42

Thread safety problem in pcap_ex_next()

What steps will reproduce the problem?
1. Use pypcap in a multi-threaded scenario, with each thread using a 
   separate pcap instance.
2. In each thread, read packets via pcap.next(), in parallel.

What is the expected output? What do you see instead?

Expected output is normal packet retrieval. Instead, one sees occasional
packet truncation (e.g., caplen 46, IP hlen indicating full 1500B). The
cause for this is the additional static pcap_pkthdr variable in pcap_ex_next
and the fact that the hdr variable in __next__ points to it, as races may
not reflect the right content at the time it is accessed.

I'm attaching a patch that fixes the problem for me. It removes the
static variable, thus restoring pcap's "caller owns value" semantics in 
this particular case.

What version of the product are you using? On what operating system?

SVN trunk, Linux 2.6.

Original issue reported on code.google.com by [email protected] on 2 Feb 2011 at 9:26

Attachments:

comilation commands

What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?


What version of the product are you using? On what operating system?


Please provide any additional information below.



using this lib compli compilation it

comilation commands 

cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG 
-IF:\winpython27\python-2.7.5.amd64\include 
-IF:\winpython27\python-2.7.5.amd64\PC /Tcpcap_ex.c 
/Fobuild\temp.win-amd64-2.7\Release\pcap_ex.obj


link.exe /DLL /nologo /INCREMENTAL:NO 
/LIBPATH:F:\winpython27\python-2.7.5.amd64\libs 
/LIBPATH:F:\winpython27\python-2.7.5.amd64\PCbuild\amd64 
/LIBPATH:F:\winpython27\my_lib\WpdPack\Lib\x64 /EXPORT:initpcap 
build\temp.win-amd64-2.7\Release\pcap.obj 
build\temp.win-amd64-2.7\Release\pcap_ex.obj 
/OUT:build\lib.win-amd64-2.7\pcap.pyd 
/IMPLIB:build\temp.win-amd64-2.7\Release\pcap.lib 
/MANIFESTFILE:build\temp.win-amd64-2.7\Release\pcap.pyd.manifest
 /DYNAMICBASE "wpcap.lib" "ws2_32.lib" "kernel32.lib" "user32.lib" "Packet.lib" "Iphlpapi.lib"

Original issue reported on code.google.com by [email protected] on 11 Nov 2013 at 5:53

Attachments:

Installing on Win7 64-bit gives 'undefined reference to `__imp_Py_InitModule4'

What steps will reproduce the problem?
1. Download the latest svn code. In setup.py replace:
'for sd in ('include/pcap', 'include', ''):'
with
'for sd in ('include', 'include/pcap', ''):'
so that it finds the right pcap.h in wpdpack
2. Follow the installation guide in Issue 28
3. mingw32-make gives an error ld.exe: cannot find -lwpcap
4. Move 'Packet.lib' and 'wpcap.lib' from wpdpack\Lib\x64 to wpdpack\Lib
5. Running mingw32-make again, gives the error 'undefined reference to 
__imp_Py_InitModule4'

What is the expected output? What do you see instead?
Running 'make' and 'make install' should create a pcap.pyd file in the 
Python26\Lib\site-packages directory, but I 'make' gives an error.

What version of the product are you using? On what operating system?
I am using the latest code from svn on Windows 7 64-bit

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 12 Jan 2011 at 4:59

setup.py doesn't work on x86_64

1. python setup.py config
2. failed to create config.h

CentOS 5.3, python 2.4.3, pypcap-1.1

modify setup.py at line 49:

-                    for sd in ('lib', ''):
+                    for sd in ('lib64','lib', ''):

Original issue reported on code.google.com by [email protected] on 15 Oct 2009 at 3:10

Can't install: AttributeError: 'NoneType' object has no attribute 'rfind'

$ sudo pip install pypcap
Downloading/unpacking pypcap
  Downloading pypcap-1.1.4.tar.gz (41kB): 41kB downloaded
  Running setup.py (path:/tmp/user/0/pip_build_root/pypcap/setup.py) egg_info for package pypcap
    Found pcap headers in /usr/src/linux-headers-3.16.0-43-generic/include/config/touchscreen/pcap.h
    Found libraries in None
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/user/0/pip_build_root/pypcap/setup.py", line 60, in <module>
        lib_file = os.path.basename(lib_file_path)
      File "/usr/lib/python2.7/posixpath.py", line 121, in basename
        i = p.rfind('/') + 1
    AttributeError: 'NoneType' object has no attribute 'rfind'
    Complete output from command python setup.py egg_info:
    Found pcap headers in /usr/src/linux-headers-3.16.0-43-generic/include/config/touchscreen/pcap.h

Found libraries in None

Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/tmp/user/0/pip_build_root/pypcap/setup.py", line 60, in <module>

    lib_file = os.path.basename(lib_file_path)

  File "/usr/lib/python2.7/posixpath.py", line 121, in basename

    i = p.rfind('/') + 1

AttributeError: 'NoneType' object has no attribute 'rfind'

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/user/0/pip_build_root/pypcap
Storing debug log for failure in /home/<redacted>/.pip/pip.log

/home//.pip/pip.log

------------------------------------------------------------
/usr/bin/pip run on Fri Oct 30 20:53:28 2015
Downloading/unpacking pypcap
  Getting page https://pypi.python.org/simple/pypcap/
  URLs to search for versions for pypcap:
  * https://pypi.python.org/simple/pypcap/
  Analyzing links from page https://pypi.python.org/simple/pypcap/
    Skipping https://pypi.python.org/packages/2.7/p/pypcap/pypcap-1.1.4-cp27-none-macosx_10_10_x86_64.whl#md5=ca7a6a3956f332a29666682ad3996001 (from https://pypi.python.org/simple/pypcap/) because it is not compatible with this Python
    Found link https://pypi.python.org/packages/source/p/pypcap/pypcap-1.1.1.tar.gz#md5=d32f422feba022dad219edb1e7de0366 (from https://pypi.python.org/simple/pypcap/), version: 1.1.1
    Found link https://pypi.python.org/packages/source/p/pypcap/pypcap-1.1.2.tar.gz#md5=c11ecfd60152ee1039cbc59f537d84ce (from https://pypi.python.org/simple/pypcap/), version: 1.1.2
    Found link https://pypi.python.org/packages/source/p/pypcap/pypcap-1.1.3.tar.gz#md5=b1c43d8959123c2d4fa8a1531e0d61ca (from https://pypi.python.org/simple/pypcap/), version: 1.1.3
    Found link https://pypi.python.org/packages/source/p/pypcap/pypcap-1.1.4.tar.gz#md5=e2ded33e75d94e4635798a2b2f4aaea1 (from https://pypi.python.org/simple/pypcap/), version: 1.1.4
    Found link https://pypi.python.org/packages/source/p/pypcap/pypcap-1.1.tar.gz#md5=d42e03b9cc322b1d3f39847752368f0d (from https://pypi.python.org/simple/pypcap/), version: 1.1
  Using version 1.1.4 (newest of versions: 1.1.4, 1.1.3, 1.1.2, 1.1.1, 1.1)
  Downloading from URL https://pypi.python.org/packages/source/p/pypcap/pypcap-1.1.4.tar.gz#md5=e2ded33e75d94e4635798a2b2f4aaea1 (from https://pypi.python.org/simple/pypcap/)
  Running setup.py (path:/tmp/user/0/pip_build_root/pypcap/setup.py) egg_info for package pypcap
    Found pcap headers in /usr/src/linux-headers-3.16.0-43-generic/include/config/touchscreen/pcap.h
    Found libraries in None
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/user/0/pip_build_root/pypcap/setup.py", line 60, in <module>
        lib_file = os.path.basename(lib_file_path)
      File "/usr/lib/python2.7/posixpath.py", line 121, in basename
        i = p.rfind('/') + 1
    AttributeError: 'NoneType' object has no attribute 'rfind'
    Complete output from command python setup.py egg_info:
    Found pcap headers in /usr/src/linux-headers-3.16.0-43-generic/include/config/touchscreen/pcap.h

Found libraries in None

Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/tmp/user/0/pip_build_root/pypcap/setup.py", line 60, in <module>

    lib_file = os.path.basename(lib_file_path)

  File "/usr/lib/python2.7/posixpath.py", line 121, in basename

    i = p.rfind('/') + 1

AttributeError: 'NoneType' object has no attribute 'rfind'

----------------------------------------
Cleaning up...
  Removing temporary dir /tmp/user/0/pip_build_root...
Command python setup.py egg_info failed with error code 1 in /tmp/user/0/pip_build_root/pypcap
Exception information:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1230, in prepare_files
    req_to_install.run_egg_info()
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 326, in run_egg_info
    command_desc='python setup.py egg_info')
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 326, in run_egg_info
    command_desc='python setup.py egg_info')
  File "/usr/lib/python2.7/dist-packages/pip/util.py", line 715, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command python setup.py egg_info failed with error code 1 in /tmp/user/0/pip_build_root/pypcap

Move pypcap to github

I have created a copy pypcap on github at this address: 
https://github.com/hellais/pypcap.

I did some refactoring of the setup.py script and made sure that it will find 
the libraries and headers on 64 and 32 bit ubuntu, fedora and OSX 10.7, 10.8.

I have not tested it with other distributions, but it should solve some of the 
issues encountered by people in ticket: 
http://code.google.com/p/pypcap/issues/detail?id=39, 
http://code.google.com/p/pypcap/issues/detail?id=38, 
http://code.google.com/p/pypcap/issues/detail?id=27, 
http://code.google.com/p/pypcap/issues/detail?id=39.

Feedback and community involvement would be appreciated :)

Original issue reported on code.google.com by [email protected] on 9 Dec 2012 at 12:45

immediate = True is ignored

What steps will reproduce the problem?

1. Execute the following testcase while causing network traffic (for example 
with "ping 8.8.8.8"):

#!/usr/bin/python2
# coding=utf-8

import pcap

capture = pcap.pcap('eth0', 1, True, 5000, True)
while True:
    print(capture.next())


What is the expected output? What do you see instead?

capture.next() does only return every 5 seconds but with immediate = True it 
should return every time network traffic is created. The same happens also if 
capture.readpkts() is used instead but I'm not sure if this is maybe intended 
there.


What version of the product are you using? On what operating system?

Operating system: Linux 3.16.3
pypcap: 1.1.2


Please provide any additional information below.

Trying to reproduce this with libpcap in C works as expected (to go sure that 
for example the immediate mode is supported on the system).

Original issue reported on code.google.com by [email protected] on 2 Oct 2014 at 7:13

support findalldevs()

this patch adds support for findalldevs() function.

tested on Linux, WindowsXP, MacOSX

There is one problem under windows.
there is no classic interefaces names under windows and this patch returns
what it gets from the OS (long names blabla). it's not a big deal but
lookupdev() returns ethX names. these ethX names are fake and don't know if
i should to do the same for findalldevs().

Original issue reported on code.google.com by [email protected] on 7 Jul 2009 at 1:06

Attachments:

No timeout in pcap.next(), setnonblock() not working correctly

pcap.pcap.__init__() has an undocumented parameter "timeout_ms=500" which
is passed to WinPcap. WinPcap's pcap_next_ex() function returns after this
time (in milliseconds) if no packets were received. The return code is 0 in
this case. But in our pcap.__next__() method, we do not deal with this
return code but just continue listening. This leads to problems, for
example with non-blocking I/O.

Example:
I want to stop receiving packets when a given timeout (e.g. an inter-packet
interval) has been reached. Moreover the user should be able to interrupt
at any time with Ctrl-C.

-- test.py --
import pcap, time
pc = pcap.pcap()
interval = 2
while True:
    start = time.time()
    print "Waiting for next packet..."
    ts, pkt = pc.next()
    end = time.time()
    print "Packet received: %s (%s) %r " % (ts, end - start, pkt)
    if end - start > interval:
        print "Max inter-packet interval reached. Quitting."
        break
--------------

Run test.py on an empty LAN. The program prints "Waiting for next
packet..." and blocks in pc.next() until a packet is received (which can be
long after the supposed interval has elapsed). Ctrl-C has no effect either
before the next packet is received.

And inserting pc.setnonblock(True) in order to switch to non-blocking I/O
mode doesn't change anything.

My config:
pypcap 1.1 on Windows XP SP2, WinPcap 4.0.1 (packet.dll 4.0.0.901), Python 2.5 

Suggested patch: see attachment

The important part are the last two changes: If pcap_ex_next() hasn't
received any packets before the timeout (n==0) we just return None to the
caller (together with a timestamp). The rest is only for compatibility: If
a user explicitly specifies a timeout, he now must take into account that
.next() will return None if no packets were received. If he doesn't specify
a timeout, everything is like before and .next() will wait forever for new
packets. 

Regards,
Dirk

Original issue reported on code.google.com by [email protected] on 18 Sep 2007 at 5:17

Attachments:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.