summaryrefslogtreecommitdiff
path: root/netifaces.c
diff options
context:
space:
mode:
authorAlastair Houghton <alastair@alastairs-place.net>2012-01-30 12:26:44 +0000
committerAlastair Houghton <alastair@alastairs-place.net>2012-01-30 12:26:44 +0000
commit451fb9574813c771fcba696cf4d130d2a92c080d (patch)
tree1a4f30afe69911d61740a11cdc75cc3adfb9de58 /netifaces.c
parente10f3627c391d48bde65fe803164b4ddb299e933 (diff)
downloadnetifaces-git-451fb9574813c771fcba696cf4d130d2a92c080d.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.
Diffstat (limited to 'netifaces.c')
-rw-r--r--netifaces.c15
1 files changed, 12 insertions, 3 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));
}