aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--native/net_monitor.c (renamed from net_monitor.c)44
-rwxr-xr-xnet_monitor (renamed from net_monitor.py)0
-rw-r--r--setup.py23
3 files changed, 52 insertions, 15 deletions
diff --git a/net_monitor.c b/native/net_monitor.c
index 49ab83b..2594a65 100644
--- a/net_monitor.c
+++ b/native/net_monitor.c
@@ -1,3 +1,4 @@
+#include <Python.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
@@ -185,31 +186,44 @@ iw_get_range_info(int skfd, const char *ifname, iwrange * range)
return(0);
}
-int main (int argc, char *argv[])
+static PyObject *
+ get_max_quality(PyObject *self, PyObject *args)
{
+ const char *iface;
+ int max_quality;
int fd, err;
struct iw_range range;
- if (argc < 2) {
- fprintf (stderr, "Usage: range-test <interface>\n");
- return 1;
- }
+ if (!PyArg_ParseTuple(args, "s", &iface))
+ return NULL;
fd = socket (PF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
fprintf (stderr, "couldn't open socket\n");
- return 1;
+ return NULL;
}
- err = iw_get_range_info(fd, argv[1], &range);
+ err = iw_get_range_info(fd, iface, &range);
+ close (fd);
+
if (err < 0) {
- perror("Getting wireless range");
- exit(1);
+ PyErr_SetFromErrno(PyExc_IOError);
+ return NULL;
}
- /* now to the interesting part */
- printf("Max quality: %d\n", range.max_qual.qual);
- printf("Max level: %d\n", range.max_qual.level);
- printf("Max noise: %d\n", range.max_qual.noise);
- close (fd);
- return 0;
+ max_quality = range.max_qual.qual;
+ return Py_BuildValue("i", max_quality);
+}
+
+/* python module details */
+static PyMethodDef net_monitor_Methods[] = {
+ {"get_max_quality", get_max_quality, METH_VARARGS,
+ "Find maximum quality value for a wireless interface."},
+ {NULL, NULL, 0, NULL} /* Sentinel */
+};
+
+PyMODINIT_FUNC
+initnet_monitor(void)
+{
+ (void) Py_InitModule("net_monitor", net_monitor_Methods);
}
+
diff --git a/net_monitor.py b/net_monitor
index fc05f2d..fc05f2d 100755
--- a/net_monitor.py
+++ b/net_monitor
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..3d2af8c
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,23 @@
+from version import *
+
+from distutils.core import setup, Extension
+
+module1 = Extension('net_monitor',
+ sources=['native/net_monitor.c'])
+
+setup (name='net_monitor',
+ version=version,
+ description='Mandriva network monitoring tool',
+ author="Eugeni Dodonov",
+ author_email="eugeni@mandriva.com",
+ url="http://www.mandriva.com",
+ license="GPL",
+ long_description=
+"""\
+This is a network monitoring tool for Mandriva Linux, intended to replace the
+old net_monitor from drakx-net. It supports graphical network monitoring and
+some advanced features, such as network profiling, activity monitoring,
+detailed logging and network traffic statistics with help of vnstat reporting.
+""",
+ scripts=["net_monitor"],
+ ext_modules=[module1])