diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..10ff4e4 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include doc/* iptc/* libxtwrapper/* NOTICE README setup.py test.py diff --git a/iptc/__init__.py b/iptc/__init__.py index 5be98ef..3bb0a96 100644 --- a/iptc/__init__.py +++ b/iptc/__init__.py @@ -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 @@ -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.""" @@ -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 @@ -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", diff --git a/iptc/version.py b/iptc/version.py index f52b723..2f3175c 100644 --- a/iptc/version.py +++ b/iptc/version.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- __pkgname__ = "python-iptables" -__version__ = "0.0.0" +__version__ = "0.1.0" diff --git a/iptc/xtables.py b/iptc/xtables.py index 2201003..ad5e1ba 100644 --- a/iptc/xtables.py +++ b/iptc/xtables.py @@ -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 @@ -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) diff --git a/setup.py b/setup.py index acafc04..0c5255c 100644 --- a/setup.py +++ b/setup.py @@ -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__, @@ -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",