|
32 | 32 | #define REGISTER_BOTH 3 |
33 | 33 |
|
34 | 34 | static FN_HANDLE_CMD IpAddAddress; |
| 35 | +static FN_HANDLE_CMD IpAddDns; |
35 | 36 | static FN_HANDLE_CMD IpSetAddress; |
36 | 37 | static FN_HANDLE_CMD IpSetDns; |
37 | 38 | static FN_HANDLE_CMD IpShowAddresses; |
|
43 | 44 | CMD_ENTRY |
44 | 45 | IpAddCommands[] = |
45 | 46 | { |
46 | | - {L"address", IpAddAddress, IDS_HLP_IP_ADD_ADDRESS, IDS_HLP_IP_ADD_ADDRESS_EX, 0} |
| 47 | + {L"address", IpAddAddress, IDS_HLP_IP_ADD_ADDRESS, IDS_HLP_IP_ADD_ADDRESS_EX, 0}, |
| 48 | + {L"dns", IpAddDns, IDS_HLP_IP_ADD_DNS, IDS_HLP_IP_ADD_DNS_EX, 0} |
47 | 49 | }; |
48 | 50 |
|
49 | 51 | static |
@@ -709,6 +711,186 @@ IpAddAddress( |
709 | 711 | } |
710 | 712 |
|
711 | 713 |
|
| 714 | +static |
| 715 | +DWORD |
| 716 | +WINAPI |
| 717 | +IpAddDns( |
| 718 | + LPCWSTR pwszMachine, |
| 719 | + LPWSTR *argv, |
| 720 | + DWORD dwCurrentIndex, |
| 721 | + DWORD dwArgCount, |
| 722 | + DWORD dwFlags, |
| 723 | + LPCVOID pvData, |
| 724 | + BOOL *pbDone) |
| 725 | +{ |
| 726 | + TAG_TYPE pttTags[] = {{L"name", NS_REQ_ZERO, FALSE}, |
| 727 | + {L"addr", NS_REQ_ZERO, FALSE}, |
| 728 | + {L"index", NS_REQ_ZERO, FALSE}}; |
| 729 | + GUID InterfaceGUID; |
| 730 | + PDWORD pdwTagType = NULL; |
| 731 | + DWORD i; |
| 732 | + BOOL bHaveName = FALSE, bHaveAddress = FALSE/*, bHaveIndex = FALSE*/; |
| 733 | + IN_ADDR Address; |
| 734 | + PWSTR pszName = NULL, pszAddress = NULL; |
| 735 | + PWSTR pszNewParameters = NULL; |
| 736 | + DWORD dwIndex, dwLength; |
| 737 | + PCWSTR Term; |
| 738 | + PTCPIP_PROPERTIES pProperties = NULL; |
| 739 | + TCPIP_PROPERTIES NewProperties; |
| 740 | + HRESULT hr; |
| 741 | + NTSTATUS Status; |
| 742 | + DWORD dwError = ERROR_SUCCESS; |
| 743 | + |
| 744 | + DPRINT1("IpAddDns()\n"); |
| 745 | + |
| 746 | + pdwTagType = HeapAlloc(GetProcessHeap(), |
| 747 | + 0, |
| 748 | + (dwArgCount - dwCurrentIndex) * sizeof(DWORD)); |
| 749 | + if (pdwTagType == NULL) |
| 750 | + { |
| 751 | + return ERROR_NOT_ENOUGH_MEMORY; |
| 752 | + } |
| 753 | + |
| 754 | + dwError = MatchTagsInCmdLine(hDllInstance, |
| 755 | + argv, |
| 756 | + dwCurrentIndex, |
| 757 | + dwArgCount, |
| 758 | + pttTags, |
| 759 | + ARRAYSIZE(pttTags), |
| 760 | + pdwTagType); |
| 761 | + if (dwError != ERROR_SUCCESS) |
| 762 | + { |
| 763 | + DPRINT1("MatchTagsInCmdLine() failed (Error %lu)\n", dwError); |
| 764 | + HeapFree(GetProcessHeap(), 0, pdwTagType); |
| 765 | + return dwError; |
| 766 | + } |
| 767 | + |
| 768 | + for (i = 0; i < (dwArgCount - dwCurrentIndex); i++) |
| 769 | + { |
| 770 | + DPRINT1("Tag %lu: %lu\n", i, pdwTagType[i]); |
| 771 | + |
| 772 | + switch (pdwTagType[i]) |
| 773 | + { |
| 774 | + case 0: /* name */ |
| 775 | + DPRINT1("Tag: name (%S)\n", argv[i + dwCurrentIndex]); |
| 776 | + dwError = NhGetGuidFromInterfaceName(argv[i + dwCurrentIndex], |
| 777 | + &InterfaceGUID, |
| 778 | + 0, 0); |
| 779 | + if (dwError != ERROR_SUCCESS) |
| 780 | + { |
| 781 | + DPRINT1("NhGetGuidFromInterfaceName() failed (Error %lu)\n", dwError); |
| 782 | + PrintMessageFromModule(hDllInstance, |
| 783 | + IDS_ERROR_INVALID_INTERFACE, |
| 784 | + argv[i + dwCurrentIndex]); |
| 785 | + dwError = ERROR_SUPPRESS_OUTPUT; |
| 786 | + break; |
| 787 | + } |
| 788 | + pszName = argv[i + dwCurrentIndex]; |
| 789 | + DPRINT1("Interface: {%08lx-%04hx-%04hx-%02x%02x-%02x%02x%02x%02x%02x%02x}\n", |
| 790 | + InterfaceGUID.Data1, InterfaceGUID.Data2, InterfaceGUID.Data3, InterfaceGUID.Data4[0], InterfaceGUID.Data4[1], |
| 791 | + InterfaceGUID.Data4[2], InterfaceGUID.Data4[3], InterfaceGUID.Data4[4], InterfaceGUID.Data4[5], InterfaceGUID.Data4[6], InterfaceGUID.Data4[7]); |
| 792 | + bHaveName = TRUE; |
| 793 | + break; |
| 794 | + |
| 795 | + case 1: /* addr */ |
| 796 | + DPRINT1("Tag: addr (%S)\n", argv[i + dwCurrentIndex]); |
| 797 | + Status = RtlIpv4StringToAddressW(argv[i + dwCurrentIndex], |
| 798 | + TRUE, |
| 799 | + &Term, |
| 800 | + &Address); |
| 801 | + if (Status != 0 /*STATUS_SUCCESS*/) |
| 802 | + { |
| 803 | + DPRINT1("RtlIpv4StringToAddressW() failed (Status 0x%08lx)\n", Status); |
| 804 | + PrintMessageFromModule(hDllInstance, |
| 805 | + IDS_ERROR_BAD_VALUE, |
| 806 | + argv[i + dwCurrentIndex], |
| 807 | + pttTags[pdwTagType[i]].pwszTag); |
| 808 | + dwError = ERROR_SUPPRESS_OUTPUT; |
| 809 | + break; |
| 810 | + } |
| 811 | + DPRINT1("IP Address: %u.%u.%u.%u\n", |
| 812 | + Address.S_un.S_un_b.s_b1, Address.S_un.S_un_b.s_b2, Address.S_un.S_un_b.s_b3, Address.S_un.S_un_b.s_b4); |
| 813 | + pszAddress = argv[i + dwCurrentIndex]; |
| 814 | + DPRINT1("IP Address: %S\n", pszAddress); |
| 815 | + bHaveAddress = TRUE; |
| 816 | + break; |
| 817 | + |
| 818 | + case 2: /* index */ |
| 819 | + DPRINT1("Tag: index (%S)\n", argv[i + dwCurrentIndex]); |
| 820 | + dwIndex = wcstoul(argv[i + dwCurrentIndex], |
| 821 | + (wchar_t**)&Term, |
| 822 | + 10); |
| 823 | + if ((dwIndex == 0) || (dwIndex > 999)) |
| 824 | + { |
| 825 | + dwError = ERROR_INVALID_PARAMETER; |
| 826 | + break; |
| 827 | + } |
| 828 | + DPRINT1("Index: %lu\n", dwIndex); |
| 829 | +// bHaveIndex = TRUE; |
| 830 | + break; |
| 831 | + |
| 832 | + default: |
| 833 | + DPRINT1("Unknown tag type %lu\n", pdwTagType[i]); |
| 834 | + break; |
| 835 | + } |
| 836 | + } |
| 837 | + |
| 838 | + if (pdwTagType) |
| 839 | + HeapFree(GetProcessHeap(), 0, pdwTagType); |
| 840 | + |
| 841 | + if (dwError != ERROR_SUCCESS) |
| 842 | + return dwError; |
| 843 | + |
| 844 | + /* Check parameters */ |
| 845 | + |
| 846 | + /* The interface name is mandatory */ |
| 847 | + if (bHaveName == FALSE) |
| 848 | + return ERROR_INVALID_SYNTAX; |
| 849 | + |
| 850 | + /* The address is mandatory */ |
| 851 | + if (!bHaveAddress) |
| 852 | + return ERROR_INVALID_SYNTAX; |
| 853 | + |
| 854 | + hr = GetInterfaceProperties(&InterfaceGUID, &pProperties); |
| 855 | + if (FAILED(hr)) |
| 856 | + { |
| 857 | + PrintMessageFromModule(hDllInstance, |
| 858 | + IDS_ERROR_GET_PROPERTIES, |
| 859 | + pszName); |
| 860 | + return ERROR_SUPPRESS_OUTPUT; |
| 861 | + } |
| 862 | + |
| 863 | + dwLength = wcslen(pProperties->pszParameters) + wcslen(pszAddress) + 2; |
| 864 | + |
| 865 | + pszNewParameters = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwLength * sizeof(WCHAR)); |
| 866 | + if (pszNewParameters == NULL) |
| 867 | + { |
| 868 | + dwError = ERROR_NOT_ENOUGH_MEMORY; |
| 869 | + goto done; |
| 870 | + } |
| 871 | + |
| 872 | + wcscpy(pszNewParameters, pProperties->pszParameters); |
| 873 | + AppendParameterValue(pszNewParameters, L"DNS", pszAddress); |
| 874 | + |
| 875 | + NewProperties.dwDhcp = 0; |
| 876 | + NewProperties.pszIpAddress = pProperties->pszIpAddress; |
| 877 | + NewProperties.pszSubnetMask = pProperties->pszSubnetMask; |
| 878 | + NewProperties.pszParameters = pszNewParameters; |
| 879 | + |
| 880 | + SetInterfaceProperties(&InterfaceGUID, &NewProperties); |
| 881 | + |
| 882 | +done: |
| 883 | + if (pszNewParameters) |
| 884 | + HeapFree(GetProcessHeap(), 0, pszNewParameters); |
| 885 | + |
| 886 | + CoTaskMemFree(pProperties); |
| 887 | + pProperties = NULL; |
| 888 | + |
| 889 | + DPRINT("IpAddDns() done (Error %lu)\n", dwError); |
| 890 | + return dwError; |
| 891 | +} |
| 892 | + |
| 893 | + |
712 | 894 | static |
713 | 895 | DWORD |
714 | 896 | WINAPI |
|
0 commit comments