aboutsummaryrefslogtreecommitdiffstats
path: root/src/drivers/linux_ioctl.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2010-01-03 20:08:26 (GMT)
committerJouni Malinen <j@w1.fi>2010-01-03 20:08:26 (GMT)
commit34f2f814e08a08806e81047198bca08537bfa5bc (patch)
tree894b605fa55d3788ee5f9d2f34c17c2b0d57ae97 /src/drivers/linux_ioctl.c
parent9c3a2284de0d967689955d166619d0704207142e (diff)
downloadhostap-34f2f814e08a08806e81047198bca08537bfa5bc.zip
hostap-34f2f814e08a08806e81047198bca08537bfa5bc.tar.gz
hostap-34f2f814e08a08806e81047198bca08537bfa5bc.tar.bz2
Share a single Linux ioctl helper fo setting interface up/down
Number of Linux driver wrappers included this more or less identical function, so lets add a new helper file to be able to share some more code between the driver wrappers.
Diffstat (limited to 'src/drivers/linux_ioctl.c')
-rw-r--r--src/drivers/linux_ioctl.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/drivers/linux_ioctl.c b/src/drivers/linux_ioctl.c
new file mode 100644
index 0000000..733bdb2
--- /dev/null
+++ b/src/drivers/linux_ioctl.c
@@ -0,0 +1,56 @@
+/*
+ * Linux ioctl helper functions for driver wrappers
+ * Copyright (c) 2002-2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+#include <sys/ioctl.h>
+#include <net/if.h>
+
+#include "utils/common.h"
+#include "linux_ioctl.h"
+
+
+int linux_set_iface_flags(int sock, const char *ifname, int dev_up)
+{
+ struct ifreq ifr;
+
+ if (sock < 0)
+ return -1;
+
+ os_memset(&ifr, 0, sizeof(ifr));
+ os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
+
+ if (ioctl(sock, SIOCGIFFLAGS, &ifr) != 0) {
+ wpa_printf(MSG_ERROR, "Could not read interface %s flags: %s",
+ ifname, strerror(errno));
+ return -1;
+ }
+
+ if (dev_up) {
+ if (ifr.ifr_flags & IFF_UP)
+ return 0;
+ ifr.ifr_flags |= IFF_UP;
+ } else {
+ if (!(ifr.ifr_flags & IFF_UP))
+ return 0;
+ ifr.ifr_flags &= ~IFF_UP;
+ }
+
+ if (ioctl(sock, SIOCSIFFLAGS, &ifr) != 0) {
+ wpa_printf(MSG_ERROR, "Could not set interface %s flags: %s",
+ ifname, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}