diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-03-22 16:48:40 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-03-22 16:48:40 -0600 |
commit | 2fa80c0cb7453ab830355b4c612192ec3064865c (patch) | |
tree | 3e5bb269bfaa0f68547fa00c65cc8f4f49497927 | |
parent | 52ec440d7977fad966002c3710ed9df957943407 (diff) |
wintun: query for NetCfgInstanceId several times
-rw-r--r-- | tun/wintun/wintun_windows.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/tun/wintun/wintun_windows.go b/tun/wintun/wintun_windows.go index f2f3684..ba94b11 100644 --- a/tun/wintun/wintun_windows.go +++ b/tun/wintun/wintun_windows.go @@ -45,14 +45,25 @@ func MakeWintun(deviceInfoSet setupapi.DevInfo, deviceInfoData *setupapi.DevInfo } defer key.Close() - // Read the NetCfgInstanceId value. - valueStr, valueType, err := key.GetStringValue("NetCfgInstanceId") + var valueStr string + var valueType uint32 + + //TODO: Figure out a way to not need to loop like this. + for i := 0; i < 30; i++ { + // Read the NetCfgInstanceId value. + valueStr, valueType, err = key.GetStringValue("NetCfgInstanceId") + if err != nil { + time.Sleep(time.Millisecond * 100) + continue + } + if valueType != registry.SZ { + return nil, fmt.Errorf("NetCfgInstanceId registry value is not REG_SZ (expected: %v, provided: %v)", registry.SZ, valueType) + } + break + } if err != nil { return nil, errors.New("RegQueryStringValue(\"NetCfgInstanceId\") failed: " + err.Error()) } - if valueType != registry.SZ { - return nil, fmt.Errorf("NetCfgInstanceId registry value is not REG_SZ (expected: %v, provided: %v)", registry.SZ, valueType) - } // Convert to windows.GUID. ifid, err := guid.FromString(valueStr) |