2 * Linux ioctl helper functions for driver wrappers
3 * Copyright (c) 2002-2010, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
16 #include <sys/ioctl.h>
19 #include "utils/common.h"
20 #include "linux_ioctl.h"
23 int linux_set_iface_flags(int sock
, const char *ifname
, int dev_up
)
30 os_memset(&ifr
, 0, sizeof(ifr
));
31 os_strlcpy(ifr
.ifr_name
, ifname
, IFNAMSIZ
);
33 if (ioctl(sock
, SIOCGIFFLAGS
, &ifr
) != 0) {
34 wpa_printf(MSG_ERROR
, "Could not read interface %s flags: %s",
35 ifname
, strerror(errno
));
40 if (ifr
.ifr_flags
& IFF_UP
)
42 ifr
.ifr_flags
|= IFF_UP
;
44 if (!(ifr
.ifr_flags
& IFF_UP
))
46 ifr
.ifr_flags
&= ~IFF_UP
;
49 if (ioctl(sock
, SIOCSIFFLAGS
, &ifr
) != 0) {
50 wpa_printf(MSG_ERROR
, "Could not set interface %s flags: %s",
51 ifname
, strerror(errno
));