diff options
author | nbd <nbd@3c298f89-4303-0410-b956-a3cf2f4a3e73> | 2005-08-29 11:30:35 +0000 |
---|---|---|
committer | nbd <nbd@3c298f89-4303-0410-b956-a3cf2f4a3e73> | 2005-08-29 11:30:35 +0000 |
commit | 35015fbd8d07398f9633a096e69f1dadb9a4c389 (patch) | |
tree | c83c02bec0dc98cc7d7f2287c1be5733ec238dae /package/wiviz/src/wl_access.c | |
parent | 70ad6e4277e5f7dd548aabcd823f18b1b73f5711 (diff) |
add Wi-viz
git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@1785 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/wiviz/src/wl_access.c')
-rw-r--r-- | package/wiviz/src/wl_access.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/package/wiviz/src/wl_access.c b/package/wiviz/src/wl_access.c new file mode 100644 index 0000000000..a5172c3665 --- /dev/null +++ b/package/wiviz/src/wl_access.c @@ -0,0 +1,73 @@ +/* +This file is part of Wi-viz (http://wiviz.natetrue.com). + +Wi-viz is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License v2 as published by +the Free Software Foundation. + +Wi-viz is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Wi-viz; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <sys/ioctl.h> +#include <net/if.h> + +#include "wl_access.h" + +int wl_ioctl(char *name, int cmd, void *buf, int len) +{ + struct ifreq ifr; + wl_ioctl_t ioc; + int ret = 0; + int s; + + /* open socket to kernel */ + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + perror("socket"); + return errno; + } + + /* do it */ + ioc.cmd = cmd; + ioc.buf = buf; + ioc.len = len; + strncpy(ifr.ifr_name, name, IFNAMSIZ); + ifr.ifr_data = (caddr_t) &ioc; + ret = ioctl(s, SIOCDEVPRIVATE, &ifr); + + /* cleanup */ + close(s); + return ret; +} + +int get_mac(char *name, void *buf) +{ + struct ifreq ifr; + int ret = 0; + int s; + + /* open socket to kernel */ + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + perror("socket"); + return errno; + } + + strncpy(ifr.ifr_name, name, IFNAMSIZ); + //ifr.ifr_data = (caddr_t) buf; + if ((ret = ioctl(s, SIOCGIFHWADDR, &ifr)) < 0) + perror(ifr.ifr_name); + + /* cleanup */ + close(s); + memcpy(buf, &ifr.ifr_hwaddr.sa_data, 6); + return ret; +} |