mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-26 09:18:24 -05:00
57 lines
1.2 KiB
C
57 lines
1.2 KiB
C
|
/*
|
||
|
* 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;
|
||
|
}
|