fix: fixed compilation of macOS for wifi modules

This commit is contained in:
evilsocket 2019-01-20 18:30:22 +01:00
commit 79279126e6
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
3 changed files with 42 additions and 21 deletions

View file

@ -37,8 +37,19 @@ func getInterfaceName(iface net.Interface) string {
}
func SetInterfaceChannel(iface string, channel int) error {
curr := GetInterfaceChannel(iface)
// the interface is already on this channel
if curr == channel {
return nil
}
_, err := core.Exec(airPortPath, []string{iface, fmt.Sprintf("-c%d", channel)})
return err
if err != nil {
return err
}
SetInterfaceCurrentChannel(iface, channel)
return nil
}
func getFrequenciesFromChannels(output string) ([]int, error) {

View file

@ -7,7 +7,6 @@ import (
"regexp"
"strconv"
"strings"
"sync"
"github.com/bettercap/bettercap/core"
)
@ -19,9 +18,6 @@ var IPv4RouteCmd = "ip"
var IPv4RouteCmdOpts = []string{"route"}
var WiFiFreqParser = regexp.MustCompile(`^\s+Channel.([0-9]+)\s+:\s+([0-9\.]+)\s+GHz.*$`)
var currChannels = make(map[string]int)
var currChannelLock = sync.Mutex{}
func IPv4RouteIsGateway(ifname string, tokens []string, f func(gateway string) (*Endpoint, error)) (*Endpoint, error) {
ifname2 := tokens[3]
@ -38,22 +34,10 @@ func getInterfaceName(iface net.Interface) string {
return iface.Name
}
func GetInterfaceChannel(iface string) int {
currChannelLock.Lock()
defer currChannelLock.Unlock()
if curr, found := currChannels[iface]; found {
return curr
}
return 0
}
func SetInterfaceChannel(iface string, channel int) error {
currChannelLock.Lock()
defer currChannelLock.Unlock()
curr := GetInterfaceChannel(iface)
// the interface is already on this channel
if curr, found := currChannels[iface]; found && curr == channel {
if curr == channel {
return nil
}
@ -64,8 +48,7 @@ func SetInterfaceChannel(iface string, channel int) error {
return fmt.Errorf("Unexpected output while setting interface %s to channel %d: %s", iface, channel, out)
}
currChannels[iface] = channel
SetInterfaceCurrentChannel(iface, channel)
return nil
}

27
network/net_wifi.go Normal file
View file

@ -0,0 +1,27 @@
package network
import (
"sync"
)
const NO_CHANNEL = -1
var (
currChannels = make(map[string]int)
currChannelLock = sync.Mutex{}
)
func GetInterfaceChannel(iface string) int {
currChannelLock.Lock()
defer currChannelLock.Unlock()
if curr, found := currChannels[iface]; found {
return curr
}
return NO_CHANNEL
}
func SetInterfaceCurrentChannel(iface string, channel int) {
currChannelLock.Lock()
defer currChannelLock.Unlock()
currChannels[iface] = channel
}