예제 #1
0
void NetPlatform_flushAddresses(const char* deviceName, struct Except* eh)
{
    NET_LUID luid = getLuid(deviceName, eh);
    MIB_UNICASTIPADDRESS_TABLE* table;

    WinFail_check(eh, GetUnicastIpAddressTable(AF_INET, &table));
    LONG ret = flushAddresses(luid, table);
    FreeMibTable(table);
    if (ret) {
        WinFail_fail(eh, "DeleteUnicastIpAddressEntry(&table->Table[i])", ret);
    }

    WinFail_check(eh, GetUnicastIpAddressTable(AF_INET6, &table));
    ret = flushAddresses(luid, table);
    FreeMibTable(table);
    if (ret) {
        WinFail_fail(eh, "DeleteUnicastIpAddressEntry(&table->Table[i])", ret);
    }
}
예제 #2
0
파일: TAPDevice.c 프로젝트: cmotc/cjdns
static int get_device_guid(
    char *name,
    int name_size,
    char *actual_name,
    int actual_name_size,
    struct Except* eh)
{
    LONG status;
    HKEY control_net_key;
    DWORD len;

    WinFail_check(eh, (
        RegOpenKeyEx(HKEY_LOCAL_MACHINE, NETWORK_CONNECTIONS_KEY, 0, KEY_READ, &control_net_key)
    ));

    int stop = 0;
    for (int i = 0; !stop; i++) {
        char enum_name[256];
        char connection_string[256];
        HKEY connKey;
        char name_data[256];
        DWORD name_type;
        const char name_string[] = "Name";

        len = sizeof (enum_name);
        status = RegEnumKeyEx(control_net_key, i, enum_name, &len, NULL, NULL, NULL, NULL);

        if (status == ERROR_NO_MORE_ITEMS) {
            break;
        } else if (status != ERROR_SUCCESS) {
            WinFail_fail(eh, "RegEnumKeyEx() failed", status);
        }

        if (len != CString_strlen(NETWORK_ADAPTER_GUID)) {
            // extranious directory, eg: "Descriptions"
            continue;
        }

        snprintf(connection_string,
             sizeof(connection_string),
             "%s\\%s\\Connection",
             NETWORK_CONNECTIONS_KEY, enum_name);

        WinFail_check(eh, (
            RegOpenKeyEx(HKEY_LOCAL_MACHINE, connection_string, 0, KEY_READ, &connKey)
        ));


        // In Windows 10, some interface keys don't have names. We should keep
        // going and treat those interfaces as having empty string names.

        len = sizeof (name_data);
        status = RegQueryValueEx(connKey, name_string, NULL, &name_type,
            (uint8_t*)name_data, &len);

        if (status == ERROR_FILE_NOT_FOUND) {
            // The interface has no name.
            strncpy(name_data, "",  sizeof (name_data));
        } else if (status != ERROR_SUCCESS) {
            WinFail_fail(eh, "RegQueryValueEx() for interface name failed", status);
        } else {
            if (name_type != REG_SZ) {
                // Someone named an interface with a non-string
                WinFail_fail(eh, "RegQueryValueEx() name_type != REG_SZ", status);
            }
        }

        if (is_tap_win32_dev(enum_name)) {
            snprintf(name, name_size, "%s", enum_name);
            if (actual_name) {
                if (CString_strcmp(actual_name, "") != 0) {
                    if (CString_strcmp(name_data, actual_name) != 0) {
                        RegCloseKey (connKey);
                        ++i;
                        continue;
                    }
                }
                else {
                    snprintf(actual_name, actual_name_size, "%s", name_data);
                }
            }
            stop = 1;
        }

        RegCloseKey(connKey);
    }

    RegCloseKey (control_net_key);

    if (stop == 0) {
        return -1;
    }

    return 0;
}