Skip to content

Commit

Permalink
fix: using iw instead of iwconfig whenever possible (fixes #657)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsocket committed Nov 25, 2019
1 parent 83c6cde commit 2f3390c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
9 changes: 8 additions & 1 deletion network/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,14 @@ func ActivateInterface(name string) error {
}

func SetInterfaceTxPower(name string, txpower int) error {
if core.HasBinary("iwconfig") {
if core.HasBinary("iw") {
Debug("SetInterfaceTxPower(%s, %d) iw based", name, txpower)
if _, err := core.Exec("iw", []string{"dev", name, "set", "txpower", fmt.Sprintf("%dmBm",
txpower)}); err != nil {
return err
}
} else if core.HasBinary("iwconfig") {
Debug("SetInterfaceTxPower(%s, %d) iwconfig based", name, txpower)
if out, err := core.Exec("iwconfig", []string{name, "txpower", fmt.Sprintf("%d", txpower)}); err != nil {
return err
} else if out != "" {
Expand Down
21 changes: 16 additions & 5 deletions network/net_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,22 @@ func SetInterfaceChannel(iface string, channel int) error {
return nil
}

out, err := core.Exec("iwconfig", []string{iface, "channel", fmt.Sprintf("%d", channel)})
if err != nil {
return err
} else if out != "" {
return fmt.Errorf("Unexpected output while setting interface %s to channel %d: %s", iface, channel, out)
if core.HasBinary("iw") {
Debug("SetInterfaceChannel(%s, %d) iw based", iface, channel)
out, err := core.Exec("iw", []string{"dev", iface, "set", "channel", fmt.Sprintf("%d", channel)})
if err != nil {
return err
} else if out != "" {
return fmt.Errorf("Unexpected output while setting interface %s to channel %d: %s", iface, channel, out)
}
} else if core.HasBinary("iwconfig") {
Debug("SetInterfaceChannel(%s, %d) iwconfig based")
out, err := core.Exec("iwconfig", []string{iface, "channel", fmt.Sprintf("%d", channel)})
if err != nil {
return err
} else if out != "" {
return fmt.Errorf("Unexpected output while setting interface %s to channel %d: %s", iface, channel, out)
}
}

SetInterfaceCurrentChannel(iface, channel)
Expand Down

0 comments on commit 2f3390c

Please sign in to comment.