|
29 | 29 | #include <sys/types.h> |
30 | 30 | #include <ifaddrs.h> |
31 | 31 | #include <netlink/route/addr.h> |
| 32 | +#include <linux/wireless.h> |
32 | 33 | #if !defined IFF_UP |
33 | 34 | #include <net/if.h> |
34 | 35 | #endif |
@@ -625,6 +626,37 @@ static PyObject *get_sg(PyObject *self __unused, PyObject *args) |
625 | 626 | return Py_BuildValue("b", value); |
626 | 627 | } |
627 | 628 |
|
| 629 | +static PyObject *get_wireless_protocol (PyObject *self __unused, PyObject *args) |
| 630 | +{ |
| 631 | + struct iwreq iwr; |
| 632 | + const char *devname; |
| 633 | + int fd, err; |
| 634 | + |
| 635 | + if (!PyArg_ParseTuple(args, "s", &devname)) |
| 636 | + return NULL; |
| 637 | + |
| 638 | + /* Setup our request structure. */ |
| 639 | + memset(&iwr, 0, sizeof(iwr)); |
| 640 | + strncpy(iwr.ifr_name, devname, IFNAMSIZ); |
| 641 | + |
| 642 | + /* Open control socket. */ |
| 643 | + fd = socket(AF_INET, SOCK_DGRAM, 0); |
| 644 | + if (fd < 0) { |
| 645 | + PyErr_SetFromErrno(PyExc_OSError); |
| 646 | + return NULL; |
| 647 | + } |
| 648 | + err = ioctl(fd, SIOCGIWNAME, &iwr); |
| 649 | + if(err < 0) { |
| 650 | + PyErr_SetFromErrno(PyExc_IOError); |
| 651 | + close(fd); |
| 652 | + return NULL; |
| 653 | + } |
| 654 | + |
| 655 | + close(fd); |
| 656 | + |
| 657 | + return PyStr_FromString(iwr.u.name); |
| 658 | +} |
| 659 | + |
628 | 660 | struct struct_desc { |
629 | 661 | char *name; |
630 | 662 | unsigned short offset; |
@@ -906,6 +938,11 @@ static struct PyMethodDef PyEthModuleMethods[] = { |
906 | 938 | .ml_meth = (PyCFunction)get_flags, |
907 | 939 | .ml_flags = METH_VARARGS, |
908 | 940 | }, |
| 941 | + { |
| 942 | + .ml_name = "get_wireless_protocol", |
| 943 | + .ml_meth = (PyCFunction)get_wireless_protocol, |
| 944 | + .ml_flags = METH_VARARGS, |
| 945 | + }, |
909 | 946 | { .ml_name = NULL, }, |
910 | 947 | }; |
911 | 948 |
|
|
0 commit comments