<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[143789] trunk/dports/python</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="https://trac.macports.org/changeset/143789">143789</a></dd>
<dt>Author</dt> <dd>jmr@macports.org</dd>
<dt>Date</dt> <dd>2015-12-21 13:03:14 -0800 (Mon, 21 Dec 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>New port: py-pypcap, a simple python binding to libpcap (#28132)</pre>

<h3>Added Paths</h3>
<ul>
<li>trunk/dports/python/py-pypcap/</li>
<li><a href="#trunkdportspythonpypypcapPortfile">trunk/dports/python/py-pypcap/Portfile</a></li>
<li>trunk/dports/python/py-pypcap/files/</li>
<li><a href="#trunkdportspythonpypypcapfilespatchpcappyx">trunk/dports/python/py-pypcap/files/patch-pcap.pyx</a></li>
<li><a href="#trunkdportspythonpypypcapfilespatchsetuppydiff">trunk/dports/python/py-pypcap/files/patch-setup.py.diff</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkdportspythonpypypcapPortfile"></a>
<div class="addfile"><h4>Added: trunk/dports/python/py-pypcap/Portfile (0 => 143789)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/dports/python/py-pypcap/Portfile                                (rev 0)
+++ trunk/dports/python/py-pypcap/Portfile        2015-12-21 21:03:14 UTC (rev 143789)
</span><span class="lines">@@ -0,0 +1,40 @@
</span><ins>+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+PortSystem 1.0
+PortGroup python 1.0
+
+name                    py-pypcap
+version                 1.1
+categories-append       net
+license                 BSD
+maintainers             gmail.com:andrew.reusch openmaintainer
+description             python extension module for libpcap
+long_description        A simplified object-oriented Python extension module for libpcap
+platforms               darwin
+
+homepage                http://code.google.com/p/pypcap/
+master_sites            googlecode:pypcap
+distname                pypcap-${version}
+
+checksums               md5     034c3cbbfa81aa19e8f685b767c65764 \
+                        sha1    966f62deca16d5086e2ef6694b0c795f273da15c \
+                        rmd160  119dcc393d42678e6fa8f0b0f8b82536ab1efb13
+
+python.versions         27
+
+if {$subport ne $name} {
+    patchfiles         patch-setup.py.diff patch-pcap.pyx
+
+    pre-configure {
+        system -W ${worksrcpath} &quot;${python.prefix}/bin/pyrexc pcap.pyx&quot;
+    }
+
+    use_configure       yes
+    configure.cmd       ${python.bin} setup.py
+    configure.args      config
+    configure.pre_args
+    configure.post_args  --with-pcap=&quot;${prefix}&quot;
+
+    depends_build           port:py${python.version}-pyrex
+    depends_lib-append      port:libpcap
+}
</ins><span class="cx">Property changes on: trunk/dports/python/py-pypcap/Portfile
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnkeywords"></a>
<div class="addfile"><h4>Added: svn:keywords</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkdportspythonpypypcapfilespatchpcappyx"></a>
<div class="addfile"><h4>Added: trunk/dports/python/py-pypcap/files/patch-pcap.pyx (0 => 143789)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/dports/python/py-pypcap/files/patch-pcap.pyx                                (rev 0)
+++ trunk/dports/python/py-pypcap/files/patch-pcap.pyx        2015-12-21 21:03:14 UTC (rev 143789)
</span><span class="lines">@@ -0,0 +1,221 @@
</span><ins>+--- ./pcap.pyx.orig        2011-10-01 22:35:33.141146678 -0400
++++ ./pcap.pyx        2011-10-01 22:35:39.416147272 -0400
+@@ -1,7 +1,7 @@
+ #
+ # pcap.pyx
+ #
+-# $Id: pcap.pyx,v 1.20 2005/10/16 23:00:11 dugsong Exp $
++# $Id: pcap.pyx 101 2010-07-16 08:20:16Z kosma@kosma.pl $

+ &quot;&quot;&quot;packet capture library

+@@ -17,9 +17,11 @@
+ __version__ = '1.1'

+ import sys
++import struct

+ cdef extern from &quot;Python.h&quot;:
+     object PyBuffer_FromMemory(char *s, int len)
++    int    PyObject_AsCharBuffer(object obj, char **buffer, int *buffer_len)
+     int    PyGILState_Ensure()
+     void   PyGILState_Release(int gil)
+     void   Py_BEGIN_ALLOW_THREADS()
+@@ -42,6 +44,10 @@
+         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)

+@@ -62,6 +68,13 @@
+     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)
++    int     pcap_lookupnet(char *device,
++                           unsigned int *netp,
++                           unsigned int *maskp,
++                           char *errbuf)
++    int     pcap_sendpacket(pcap_t *p, char *buf, int size)

