Ticket #328 (assigned enhancement)

Opened 15 months ago

Last modified 3 weeks ago

improvements for pypcap wrapper

Reported by: getxsick Owned by: kosma
Priority: medium Milestone: UMPA 0.5
Component: UMPA Version: current svn
Keywords: Cc: luis, ignotus

Description

wrapper pypcap doesn't support findalldevs() this support should be added (the wrapper is written partialy in pyrex)

anyway, the way how e.g. scapy works with findalldevs() is obscure, it just check interfaces in /proc and it doesn't have anything with libpcap. this way is wrong.

Attachments

pcap_findalldevs.patch (1.1 kB) - added by getxsick 14 months ago.
pcap_lookupnet.diff (1.8 kB) - added by ignotus 14 months ago.
pcap_loop__cnt.patch (1.5 kB) - added by getxsick 14 months ago.
support CNT for pcap_loop()
pcap_dump2.patch (3.3 kB) - added by getxsick 14 months ago.
dump support - different idea (more OO)
pcap_dump1.patch (3.3 kB) - added by getxsick 14 months ago.
current using patch for dumping
pcap_dump3.patch (3.9 kB) - added by getxsick 14 months ago.
with dump class
README (1.0 kB) - added by getxsick 12 months ago.
this is a README which we include for our modified binaries of pypcap
pcap_timeout.patch (460 bytes) - added by getxsick 10 months ago.
fixation for a timeout bug
patch_pack.diff (6.6 kB) - added by getxsick 10 months ago.
it contains all patches (pcap_findalldevs.patch, pcap_lookupnet.diff, pcap_loopcnt.patch, pcap_dump3.patch, pcap_timeout.patch)
sendpacket.patch (1.0 kB) - added by kosma 5 weeks ago.
add bindings for pcap_sendpacket() function

Change History

Changed 14 months ago by getxsick

  Changed 14 months ago by getxsick

Not tested under Windows.

Changed 14 months ago by ignotus

  Changed 14 months ago by ignotus

Also added support to pcap_lookupnet(). That can be used with pcap_findalldevs() to choose the correct interface to sniff.

  Changed 14 months ago by getxsick

  • summary changed from findalldevs() support for pypcap to improvements for pypcap wrapper

I'm changing summary to be more general about pypcap wrapper.

ignotus: please reedit your patch. it should be seperated from pcap_findalldevs.patch

Changed 14 months ago by getxsick

support CNT for pcap_loop()

follow-up: ↓ 5   Changed 14 months ago by getxsick

  • cc luis added

I attached 2 patches for dump supporting. Both of them work in the same way (internally). But API is different. First one is more like C pypcap, second one is more OO but still I'm not sure if it's optimal. Maybe I should use second one but add these functions as dump_open() and dump_close() anyway?

Because now, to use dump feature we have to pass a file path to pcap constructor. There is no other way to create dump file later. <--this is for 2nd patch.

Propably the solution is trivial, but it's 3:40am and hmmm I'm not sure now.

in reply to: ↑ 4   Changed 14 months ago by getxsick

Replying to getxsick:

Because now, to use dump feature we have to pass a file path to pcap constructor. There is no other way to create dump file later. <--this is for 2nd patch. Propably the solution is trivial, but it's 3:40am and hmmm I'm not sure now.

But hey, it's the same as with an interface. We pass it to the consructor and can't change later. Hmm it's not a big deal to leave it as it is. Unless someone would like to use 2 different files for the same sniffing. But why?

  Changed 14 months ago by getxsick

And another question is...should we flush buffer to save it to the disk during dump() call or leave it?

Changed 14 months ago by getxsick

dump support - different idea (more OO)

follow-up: ↓ 8   Changed 14 months ago by luis


I attached 2 patches for dump supporting. Both of them work in the same way (internally). But API is different. First one is more like C pypcap, second one is more OO but still I'm not sure if it's optimal. Maybe I should use second one but add these functions as dump_open() and dump_close() anyway?

Because now, to use dump feature we have to pass a file path to pcap constructor. There is no other way to create dump file later. <--this is for 2nd patch.

Propably the solution is trivial, but it's 3:40am and hmmm I'm not sure now.

