//============================================================================= // Copyright (c) 2001 Microsoft Corporation // Abstract: // This module implements IPv6 configuration commands. //============================================================================= #include "precomp.h" #pragma hdrstop typedef enum { ACTION_ADD, ACTION_SET } ACTION; DWORD GetTime( IN PWCHAR pwszLife) { PWCHAR pwcUnit; DWORD dwUnits, dwLife = 0; if (!_wcsnicmp(pwszLife, TOKEN_VALUE_INFINITE, wcslen(pwszLife))) { return INFINITE_LIFETIME; } while ((pwcUnit = wcspbrk(pwszLife, L"sSmMhHdD")) != NULL) { switch (*pwcUnit) { case L's': case L'S': dwUnits = SECONDS; break; case L'm': case L'M': dwUnits = MINUTES; break; case L'h': case L'H': dwUnits = HOURS; break; case L'd': case L'D': dwUnits = DAYS; break; } *pwcUnit = L'\0'; dwLife += wcstoul(pwszLife, NULL, 10) * dwUnits; pwszLife = pwcUnit + 1; if (*pwszLife == L'\0') return dwLife; } return dwLife + wcstoul(pwszLife, NULL, 10); } ///////////////////////////////////////////////////////////////////////////// // Commands related to addresses ///////////////////////////////////////////////////////////////////////////// DWORD HandleAddSetAddress( IN OUT LPWSTR *ppwcArguments, IN DWORD dwCurrentIndex, IN DWORD dwArgCount, IN ACTION Action, OUT BOOL *pbDone ) { DWORD dwErr, i; TAG_TYPE pttTags[] = {{TOKEN_INTERFACE, TRUE, FALSE}, {TOKEN_ADDRESS, TRUE, FALSE}, {TOKEN_TYPE, FALSE, FALSE}, {TOKEN_VALIDLIFETIME, FALSE, FALSE}, {TOKEN_PREFERREDLIFETIME, FALSE, FALSE}, {TOKEN_STORE, FALSE, FALSE}}; DWORD rgdwTagType[sizeof(pttTags)/sizeof(TAG_TYPE)]; PWCHAR pwszIfFriendlyName = NULL; IN6_ADDR ipAddress; TOKEN_VALUE rgtvTypeEnum[] = {{ TOKEN_VALUE_UNICAST, ADE_UNICAST }, { TOKEN_VALUE_ANYCAST, ADE_ANYCAST }}; TOKEN_VALUE rgtvStoreEnum[] = {{ TOKEN_VALUE_ACTIVE, FALSE }, { TOKEN_VALUE_PERSISTENT, TRUE }}; DWORD dwType = ADE_UNICAST; DWORD dwValidLifetime = INFINITE_LIFETIME; DWORD dwPreferredLifetime = INFINITE_LIFETIME; BOOL bPersistent = TRUE; // Parse arguments dwErr = PreprocessCommand(g_hModule, ppwcArguments, dwCurrentIndex, dwArgCount, pttTags, sizeof(pttTags)/sizeof(TAG_TYPE), 0, sizeof(pttTags)/sizeof(TAG_TYPE), rgdwTagType ); for (i=0; (dwErr == NO_ERROR) && (i Servers) { // Null out final delimiter. p--; *p = '\0'; } dwErr = SetString(hIf, KEY_DNS_SERVER_LIST, Servers); RegCloseKey(hIf); RegCloseKey(hInterfaces); return dwErr; } DWORD HandleAddDns( IN LPCWSTR pwszMachine, IN OUT LPWSTR *ppwcArguments, IN DWORD dwCurrentIndex, IN DWORD dwArgCount, IN DWORD dwFlags, IN LPCVOID pvData, OUT BOOL *pbDone ) { DWORD dwErr = NO_ERROR; TAG_TYPE pttTags[] = {{TOKEN_INTERFACE, NS_REQ_PRESENT, FALSE}, {TOKEN_ADDRESS, NS_REQ_PRESENT, FALSE}, {TOKEN_INDEX, NS_REQ_ZERO, FALSE}}; DWORD rgdwTagType[sizeof(pttTags)/sizeof(TAG_TYPE)]; DWORD i; PWCHAR pwszIfFriendlyName = NULL; IN6_ADDR ipAddress; DWORD dwIndex = -1; HKEY hInterfaces, hIf; IN6_ADDR *ipDnsList; DWORD dwNumEntries; PIP_ADAPTER_ADDRESSES pAdapterInfo = NULL; // Parse arguments dwErr = PreprocessCommand(g_hModule, ppwcArguments, dwCurrentIndex, dwArgCount, pttTags, sizeof(pttTags)/sizeof(TAG_TYPE), 0, sizeof(pttTags)/sizeof(TAG_TYPE), rgdwTagType ); if (dwErr isnot NO_ERROR) { return dwErr; } for (i=0; i dwNumEntries)) { dwErr = ERROR_INVALID_PARAMETER; goto Cleanup; } else { dwIndex--; // Insert server at location 'dwIndex'. for (i = dwNumEntries; i > dwIndex; i--) { ipDnsList[i] = ipDnsList[i-1]; } ipDnsList[dwIndex] = ipAddress; dwNumEntries++; } dwErr = SetDnsServerList(pwszIfFriendlyName, pAdapterInfo, ipDnsList, dwNumEntries); Cleanup: if (ipDnsList != NULL) { FREE(ipDnsList); } if (pAdapterInfo != NULL) { FREE(pAdapterInfo); } if (dwErr == NO_ERROR) { dwErr = ERROR_OKAY; } return dwErr; } DWORD HandleDelDns( IN LPCWSTR pwszMachine, IN OUT LPWSTR *ppwcArguments, IN DWORD dwCurrentIndex, IN DWORD dwArgCount, IN DWORD dwFlags, IN LPCVOID pvData, OUT BOOL *pbDone ) { DWORD dwErr = NO_ERROR; TAG_TYPE pttTags[] = {{TOKEN_INTERFACE, NS_REQ_PRESENT, FALSE}, {TOKEN_ADDRESS, NS_REQ_PRESENT, FALSE}}; DWORD rgdwTagType[sizeof(pttTags)/sizeof(TAG_TYPE)]; DWORD i; PWCHAR pwszIfFriendlyName = NULL; IN6_ADDR ipAddress; IN6_ADDR *ipDnsList; BOOL bAll = FALSE; DWORD dwNumEntries; PIP_ADAPTER_ADDRESSES pAdapterInfo = NULL; // Parse arguments dwErr = PreprocessCommand(g_hModule, ppwcArguments, dwCurrentIndex, dwArgCount, pttTags, sizeof(pttTags)/sizeof(TAG_TYPE), 0, sizeof(pttTags)/sizeof(TAG_TYPE), rgdwTagType ); if (dwErr isnot NO_ERROR) { return dwErr; } for (i=0; i 0)) { // DisplayMessage(g_hModule, MSG_DNS_SERVER_HEADER, pwszIfFriendlyName); *pbHeaderDone = TRUE; } ZeroMemory(&saddr, sizeof(saddr)); saddr.sin6_family = AF_INET6; for (i = 0; i < dwNumEntries; i++) { saddr.sin6_addr = ipDnsList[i]; Length = sizeof(saddr); if (WSAAddressToStringW((LPSOCKADDR)&saddr, sizeof(saddr), NULL, buff, &Length) != NO_ERROR) { continue; } if (bDump) { DisplayMessageT(DMP_IPV6_ADD_DNS); DisplayMessageT(DMP_QUOTED_STRING_ARG, TOKEN_INTERFACE, pwszIfFriendlyName); DisplayMessageT(DMP_STRING_ARG, TOKEN_ADDRESS, buff); DisplayMessage(g_hModule, MSG_NEWLINE); } else { // DisplayMessage(g_hModule, MSG_DNS_SERVER, i+1, buff); } } Error: if (ipDnsList != NULL) { FREE(ipDnsList); } return dwErr; } DWORD ShowDnsServers( IN BOOL bDump, IN PWCHAR pwszIfFriendlyName ) { PIP_ADAPTER_ADDRESSES pIf, pAdapterInfo = NULL; DWORD dwErr; BOOL bHeaderDone = FALSE; dwErr = MyGetAdaptersInfo(&pAdapterInfo); if (dwErr != NO_ERROR) { return dwErr; } if (pwszIfFriendlyName == NULL) { for (pIf = pAdapterInfo; (dwErr == NO_ERROR) && pIf; pIf = pIf->Next) { if (pIf->Ipv6IfIndex == 0) { continue; } dwErr = ShowIfDnsServers(bDump, pAdapterInfo, pIf->FriendlyName, &bHeaderDone); } } else { dwErr = ShowIfDnsServers(bDump, pAdapterInfo, pwszIfFriendlyName, &bHeaderDone); } if (!bDump) { if (!bHeaderDone) { DisplayMessage(g_hModule, MSG_IP_NO_ENTRIES); } if (dwErr == NO_ERROR) { dwErr = ERROR_SUPPRESS_OUTPUT; } } FREE(pAdapterInfo); return dwErr; } DWORD HandleShowDns( IN LPCWSTR pwszMachine, IN OUT LPWSTR *ppwcArguments, IN DWORD dwCurrentIndex, IN DWORD dwArgCount, IN DWORD dwFlags, IN LPCVOID pvData, OUT BOOL *pbDone ) { DWORD dwErr = NO_ERROR; TAG_TYPE pttTags[] = {{TOKEN_INTERFACE, NS_REQ_ZERO, FALSE}}; DWORD rgdwTagType[sizeof(pttTags)/sizeof(TAG_TYPE)]; DWORD i; PWCHAR pwszIfFriendlyName = NULL; // Parse arguments dwErr = PreprocessCommand(g_hModule, ppwcArguments, dwCurrentIndex, dwArgCount, pttTags, sizeof(pttTags)/sizeof(TAG_TYPE), 0, sizeof(pttTags)/sizeof(TAG_TYPE), rgdwTagType ); if (dwErr isnot NO_ERROR) { return dwErr; } for (i=0; i