2 * ipconfig - display IP stack parameters.
4 * This source code is in the PUBLIC DOMAIN and has NO WARRANTY.
6 * Robert Dickenson <robd@reactos.org>, August 15, 2002.
21 ////////////////////////////////////////////////////////////////////////////////
23 /* imported from iphlpapi.dll
28 NhGetInterfaceNameFromGuid
29 NhpAllocateAndGetInterfaceInfoFromStack
33 static TCHAR
* GetNodeTypeName(int nNodeType
)
36 case 0: return _T("zero");
37 case 1: return _T("one");
38 case 2: return _T("two");
39 case 3: return _T("three");
40 case 4: return _T("mixed");
41 default: return _T("unknown");
45 static void ShowNetworkFixedInfo()
47 FIXED_INFO
* pFixedInfo
= NULL
;
51 result
= GetNetworkParams(NULL
, &OutBufLen
);
52 if (result
== ERROR_BUFFER_OVERFLOW
) {
53 pFixedInfo
= (FIXED_INFO
*)malloc(OutBufLen
);
55 _tprintf(_T("ERROR: failed to allocate 0x%08X bytes of memory\n"), OutBufLen
);
59 _tprintf(_T("ERROR: GetNetworkParams() failed to report required buffer size.\n"));
63 result
= GetNetworkParams(pFixedInfo
, &OutBufLen
);
64 if (result
== ERROR_SUCCESS
) {
65 IP_ADDR_STRING
* pIPAddr
;
67 printf("\tHostName. . . . . . . . . . . : %s\n", pFixedInfo
->HostName
);
68 printf("\tDomainName. . . . . . . . . . : %s\n", pFixedInfo
->DomainName
);
70 printf("\tDNS Servers . . . . . . . . . : %s\n", pFixedInfo
->DnsServerList
.IpAddress
.String
);
71 pIPAddr
= pFixedInfo
->DnsServerList
.Next
;
73 printf("\t\t\t\t : %s\n", pIPAddr
->IpAddress
.String
);
74 pIPAddr
= pIPAddr
->Next
;
77 _tprintf(_T("\tNodeType. . . . . . . . . . . : %d (%s)\n"), pFixedInfo
->NodeType
, GetNodeTypeName(pFixedInfo
->NodeType
));
78 printf("\tScopeId . . . . . . . . . . . : %s\n", pFixedInfo
->ScopeId
);
79 _tprintf(_T("\tEnableRouting . . . . . . . . : %s\n"), pFixedInfo
->EnableRouting
? _T("yes") : _T("no"));
80 _tprintf(_T("\tEnableProxy . . . . . . . . . : %s\n"), pFixedInfo
->EnableProxy
? _T("yes") : _T("no"));
81 _tprintf(_T("\tEnableDns . . . . . . . . . . : %s\n"), pFixedInfo
->EnableDns
? _T("yes") : _T("no"));
83 //_tprintf(_T("\n"),);
84 //_tprintf(_T("GetNetworkParams() returned with %d\n"), pIfTable->NumAdapters);
86 // _tprintf(_T("\tConnection specific DNS suffix: %s\n"), pFixedInfo->EnableDns ? _T("yes") : _T("no"));
90 case ERROR_BUFFER_OVERFLOW
:
91 _tprintf(_T("The buffer size indicated by the pOutBufLen parameter is too small to hold the adapter information. The pOutBufLen parameter points to the required size\n"));
93 case ERROR_INVALID_PARAMETER
:
94 _tprintf(_T("The pOutBufLen parameter is NULL, or the calling process does not have read/write access to the memory pointed to by pOutBufLen, or the calling process does not have write access to the memory pointed to by the pAdapterInfo parameter\n"));
97 _tprintf(_T("No adapter information exists for the local computer\n"));
99 case ERROR_NOT_SUPPORTED
:
100 _tprintf(_T("This function is not supported on the operating system in use on the local system\n"));
103 _tprintf(_T("0x%08X - Use FormatMessage to obtain the message string for the returned error\n"), result
);
109 static void ShowNetworkInterfaces()
111 IP_INTERFACE_INFO
* pIfTable
= NULL
;
114 DWORD dwOutBufLen
= 0;
116 if ((result
= GetNumberOfInterfaces(&dwNumIf
)) != NO_ERROR
) {
117 _tprintf(_T("GetNumberOfInterfaces() failed with code 0x%08X - Use FormatMessage to obtain the message string for the returned error\n"), result
);
120 _tprintf(_T("GetNumberOfInterfaces() returned %d\n"), dwNumIf
);
123 result
= GetInterfaceInfo(pIfTable
, &dwOutBufLen
);
124 // dwOutBufLen = sizeof(IP_INTERFACE_INFO) + dwNumIf * sizeof(IP_ADAPTER_INDEX_MAP);
125 // _tprintf(_T("GetNumberOfInterfaces() returned %d, dwOutBufLen %d\n"), dwNumIf, dwOutBufLen);
126 // _tprintf(_T("sizeof(IP_INTERFACE_INFO) %d, sizeof(IP_ADAPTER_INDEX_MAP) %d\n"), sizeof(IP_INTERFACE_INFO), sizeof(IP_ADAPTER_INDEX_MAP));
128 pIfTable
= (IP_INTERFACE_INFO
*)malloc(dwOutBufLen
);
130 _tprintf(_T("ERROR: failed to allocate 0x%08X bytes of memory\n"), dwOutBufLen
);
134 typedef struct _IP_ADAPTER_INDEX_MAP {
135 ULONG Index; // adapter index
136 WCHAR Name[MAX_ADAPTER_NAME]; // name of the adapter
137 } IP_ADAPTER_INDEX_MAP, * PIP_ADAPTER_INDEX_MAP;
139 typedef struct _IP_INTERFACE_INFO {
140 LONG NumAdapters; // number of adapters in array
141 IP_ADAPTER_INDEX_MAP Adapter[1]; // adapter indices and names
142 } IP_INTERFACE_INFO,*PIP_INTERFACE_INFO;
144 result
= GetInterfaceInfo(pIfTable
, &dwOutBufLen
);
145 if (result
== NO_ERROR
) {
147 _tprintf(_T("GetInterfaceInfo() returned with %d adaptor entries\n"), pIfTable
->NumAdapters
);
148 for (i
= 0; i
< pIfTable
->NumAdapters
; i
++) {
149 wprintf(L
"[%d] %s\n", i
+ 1, pIfTable
->Adapter
[i
].Name
);
150 //wprintf(L"[%d] %s\n", pIfTable->Adapter[i].Index, pIfTable->Adapter[i].Name);
152 // \DEVICE\TCPIP_{DB0E61C1-3498-4C5F-B599-59CDE8A1E357}
153 // \DEVICE\TCPIP_{BD445697-0945-4591-AE7F-2AB0F383CA87}
154 // \DEVICE\TCPIP_{6D87DC08-6BC5-4E78-AB5F-18CAB785CFFE}
156 //HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\Interfaces\Tcpip_{DB0E61C1-3498-4C5F-B599-59CDE8A1E357}
160 case ERROR_INVALID_PARAMETER
:
161 _tprintf(_T("The dwOutBufLen parameter is NULL, or GetInterfaceInterface is unable to write to the memory pointed to by the dwOutBufLen parameter\n"));
163 case ERROR_INSUFFICIENT_BUFFER
:
164 _tprintf(_T("The buffer pointed to by the pIfTable parameter is not large enough. The required size is returned in the DWORD variable pointed to by the dwOutBufLen parameter\n"));
165 _tprintf(_T("\tdwOutBufLen: %d\n"), dwOutBufLen
);
167 case ERROR_NOT_SUPPORTED
:
168 _tprintf(_T("This function is not supported on the operating system in use on the local system\n"));
171 _tprintf(_T("0x%08X - Use FormatMessage to obtain the message string for the returned error\n"), result
);
179 typedef struct _IP_ADAPTER_INFO {
180 struct _IP_ADAPTER_INFO* Next;
182 char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
183 1 char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];
185 2 BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH];
189 5 PIP_ADDR_STRING CurrentIpAddress;
190 IP_ADDR_STRING IpAddressList;
191 7 IP_ADDR_STRING GatewayList;
192 8 IP_ADDR_STRING DhcpServer;
194 IP_ADDR_STRING PrimaryWinsServer;
195 IP_ADDR_STRING SecondaryWinsServer;
196 a time_t LeaseObtained;
197 b time_t LeaseExpires;
198 } IP_ADAPTER_INFO, *PIP_ADAPTER_INFO;
201 Ethernet adapter VMware Virtual Ethernet Adapter (Network Address Translation (NAT) for VMnet8):
203 Connection-specific DNS Suffix . :
204 1 Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter (Network Address Translation (NAT) for VMnet8)
205 2 Physical Address. . . . . . . . . : 00-50-56-C0-00-08
206 3 DHCP Enabled. . . . . . . . . . . : Yes
207 Autoconfiguration Enabled . . . . : Yes
208 5 IP Address. . . . . . . . . . . . : 192.168.136.1
209 Subnet Mask . . . . . . . . . . . : 255.255.255.0
210 7 Default Gateway . . . . . . . . . :
211 8 DHCP Server . . . . . . . . . . . : 192.168.136.254
212 DNS Servers . . . . . . . . . . . :
213 a Lease Obtained. . . . . . . . . . : Monday, 30 December 2002 5:56:53 PM
214 b Lease Expires . . . . . . . . . . : Monday, 30 December 2002 6:26:53 PM
216 static void ShowAdapterInfo()
218 IP_ADAPTER_INFO
* pAdaptorInfo
;
222 _tprintf(_T("\nAdaptor Information\t\n"));
223 pAdaptorInfo
= (IP_ADAPTER_INFO
*)GlobalAlloc(GPTR
, sizeof(IP_ADAPTER_INFO
));
224 ulOutBufLen
= sizeof(IP_ADAPTER_INFO
);
226 if (ERROR_BUFFER_OVERFLOW
== GetAdaptersInfo(pAdaptorInfo
, &ulOutBufLen
)) {
227 GlobalFree(pAdaptorInfo
);
228 pAdaptorInfo
= (IP_ADAPTER_INFO
*)GlobalAlloc(GPTR
, ulOutBufLen
);
230 if (dwRetVal
= GetAdaptersInfo(pAdaptorInfo
, &ulOutBufLen
)) {
231 _tprintf(_T("Call to GetAdaptersInfo failed. Return Value: %08x\n"), dwRetVal
);
233 while (pAdaptorInfo
) {
234 printf(" AdapterName: %s\n", pAdaptorInfo
->AdapterName
);
235 printf(" Description: %s\n", pAdaptorInfo
->Description
);
236 pAdaptorInfo
= pAdaptorInfo
->Next
;
241 const char szUsage
[] = { "USAGE:\n" \
242 " ipconfig [/? | /all | /release [adapter] | /renew [adapter]\n" \
243 " | /flushdns | /registerdns\n" \
244 " | /showclassid adapter\n" \
245 " | /showclassid adapter\n" \
246 " | /setclassid adapter [classidtoset] ]\n" \
248 "adapter Full name or pattern with '*' and '?' to 'match',\n" \
249 " * matches any character, ? matches one character.\n" \
251 " /? Display this help message.\n" \
252 " /all Display full configuration information.\n" \
253 " /release Release the IP address for the specified adapter.\n" \
254 " /renew Renew the IP address for the specified adapter.\n" \
255 " /flushdns Purges the DNS Resolver cache.\n" \
256 " /registerdns Refreshes all DHCP leases and re-registers DNS names\n" \
257 " /displaydns Display the contents of the DNS Resolver Cache.\n" \
258 " /showclassid Displays all the dhcp class IDs allowed for adapter.\n" \
259 " /setclassid Modifies the dhcp class id.\n" \
261 "The default is to display only the IP address, subnet mask and\n" \
262 "default gateway for each adapter bound to TCP/IP.\n"
266 "For Release and Renew, if no adapter name is specified, then the IP address\n" \
267 "leases for all adapters bound to TCP/IP will be released or renewed.\n" \
269 "For SetClassID, if no class id is specified, then the classid is removed.\n" \
272 " > ipconfig ... Show information.\n" \
273 " > ipconfig /all ... Show detailed information\n" \
274 " > ipconfig /renew ... renew all adapaters\n" \
275 " > ipconfig /renew EL* ... renew adapters named EL....\n" \
276 " > ipconfig /release *ELINK?21* ... release all matching adapters,\n" \
277 eg. ELINK-21, myELELINKi21adapter.\n"
280 static void usage(void)
282 fputs(szUsage
, stderr
);
286 int main(int argc
, char *argv
[])
288 // 10.0.0.100 // As of build 0.0.20 this is hardcoded in the ip stack
294 _tprintf(_T("ReactOS IP Configuration\n"));
295 ShowNetworkFixedInfo();
296 ShowNetworkInterfaces();