You're changing a wrapper, then you need to keep consistency with already exists. Support both can be misunderstood API.

But hey, it's the same as with an interface. We pass it to the consructor and can't change later. Hmm it's not a big deal to leave it as it is. Unless someone would like to use 2 different files for the same sniffing. But why? 

Could have a method set_file or something like that, OOP approach?

And another question is...should we flush buffer to save it to the disk during dump() call or leave it?
pcap_dump(self.__dump, self.__hdr, self.__pkt) 
# should we call pcap_flush() here? 

After dump it should be written on disk. Chunk it from buffer seems good idea.

in reply to: ↑ 7 ; follow-up: ↓ 9   Changed 14 months ago by getxsick

Replying to luis:

Could have a method set_file or something like that, OOP approach?

method set_file() instead of dump_open()? the name dump_open() is from libpcap directly...

anyway, you mean that you don't like the idea of 2nd patch? where we can pass path to a file in constructor? why?

After dump it should be written on disk. Chunk it from buffer seems good idea.

Please remember, that it's usual in common operating systems and other functions. that's why people involve buffers to avoid a situation to using IO too often (which is a bottleneck in general). of course flush it all the time after another calling of dump() has a nice effect but i'm not sure if we should follow this way.

Hmmm maybe I could write a special Dump class which all methods like flush(), open(), close(), dump() ?

in reply to: ↑ 8 ; follow-up: ↓ 10   Changed 14 months ago by luis

Replying to getxsick:

Replying to luis:

Could have a method set_file or something like that, OOP approach?

method set_file() instead of dump_open()? the name dump_open() is from libpcap directly... anyway, you mean that you don't like the idea of 2nd patch? where we can pass path to a file in constructor? why?

No. I prefer 2nd patch. And I suggested adding a new method to set_file if is necessary.

After dump it should be written on disk. Chunk it from buffer seems good idea.

Please remember, that it's usual in common operating systems and other functions. that's why people involve buffers to avoid a situation to using IO too often (which is a bottleneck in general). of course flush it all the time after another calling of dump() has a nice effect but i'm not sure if we should follow this way.

shame on me. :) I get it wrong. flush for each packet is not good.

Hmmm maybe I could write a special Dump class which all methods like flush(), open(), close(), dump() ?

Yeah. It sounds better. It is in the direction of 2nd patch.

in reply to: ↑ 9 ; follow-up: ↓ 11   Changed 14 months ago by getxsick

Replying to luis:

No. I prefer 2nd patch. And I suggested adding a new method to set_file if is necessary.

OK...but then we have 2 functions instead of 1. and still more corner cases like "what if someone want to stop dumping in the middle of time?" then add another method like dump_finish()? i think we have to solutions:

  1. keep it simple as 2nd patch is. we can pass a name to the constructor and get dumping. that's all
  2. create a Dumper class which can have as many methods related to dumping as we want

Hmmm maybe I could write a special Dump class which all methods like flush(), open(), close(), dump() ?

Yeah. It sounds better. It is in the direction of 2nd patch.

But where to keep the object? I mean should we have an access to this class straight from pcap module? so user has to carry about it by hisself or pack it into pcap class and make closer relation to pcap object?

in reply to: ↑ 10   Changed 14 months ago by luis

Replying to getxsick:

Replying to luis:

No. I prefer 2nd patch. And I suggested adding a new method to set_file if is necessary.

OK...but then we have 2 functions instead of 1. and still more corner cases like "what if someone want to stop dumping in the middle of time?" then add another method like dump_finish()? i think we have to solutions: 1. keep it simple as 2nd patch is. we can pass a name to the constructor and get dumping. that's all 2. create a Dumper class which can have as many methods related to dumping as we want

Hmmm maybe I could write a special Dump class which all methods like flush(), open(), close(), dump() ?

Yeah. It sounds better. It is in the direction of 2nd patch.

But where to keep the object? I mean should we have an access to this class straight from pcap module? so user has to carry about it by hisself or pack it into pcap class and make closer relation to pcap object?

Regarding the API proposed by you in IRC:

import pcap

p = pcap.pcap("any")
p.dump.open("/tmp/x.cap")
p.next()
p.dump.dump()
p.dump.flush()
p.dump.close()