+ cdef extern from &quot;pcap_ex.h&quot;:
+     # XXX - hrr, sync with libdnet and libevent
+@@ -134,16 +147,18 @@
+             raise IOError, 'bad filter'
+     def filter(self, buf):
+         &quot;&quot;&quot;Return boolean match for buf against our filter.&quot;&quot;&quot;
++        cdef char *p
+         cdef int n
+-        n = len(buf)
+-        if bpf_filter(self.fcode.bf_insns, buf, n, n) == 0:
++        if PyObject_AsCharBuffer(buf, &amp;p, &amp;n) &lt; 0:
++            raise TypeError
++        if bpf_filter(self.fcode.bf_insns, p, n, n) == 0:
+             return False
+         return True
+     def __dealloc__(self):
+         pcap_freecode(&amp;self.fcode)
+             
+ cdef class pcap:
+-    &quot;&quot;&quot;pcap(name=None, snaplen=65535, promisc=True, immediate=False) -&gt; packet capture object
++    &quot;&quot;&quot;pcap(name=None, snaplen=65535, promisc=True, timeout_ms=None, immediate=False)  -&gt; packet capture object
+     
+     Open a handle to a packet capture descriptor.
+     
+@@ -152,6 +167,9 @@
+                  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
++    timeout_ms -- requests for the next packet will return None if the timeout
++                  (in milliseconds) is reached and no packets were received
++                  (Default: no timeout)  
+     immediate -- disable buffering, if possible
+     &quot;&quot;&quot;
+     cdef pcap_t *__pcap
+@@ -161,7 +179,7 @@
+     cdef int __dloff
+     
+     def __init__(self, name=None, snaplen=65535, promisc=True,
+-                 timeout_ms=500, immediate=False):
++                 timeout_ms=0, immediate=False):
+         global dltoff
+         cdef char *p
+         
+@@ -171,7 +189,7 @@
+                 raise OSError, self.__ebuf
+         else:
+             p = name
+-        
++            
+         self.__pcap = pcap_open_offline(p, self.__ebuf)
+         if not self.__pcap:
+             self.__pcap = pcap_open_live(pcap_ex_name(p), snaplen, promisc,
+@@ -184,7 +202,7 @@
+         try: self.__dloff = dltoff[pcap_datalink(self.__pcap)]
+         except KeyError: pass
+         if immediate and pcap_ex_immediate(self.__pcap) &lt; 0:
+-            raise OSError, &quot;couldn't set BPF immediate mode&quot;
++            raise OSError, &quot;couldn't enable immediate mode&quot;
+     
+     property name:
+         &quot;&quot;&quot;Network interface or dumpfile name.&quot;&quot;&quot;
+@@ -243,16 +261,6 @@
+         &quot;&quot;&quot;Return datalink type (DLT_* values).&quot;&quot;&quot;
+         return pcap_datalink(self.__pcap)
+     
+-    def next(self):
+-        &quot;&quot;&quot;Return the next (timestamp, packet) tuple, or None on error.&quot;&quot;&quot;
+-        cdef pcap_pkthdr hdr
+-        cdef char *pkt
+-        pkt = &lt;char *&gt;pcap_next(self.__pcap, &amp;hdr)
+-        if not pkt:
+-            return None
+-        return (hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0),
+-                PyBuffer_FromMemory(pkt, hdr.caplen))
+-
+     def __add_pkts(self, ts, pkt, pkts):
+         pkts.append((ts, pkt))
+     
+@@ -288,18 +296,24 @@
+             raise exc[0], exc[1], exc[2]
+         return n

+-    def loop(self, callback, *args):
+-        &quot;&quot;&quot;Loop forever, processing packets with a user callback.
+-        The loop can be exited with an exception, including KeyboardInterrupt.
++    def loop(self, cnt, callback, *args):
++        &quot;&quot;&quot;Processing packets with a user callback during a loop.
++        The loop can be exited when cnt value is reached
++        or with an exception, including KeyboardInterrupt.
+         
+         Arguments:

