summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Houghton <alastair@coriolis-systems.com>2012-01-30 12:26:44 +0000
committerAlastair Houghton <alastair@coriolis-systems.com>2012-01-30 12:26:44 +0000
commit30f8cdaf17f46383831cc393abb81b758577a47f (patch)
tree1a4f30afe69911d61740a11cdc75cc3adfb9de58
parent5b8f2317863f2c1c572bb2068801e631d05a924f (diff)
downloadnetifaces-30f8cdaf17f46383831cc393abb81b758577a47f.tar.gz
Improved setup script so it will build successfully in more cases. Added a version constant to the module. Fixed odd error behaviour for interfaces with no addresses on Linux.
-rw-r--r--netifaces.c15
-rwxr-xr-xnetifaces.egg-info/PKG-INFO2
-rw-r--r--setup.py24
3 files changed, 27 insertions, 14 deletions
diff --git a/netifaces.c b/netifaces.c
index bc4298b..5c99a20 100644
--- a/netifaces.c
+++ b/netifaces.c
@@ -550,6 +550,10 @@ ifaddrs (PyObject *self, PyObject *args)
if (strcmp (addr->ifa_name, ifname) != 0)
continue;
+ /* We mark the interface as found, even if there are no addresses;
+ this results in sensible behaviour for these few cases. */
+ found = TRUE;
+
/* Sometimes there are records without addresses (e.g. in the case of a
dial-up connection via ppp, which on Linux can have a link address
record with no actual address). We skip these as they aren't useful.
@@ -557,8 +561,6 @@ ifaddrs (PyObject *self, PyObject *args)
if (!addr->ifa_addr)
continue;
- found = TRUE;
-
if (string_from_sockaddr (addr->ifa_addr, buffer, sizeof (buffer)) == 0)
pyaddr = PyString_FromString (buffer);
@@ -950,6 +952,7 @@ static PyMethodDef methods[] = {
PyMODINIT_FUNC
initnetifaces (void)
{
+ PyObject *address_family_dict;
PyObject *m;
#ifdef WIN32
@@ -962,7 +965,7 @@ initnetifaces (void)
m = Py_InitModule ("netifaces", methods);
/* Address families (auto-detect using #ifdef) */
- PyObject *address_family_dict = PyDict_New();
+ address_family_dict = PyDict_New();
#ifdef AF_UNSPEC
PyModule_AddIntConstant (m, "AF_UNSPEC", AF_UNSPEC);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_UNSPEC),
@@ -1259,4 +1262,10 @@ initnetifaces (void)
PyString_FromString("AF_BLUETOOTH"));
#endif
PyModule_AddObject(m, "address_families", address_family_dict);
+
+ // Add-in the version number from setup.py
+#define _STR(x) #x
+#define STR(x) _STR(x)
+
+ PyModule_AddStringConstant(m, "version", STR(NETIFACES_VERSION));
}
diff --git a/netifaces.egg-info/PKG-INFO b/netifaces.egg-info/PKG-INFO
index 9dcb201..8e90ec2 100755
--- a/netifaces.egg-info/PKG-INFO
+++ b/netifaces.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: netifaces
-Version: 0.6
+Version: 0.7
Summary: Portable network interface information.
Home-page: http://alastairs-place.net/netifaces
Author: Alastair Houghton
diff --git a/setup.py b/setup.py
index a9335e4..9973d0b 100644
--- a/setup.py
+++ b/setup.py
@@ -7,8 +7,13 @@ from setuptools.command.build_ext import build_ext
from distutils.errors import *
import pickle
-# Disable hard links, otherwise building distributions fails
-del os.link
+__version__ = "0.7"
+
+# Disable hard links, otherwise building distributions fails on OS X
+try:
+ del os.link
+except:
+ pass
# On Windows, we need ws2_32 and iphlpapi
if getattr(sys, 'getwindowsversion', None):
@@ -21,6 +26,8 @@ else:
libraries = ['socket', 'nsl']
def_macros = []
+def_macros.append(("NETIFACES_VERSION", __version__))
+
iface_mod = Extension('netifaces', sources=['netifaces.c'],
libraries=libraries,
define_macros=def_macros)
@@ -33,7 +40,7 @@ class my_build_ext(build_ext):
self.check_requirements()
build_ext.build_extensions(self)
- def test_build(self, contents, link=True, execute=True, libraries=None,
+ def test_build(self, contents, link=True, execute=False, libraries=None,
include_dirs=None, library_dirs=None):
name = os.path.join(self.build_temp, 'conftest-%s.c' % self.conftestidx)
self.conftestidx += 1
@@ -43,9 +50,6 @@ class my_build_ext(build_ext):
print >>thefile, contents
thefile.close()
- tmpext = Extension('_dummy', [], libraries = libraries)
- libraries = self.get_libraries(tmpext)
-
sys.stdout.flush()
sys.stderr.flush()
mystdout = os.dup(1)
@@ -275,7 +279,7 @@ class my_build_ext(build_ext):
int main (void) { return 0; }
""" % header
- if self.test_build(testrig, link=False, execute=False):
+ if self.test_build(testrig, link=False):
result.append(header)
if result:
@@ -309,7 +313,7 @@ class my_build_ext(build_ext):
}
"""
- result = self.test_build(testrig, execute=False)
+ result = self.test_build(testrig)
if result:
print 'yes. %s' % cached
@@ -356,7 +360,7 @@ class my_build_ext(build_ext):
in optional_headers]),
'sockaddr': sockaddr }
- if self.test_build(testrig, execute=False):
+ if self.test_build(testrig):
result.append(sockaddr)
if result:
@@ -381,7 +385,7 @@ if not getattr(sys, 'getwindowsversion', None):
setuptools.command.build_ext.build_ext = my_build_ext
setup (name='netifaces',
- version='0.6',
+ version=__version__,
description="Portable network interface information.",
license="MIT License",
long_description="""\