mark2b / wpa-connect

wpa-connect
MIT License
61 stars 19 forks source link

Scan/Connect Managers hardcode wifi dev name #5

Closed buildscientist closed 3 years ago

buildscientist commented 3 years ago

The scan & connect managers both hardcode the wifi dev name to wlan0 unless the developer overrides the device name prior to calling the Scan() or Connect() methods.

Following your code example one would need to do the following:

wifi.ScanManager.NetInterface  = "customUDev0"
if bssList, err := wifi.ScanManager.Scan(); err == nil {
    for _, bss := range bssList {
        print(bss.SSID, bss.Signal, bss.KeyMgmt)
    }
}

Is there any reason why the Scan/Connect manager define global vars with a pre-instantiated struct setting the wifi uDev name? I think it would make more sense to require the developer to create a reference to their own Scan/Connect managers. Consider a case where the system using this library has multiple wifi devices.

mark2b commented 3 years ago

Scan & Connect managers have default name for wifi dev name wlan0 because it is default interface for most of linux distros. But there is an option to customize, like line of code you provided. Reason of global singleton Scan & Connect managers is to make code simple and have an access to same instance from different places of code (singleton in other words) It is a good point to take ability to create multiple instances of managers, I will add new methods like wifi.NewConnectManager('wlan0') and wifi.NewScanManager('wlan0')