-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | 70 | ||||
-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh | 3 |
2 files changed, 72 insertions, 1 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc index d385df4..7c9fbc4 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc @@ -201,4 +201,74 @@ int card_set_promisc_up (const char *device) } +/* Remove card from promisc mode */ +int card_remove_promisc (const char *device) +{ + int err; + /* First generate a socket to use with iocalls */ + int fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd < 0) + { + /* In case of an error */ + perror("socket"); + return 0; + } + + /* Fill an empty an interface structure with the right flags (UP and Promsic) */ + struct ifreq ifr; +/* strncpy(ifr.ifr_name, device,10); + ifr.ifr_flags = IFF_UP + IFF_PROMISC; + err = ioctl(fd, SIOCSIFFLAGS, &ifr); + if (err < 0) + { + perror("Could not access the interface, "); + close(fd); + return 0; + } + */ + /* Get the flags from the interface*/ + strncpy(ifr.ifr_name, device,10); + err = ioctl(fd, SIOCGIFFLAGS, &ifr); + if (err < 0) + { + perror("Could not access the interface, "); + close(fd); + return 0; + } + /* Remove the IFF_PROMISC flag */ + ifr.ifr_flags = ifr.ifr_flags - IFF_PROMISC; + /*Set the new flags to the interface*/ + err = ioctl(fd, SIOCSIFFLAGS, &ifr); + if (err < 0) + { + perror("Could not access the interface, "); + close(fd); + return 0; + } + + /* Get the flags again to check if IFF_PROMISC is removed */ + err = ioctl(fd, SIOCGIFFLAGS, &ifr); + if (err < 0) + { + perror("Could not access the interface, "); + close(fd); + return 0; + } + if(ifr.ifr_flags && IFF_PROMISC) + { + wl_logerr("Could not remove the promisc flag on %d", device); + close(fd); + return 0; + } + else + { + /* Successfully removed the promisc flags */ + close(fd); + return 1; + } +} + + + + /* Set channel (Wireless frequency) of the device */ int card_set_channel (const char *device, int channel, int cardtype) diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh index b35dddd..652b3ed 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh @@ -49,5 +49,6 @@ extern "C" int card_check_rfmon_datalink (const char *device); int card_into_monitormode (pcap_t **, const char *, int); -int card_set_promisc_up (const char *); +int card_set_promisc_up (const char *device); +int card_remove_promisc (const char *device); int card_set_channel (const char *device, int channel,int cardtype); int iw_get_range_info(int skfd, const char * ifname, struct iw_range * range); |