Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include doc/* iptc/* libxtwrapper/* NOTICE README setup.py test.py
11 changes: 7 additions & 4 deletions iptc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import socket
import struct
import weakref
import ctypes.util

from xtables import XT_INV_PROTO, NFPROTO_IPV4, XTF_TRY_LOAD, XTablesError, xtables, xtables_globals, xt_align, xt_counters, xt_entry_target, xt_entry_match

Expand Down Expand Up @@ -76,7 +77,7 @@ class ipt_entry_match(xt_entry_match):

ipt_align = xt_align

_libiptc = ct.CDLL("libiptc.so.0", use_errno = True)
_libiptc = ct.CDLL(ctypes.util.find_library("iptc"), use_errno = True)

class iptc(object):
"""This class contains all libiptc API calls."""
Expand Down Expand Up @@ -229,11 +230,12 @@ class IPTCError(Exception):
executing an iptables operation.
"""

_libc = ct.CDLL("libc.so.6")
_libc = ct.CDLL(ctypes.util.find_library("c"))
_optind = ct.c_long.in_dll(_libc, "optind")
_optarg = ct.c_char_p.in_dll(_libc, "optarg")

_lib_xtwrapper = ct.CDLL('libxtwrapper.so')
from distutils.sysconfig import get_python_lib
_lib_xtwrapper = ct.CDLL(get_python_lib(1) + '/libxtwrapper.so')
#_lib_xtwrapper.use_errno = True
_wrap_parse = _lib_xtwrapper.wrap_parse
_wrap_save = _lib_xtwrapper.wrap_save
Expand Down Expand Up @@ -603,7 +605,8 @@ class Rule(object):
* One target. This determines what happens with the packet if it is
matched.
"""
protocols = { socket.IPPROTO_TCP: "tcp",
protocols = { 0: "all",
socket.IPPROTO_TCP: "tcp",
socket.IPPROTO_UDP: "udp",
socket.IPPROTO_ICMP: "icmp",
socket.IPPROTO_ESP: "esp",
Expand Down
2 changes: 1 addition & 1 deletion iptc/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

__pkgname__ = "python-iptables"
__version__ = "0.0.0"
__version__ = "0.1.0"
8 changes: 5 additions & 3 deletions iptc/xtables.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

import ctypes as ct
import ctypes.util
import version

XT_INV_PROTO = 0x40 # Invert the sense of PROTO
Expand Down Expand Up @@ -144,10 +145,11 @@ class xtables_target(ct.Structure):
class XTablesError(Exception):
"""Raised when an xtables call fails for some reason."""

_lib_xtables = ct.CDLL('libxtables.so.2', mode=ct.RTLD_GLOBAL)
_lib_xtables = ct.CDLL(ctypes.util.find_library("xtables"), mode=ct.RTLD_GLOBAL)

_lib_xtwrapper = ct.CDLL('libxtwrapper.so')
_throw = _lib_xtwrapper.throw_exception
from distutils.sysconfig import get_python_lib
_lib_xtwrapper = ct.CDLL(get_python_lib(1) + '/libxtwrapper.so')
throw = _lib_xtwrapper.throw_exception

def xt_exit(status, *args):
_throw(status)
Expand Down
17 changes: 2 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,10 @@
"""python-iptables setup script"""

import os
from distutils import ccompiler
from distutils.core import setup
from distutils.core import setup, Extension

execfile("iptc/version.py")

# libxtwrapper sources
LIBDIR="libxtwrapper"
csources = [os.path.join(LIBDIR, src)
for src in os.listdir("libxtwrapper") if src.endswith(".c")]

# compile and link libxtwrapper as a shared library
compiler = ccompiler.new_compiler(compiler="unix")
objs = compiler.compile(csources, extra_preargs=["-fPIC"])
compiler.link_shared_lib(objs, "xtwrapper", output_dir=LIBDIR)
lib = [os.path.join(LIBDIR,
compiler.library_filename("xtwrapper", lib_type="shared"))]

# build/install python-iptables
setup(
name = __pkgname__,
Expand All @@ -30,7 +17,7 @@
url = "http://nilvec.com/",
packages = ["iptc"],
package_dir = {"iptc" : "iptc"},
data_files = [("lib", lib)],
ext_modules = [Extension("libxtwrapper", ["libxtwrapper/wrapper.c"])],
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
Expand Down