++        cnt      -- number of packets to process;
++                    0 or -1 to process all packets until an error occurs,
++                    EOF is reached;
+         callback -- function with (timestamp, pkt, *args) prototype
+         *args    -- optional arguments passed to callback on execution
+         &quot;&quot;&quot;
+         cdef pcap_pkthdr *hdr
+         cdef char *pkt
+         cdef int n
++        cdef int i
++        i = 1
+         pcap_ex_setup(self.__pcap)
+         while 1:
+             Py_BEGIN_ALLOW_THREADS
+@@ -308,10 +322,22 @@
+             if n == 1:
+                 callback(hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0),
+                          PyBuffer_FromMemory(pkt, hdr.caplen), *args)
++            elif n == 0:
++                break
+             elif n == -1:
+                 raise KeyboardInterrupt
+             elif n == -2:
+                 break
++            if i == cnt:
++                break
++            i = i + 1
++
++    def sendpacket(self, buf):
++        &quot;&quot;&quot;Send a raw network packet on the interface.&quot;&quot;&quot;
++        ret = pcap_sendpacket(self.__pcap, buf, len(buf))
++        if ret == -1:
++            raise OSError, pcap_geterr(self.__pcap)
++        return len(buf)
+     
+     def geterr(self):
+         &quot;&quot;&quot;Return the last error message associated with this handle.&quot;&quot;&quot;
+@@ -340,6 +366,8 @@
+             if n == 1:
+                 return (hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0),
+                         PyBuffer_FromMemory(pkt, hdr.caplen))
++            elif n == 0:
++                return None
+             elif n == -1:
+                 raise KeyboardInterrupt
+             elif n == -2:
+@@ -364,3 +392,36 @@
+         raise OSError, ebuf
+     return p

++def findalldevs():
++    &quot;&quot;&quot;Return a list of capture devices.&quot;&quot;&quot;
++    cdef pcap_if_t *devs, *curr
++    cdef char ebuf[256]
++
++    status = pcap_findalldevs(&amp;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
++
++def lookupnet(char *dev):
++    &quot;&quot;&quot;
++    Return the address and the netmask of a given device
++    as network-byteorder integers.
++    &quot;&quot;&quot;
++    cdef unsigned int netp
++    cdef unsigned int maskp
++    cdef char ebuf[256]
++
++    status = pcap_lookupnet(dev, &amp;netp, &amp;maskp, ebuf)
++    if status:
++        raise OSError(ebuf)
++    return struct.pack('I', netp), struct.pack('I', maskp)
</ins></span></pre></div>
<a id="trunkdportspythonpypypcapfilespatchsetuppydiff"></a>
<div class="addfile"><h4>Added: trunk/dports/python/py-pypcap/files/patch-setup.py.diff (0 => 143789)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/dports/python/py-pypcap/files/patch-setup.py.diff                                (rev 0)
+++ trunk/dports/python/py-pypcap/files/patch-setup.py.diff        2015-12-21 21:03:14 UTC (rev 143789)
</span><span class="lines">@@ -0,0 +1,20 @@
</span><ins>+--- setup.py.orig        2011-01-25 10:56:52.000000000 -0800
++++ setup.py        2011-01-25 11:19:36.000000000 -0800
+@@ -42,7 +42,7 @@
+             dirs = [ '/usr', sys.prefix ] + glob.glob('/opt/libpcap*') + \
+                    glob.glob('../libpcap*') + glob.glob('../wpdpack*')
+         for d in dirs:
+-            for sd in ('include', 'include/pcap', ''):
++            for sd in ('include/pcap', 'include', ''):
+                 incdirs = [ os.path.join(d, sd) ]
+                 if os.path.exists(os.path.join(d, sd, 'pcap.h')):
+                     cfg['include_dirs'] = [ os.path.join(d, sd) ]
+@@ -75,7 +75,7 @@
+             print &quot;removing '%s'&quot; % pcap_cache
+             os.unlink(pcap_cache)

+-if len(sys.argv) &gt; 1 and sys.argv[1] == 'build':
++if len(sys.argv) &gt; 1 and ('build' in sys.argv or 'install' in sys.argv):
+     try:
+         pcap_config = cPickle.load(open(pcap_cache))
+     except IOError:
</ins></span></pre>
</div>
</div>

</body>
</html>