-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 @@ -191,24 +191,94 @@ int card_set_promisc_up (const char *device) { close(fd); return 1; } else { wl_logerr("Could not set promisc flag on %d", device); close(fd); return 0; } } +/* 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) { if (cardtype == CARD_TYPE_CISCO || cardtype == CARD_TYPE_NG) { /* Cisco and wlan-ng drivers don't need channelswitching */ return 1; } /* If it is a lucent orinocco card */ else if (cardtype == CARD_TYPE_ORINOCCO) { int fd; 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 @@ -39,25 +39,26 @@ extern "C" #define KILO 1e3 #define MEGA 1e6 #define GIGA 1e9 /* only for now, until we have the daemon running */ /*the config file should provide these information */ #define CARD_TYPE CARD_TYPE_HOSTAP /* Prototypes */ 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); double iw_freq2float(iw_freq * in); void iw_float2freq(double in, iw_freq * out); int card_detect_channels (char * device); /*------------------------------------------------------------------*/ /* * Wrapper to push some Wireless Parameter in the driver */ static inline int |