pcap.dump is create in pcap.pcap, right?

p = pcap.pcap("any")
d = pcap.dump
d.open("/tmp/x.cap")
p.next()
d.dump()
d.flush()
d.close()

if we look this way it looks more beaty.

What do you think?

follow-up: ↓ 13   Changed 14 months ago by getxsick

Firstly, I don't think that "beaty" is the most important thing. Anyway, as I said, I don't know. Both solutions have some pros and cons. I would like to hear ignotus opinion here.

in reply to: ↑ 12   Changed 14 months ago by luis

  • cc ignotus added

Replying to getxsick:

Firstly, I don't think that "beaty" is the most important thing. Anyway, as I said, I don't know. Both solutions have some pros and cons. I would like to hear ignotus opinion here.

It is a design issue. What counts is the quality of API, and what API does.

Changed 14 months ago by getxsick

current using patch for dumping

Changed 14 months ago by getxsick

with dump class

  Changed 13 months ago by getxsick

  Changed 13 months ago by getxsick

  Changed 12 months ago by getxsick

  • status changed from new to closed
  • resolution set to fixed

I'm closing this ticket.

For futher development issues please follow URLs listed above to code.google.com

For user issues, please read: http://trac.umitproject.org/wiki/UMPA/PypcapModified

Changed 12 months ago by getxsick

this is a README which we include for our modified binaries of pypcap

Changed 10 months ago by getxsick

fixation for a timeout bug

  Changed 10 months ago by getxsick

pcap_timeout.patch fix a bug for a timeout. so far the application never break so it looks like a freezing.

here is a code to reproduce a bug:

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

Changed 10 months ago by getxsick

it contains all patches (pcap_findalldevs.patch, pcap_lookupnet.diff, pcap_loopcnt.patch, pcap_dump3.patch, pcap_timeout.patch)

  Changed 10 months ago by getxsick

  • status changed from closed to reopened
  • resolution fixed deleted
  • milestone changed from UMPA 0.2 - sniffing to UMPA 0.3

  Changed 10 months ago by luis

the patch works fine.

I got yet the error compiling the pypcap:

$ make
(...)
pcap.c:1572: warning: pointer targets in passing argument 3 of ‘pcap_dump’ differ in signedness
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include -I/usr/include/python2.6 -c pcap_ex.c -o build/temp.linux-i686-2.6/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_compile_nopcap’:
pcap_ex.c:292: warning: implicit declaration of function ‘mktemp’
error: command 'gcc' failed with exit status 1
make: *** [all] Error 1

Proposed solution by Francesco (tested on Linux and Mac OS):

Index: pcap_ex.c
===================================================================
--- pcap_ex.c	(revision 85)
+++ pcap_ex.c	(working copy)
@@ -12,7 +12,7 @@
 # include <signal.h>
 # include <unistd.h>
 #endif
-
+#define HAVE_PCAP_FILE
 #include <pcap.h>
 #ifdef HAVE_PCAP_INT_H
 # include <pcap-int.h>

Probably it should also be included, on tarball?

  Changed 10 months ago by getxsick

this error during compilation depends on used operating system. it's worth to mention how to solve the issue but i dont know if it's correct solution to every system

  Changed 2 months ago by kosma

  • owner changed from getxsick to kosma
  • status changed from reopened to new

  Changed 2 months ago by kosma

  • status changed from new to assigned

  Changed 8 weeks ago by kosma

  • milestone changed from UMPA 0.3 - L2 to UMPA 0.5

Changed 5 weeks ago by kosma

add bindings for pcap_sendpacket() function

  Changed 5 weeks ago by kosma

Attached patch adds bindings for pcap_sendpacket() function. The libpcap API has a second one, pcap_inject(), which returns the number of bytes sent; however, it uses a size_t argument, and presently using this type under Pyrex is problematic and hard to get right.

  Changed 3 weeks ago by kosma

Gentlemen, we're in!

http://code.google.com/p/pypcap/people/list

Bartosz and me just got commit rights to the pypcap repository and we're going to merge the changes ASAP. Stay tuned.

Add/Change #328 (improvements for pypcap wrapper)

Author



Action
as assigned
 
Note: See TracTickets for help on using tickets.