source: freewrt/package/wiviz/src/wl_access.c@ 6fc4520e

freewrt_1_0 freewrt_2_0
Last change on this file since 6fc4520e was 475ad56, checked in by Waldemar Brodkorb <wbx@…>, 20 years ago

add OpenWrt trunk revision 3830.

git-svn-id: svn://www.freewrt.org/trunk/freewrt@1 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/*
2This file is part of Wi-viz (http://wiviz.natetrue.com).
3
4Wi-viz is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License v2 as published by
6the Free Software Foundation.
7
8Wi-viz is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License
14along with Wi-viz; if not, write to the Free Software
15Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16*/
17#include <stdio.h>
18#include <unistd.h>
19#include <string.h>
20#include <errno.h>
21#include <sys/ioctl.h>
22#include <net/if.h>
23
24#include "wl_access.h"
25
26int wl_ioctl(char *name, int cmd, void *buf, int len)
27{
28 struct ifreq ifr;
29 wl_ioctl_t ioc;
30 int ret = 0;
31 int s;
32
33 /* open socket to kernel */
34 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
35 perror("socket");
36 return errno;
37 }
38
39 /* do it */
40 ioc.cmd = cmd;
41 ioc.buf = buf;
42 ioc.len = len;
43 strncpy(ifr.ifr_name, name, IFNAMSIZ);
44 ifr.ifr_data = (caddr_t) &ioc;
45 ret = ioctl(s, SIOCDEVPRIVATE, &ifr);
46
47 /* cleanup */
48 close(s);
49 return ret;
50}
51
52int get_mac(char *name, void *buf)
53{
54 struct ifreq ifr;
55 int ret = 0;
56 int s;
57
58 /* open socket to kernel */
59 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
60 perror("socket");
61 return errno;
62 }
63
64 strncpy(ifr.ifr_name, name, IFNAMSIZ);
65 //ifr.ifr_data = (caddr_t) buf;
66 if ((ret = ioctl(s, SIOCGIFHWADDR, &ifr)) < 0)
67 perror(ifr.ifr_name);
68
69 /* cleanup */
70 close(s);
71 memcpy(buf, &ifr.ifr_hwaddr.sa_data, 6);
72 return ret;
73}
Note: See TracBrowser for help on using the repository browser.