Fix touch
[openwrt.git] / package / openwrt / libshared / wl_linux.c
1 /*
2 * Wireless network adapter utilities (linux-specific)
3 *
4 * Copyright 2004, Broadcom Corporation
5 * All Rights Reserved.
6 *
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
11 *
12 * $Id$
13 */
14
15 #include <stdio.h>
16 #include <unistd.h>
17 #include <string.h>
18 #include <errno.h>
19 #include <sys/ioctl.h>
20 #include <net/if.h>
21
22 #include <typedefs.h>
23 #include <wlioctl.h>
24 #include <wlutils.h>
25
26 int
27 wl_ioctl(char *name, int cmd, void *buf, int len)
28 {
29 struct ifreq ifr;
30 wl_ioctl_t ioc;
31 int ret = 0;
32 int s;
33
34 /* open socket to kernel */
35 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
36 perror("socket");
37 return errno;
38 }
39
40 /* do it */
41 ioc.cmd = cmd;
42 ioc.buf = buf;
43 ioc.len = len;
44 strncpy(ifr.ifr_name, name, IFNAMSIZ);
45 ifr.ifr_data = (caddr_t) &ioc;
46 if ((ret = ioctl(s, SIOCDEVPRIVATE, &ifr)) < 0)
47 if (cmd != WLC_GET_MAGIC)
48 perror(ifr.ifr_name);
49
50 /* cleanup */
51 close(s);
52 return ret;
53 }
54
55 int
56 wl_hwaddr(char *name, unsigned char *hwaddr)
57 {
58 struct ifreq ifr;
59 int ret = 0;
60 int s;
61
62 /* open socket to kernel */
63 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
64 perror("socket");
65 return errno;
66 }
67
68 /* do it */
69 strncpy(ifr.ifr_name, name, IFNAMSIZ);
70 if ((ret = ioctl(s, SIOCGIFHWADDR, &ifr)) == 0)
71 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
72
73 /* cleanup */
74 close(s);
75 return ret;
76 }
77
This page took 0.049802 seconds and 5 git commands to generate.