Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenipconfig.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS ipconfig utility 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: apps/utils/net/ipconfig/ipconfig.c 00005 * PURPOSE: Display IP info for net adapters 00006 * PROGRAMMERS: Copyright 2005 - 2006 Ged Murphy (gedmurphy@gmail.com) 00007 */ 00008 /* 00009 * TODO: 00010 * fix renew / release 00011 * implement flushdns, registerdns, displaydns, showclassid, setclassid 00012 * allow globbing on adapter names 00013 */ 00014 00015 #define WIN32_LEAN_AND_MEAN 00016 #include <windows.h> 00017 #include <stdio.h> 00018 #include <tchar.h> 00019 #include <time.h> 00020 #include <iphlpapi.h> 00021 #include "resource.h" 00022 00023 #define GUID_LEN 40 00024 00025 HINSTANCE hInstance; 00026 HANDLE ProcessHeap; 00027 00028 int LoadStringAndOem(HINSTANCE hInst, 00029 UINT uID, 00030 LPTSTR szNode, 00031 int byteSize 00032 ) 00033 { 00034 TCHAR *szTmp; 00035 int res; 00036 00037 szTmp = (LPTSTR)HeapAlloc(ProcessHeap, 0, byteSize); 00038 if (szTmp == NULL) 00039 { 00040 return 0; 00041 } 00042 res = LoadString(hInst, uID, szTmp, byteSize); 00043 CharToOem(szTmp, szNode); 00044 HeapFree(ProcessHeap, 0, szTmp); 00045 return res; 00046 } 00047 00048 LPTSTR GetNodeTypeName(UINT NodeType) 00049 { 00050 static TCHAR szNode[14]; 00051 00052 switch (NodeType) 00053 { 00054 case 1: 00055 if (!LoadStringAndOem(hInstance, IDS_BCAST, szNode, sizeof(szNode))) 00056 return NULL; 00057 break; 00058 00059 case 2: 00060 if (!LoadStringAndOem(hInstance, IDS_P2P, szNode, sizeof(szNode))) 00061 return NULL; 00062 break; 00063 00064 case 4: 00065 if (!LoadStringAndOem(hInstance, IDS_MIXED, szNode, sizeof(szNode))) 00066 return NULL; 00067 break; 00068 00069 case 8: 00070 if (!LoadStringAndOem(hInstance, IDS_HYBRID, szNode, sizeof(szNode))) 00071 return NULL; 00072 break; 00073 00074 default : 00075 if (!LoadStringAndOem(hInstance, IDS_UNKNOWN, szNode, sizeof(szNode))) 00076 return NULL; 00077 break; 00078 } 00079 00080 return szNode; 00081 } 00082 00083 00084 LPTSTR GetInterfaceTypeName(UINT InterfaceType) 00085 { 00086 static TCHAR szIntType[25]; 00087 00088 switch (InterfaceType) 00089 { 00090 case MIB_IF_TYPE_OTHER: 00091 if (!LoadStringAndOem(hInstance, IDS_OTHER, szIntType, sizeof(szIntType))) 00092 return NULL; 00093 break; 00094 00095 case MIB_IF_TYPE_ETHERNET: 00096 if (!LoadStringAndOem(hInstance, IDS_ETH, szIntType, sizeof(szIntType))) 00097 return NULL; 00098 break; 00099 00100 case MIB_IF_TYPE_TOKENRING: 00101 if (!LoadStringAndOem(hInstance, IDS_TOKEN, szIntType, sizeof(szIntType))) 00102 return NULL; 00103 break; 00104 00105 case MIB_IF_TYPE_FDDI: 00106 if (!LoadStringAndOem(hInstance, IDS_FDDI, szIntType, sizeof(szIntType))) 00107 return NULL; 00108 break; 00109 00110 case MIB_IF_TYPE_PPP: 00111 if (!LoadStringAndOem(hInstance, IDS_PPP, szIntType, sizeof(szIntType))) 00112 return NULL; 00113 break; 00114 00115 case MIB_IF_TYPE_LOOPBACK: 00116 if (!LoadStringAndOem(hInstance, IDS_LOOP, szIntType, sizeof(szIntType))) 00117 return NULL; 00118 break; 00119 00120 case MIB_IF_TYPE_SLIP: 00121 if (!LoadStringAndOem(hInstance, IDS_SLIP, szIntType, sizeof(szIntType))) 00122 return NULL; 00123 break; 00124 00125 default: 00126 if (!LoadStringAndOem(hInstance, IDS_UNKNOWN, szIntType, sizeof(szIntType))) 00127 return NULL; 00128 break; 00129 } 00130 00131 return szIntType; 00132 } 00133 00134 00135 /* print MAC address */ 00136 PTCHAR PrintMacAddr(PBYTE Mac) 00137 { 00138 static TCHAR MacAddr[20]; 00139 00140 _stprintf(MacAddr, _T("%02x-%02x-%02x-%02x-%02x-%02x"), 00141 Mac[0], Mac[1], Mac[2], Mac[3], Mac[4], Mac[5]); 00142 00143 return MacAddr; 00144 } 00145 00146 00147 VOID DoFormatMessage(LONG ErrorCode) 00148 { 00149 LPVOID lpMsgBuf; 00150 //DWORD ErrorCode; 00151 00152 if (ErrorCode == 0) 00153 ErrorCode = GetLastError(); 00154 00155 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 00156 FORMAT_MESSAGE_FROM_SYSTEM | 00157 FORMAT_MESSAGE_IGNORE_INSERTS, 00158 NULL, 00159 ErrorCode, 00160 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ 00161 (LPTSTR) &lpMsgBuf, 00162 0, 00163 NULL)) 00164 { 00165 _tprintf(_T("%s"), (LPTSTR)lpMsgBuf); 00166 LocalFree(lpMsgBuf); 00167 } 00168 } 00169 00170 00171 LPTSTR GetConnectionType(LPTSTR lpClass) 00172 { 00173 HKEY hKey = NULL; 00174 LPTSTR ConType = NULL; 00175 LPTSTR ConTypeTmp = NULL; 00176 TCHAR Path[256]; 00177 LPTSTR PrePath = _T("SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\"); 00178 LPTSTR PostPath = _T("\\Connection"); 00179 DWORD PathSize; 00180 DWORD dwType; 00181 DWORD dwDataSize; 00182 00183 /* don't overflow the buffer */ 00184 PathSize = lstrlen(PrePath) + lstrlen(lpClass) + lstrlen(PostPath) + 1; 00185 if (PathSize >= 255) 00186 return NULL; 00187 00188 wsprintf(Path, _T("%s%s%s"), PrePath, lpClass, PostPath); 00189 00190 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, 00191 Path, 00192 0, 00193 KEY_READ, 00194 &hKey) == ERROR_SUCCESS) 00195 { 00196 if(RegQueryValueEx(hKey, 00197 _T("Name"), 00198 NULL, 00199 &dwType, 00200 NULL, 00201 &dwDataSize) == ERROR_SUCCESS) 00202 { 00203 ConTypeTmp = (LPTSTR)HeapAlloc(ProcessHeap, 00204 0, 00205 dwDataSize); 00206 00207 ConType = (LPTSTR)HeapAlloc(ProcessHeap, 00208 0, 00209 dwDataSize); 00210 if (ConType && ConTypeTmp) 00211 { 00212 if(RegQueryValueEx(hKey, 00213 _T("Name"), 00214 NULL, 00215 &dwType, 00216 (PBYTE)ConTypeTmp, 00217 &dwDataSize) != ERROR_SUCCESS) 00218 { 00219 HeapFree(ProcessHeap, 00220 0, 00221 ConType); 00222 00223 HeapFree(ProcessHeap, 00224 0, 00225 ConTypeTmp); 00226 00227 ConType = NULL; 00228 } 00229 00230 if (ConType) CharToOem(ConTypeTmp, ConType); 00231 } 00232 } 00233 } 00234 00235 if (hKey != NULL) 00236 RegCloseKey(hKey); 00237 00238 return ConType; 00239 } 00240 00241 00242 LPTSTR GetConnectionDescription(LPTSTR lpClass) 00243 { 00244 HKEY hBaseKey = NULL; 00245 HKEY hClassKey = NULL; 00246 LPTSTR lpKeyClass = NULL; 00247 LPTSTR lpConDesc = NULL; 00248 LPTSTR lpPath = NULL; 00249 TCHAR szPrePath[] = _T("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\"); 00250 DWORD dwType; 00251 DWORD dwDataSize; 00252 INT i; 00253 00254 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, 00255 szPrePath, 00256 0, 00257 KEY_READ, 00258 &hBaseKey) != ERROR_SUCCESS) 00259 { 00260 return NULL; 00261 } 00262 00263 for (i=0; ; i++) 00264 { 00265 DWORD PathSize; 00266 LONG Status; 00267 TCHAR szName[10]; 00268 DWORD NameLen = 9; 00269 00270 if ((Status = RegEnumKeyEx(hBaseKey, 00271 i, 00272 szName, 00273 &NameLen, 00274 NULL, 00275 NULL, 00276 NULL, 00277 NULL)) != ERROR_SUCCESS) 00278 { 00279 if (Status == ERROR_NO_MORE_ITEMS) 00280 { 00281 DoFormatMessage(Status); 00282 lpConDesc = NULL; 00283 goto CLEANUP; 00284 } 00285 else 00286 continue; 00287 } 00288 00289 PathSize = lstrlen(szPrePath) + lstrlen(szName) + 1; 00290 lpPath = (LPTSTR)HeapAlloc(ProcessHeap, 00291 0, 00292 PathSize * sizeof(TCHAR)); 00293 if (lpPath == NULL) 00294 goto CLEANUP; 00295 00296 wsprintf(lpPath, _T("%s%s"), szPrePath, szName); 00297 00298 //MessageBox(NULL, lpPath, NULL, 0); 00299 00300 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, 00301 lpPath, 00302 0, 00303 KEY_READ, 00304 &hClassKey) != ERROR_SUCCESS) 00305 { 00306 goto CLEANUP; 00307 } 00308 00309 HeapFree(ProcessHeap, 0, lpPath); 00310 lpPath = NULL; 00311 00312 if(RegQueryValueEx(hClassKey, 00313 _T("NetCfgInstanceId"), 00314 NULL, 00315 &dwType, 00316 NULL, 00317 &dwDataSize) == ERROR_SUCCESS) 00318 { 00319 lpKeyClass = (LPTSTR)HeapAlloc(ProcessHeap, 00320 0, 00321 dwDataSize); 00322 if (lpKeyClass == NULL) 00323 goto CLEANUP; 00324 00325 if(RegQueryValueEx(hClassKey, 00326 _T("NetCfgInstanceId"), 00327 NULL, 00328 &dwType, 00329 (PBYTE)lpKeyClass, 00330 &dwDataSize) != ERROR_SUCCESS) 00331 { 00332 lpKeyClass = NULL; 00333 HeapFree(ProcessHeap, 0, lpKeyClass); 00334 continue; 00335 } 00336 } 00337 else 00338 continue; 00339 00340 if (!lstrcmp(lpClass, lpKeyClass)) 00341 { 00342 HeapFree(ProcessHeap, 0, lpKeyClass); 00343 lpKeyClass = NULL; 00344 00345 if(RegQueryValueEx(hClassKey, 00346 _T("DriverDesc"), 00347 NULL, 00348 &dwType, 00349 NULL, 00350 &dwDataSize) == ERROR_SUCCESS) 00351 { 00352 lpConDesc = (LPTSTR)HeapAlloc(ProcessHeap, 00353 0, 00354 dwDataSize); 00355 if (lpConDesc == NULL) 00356 goto CLEANUP; 00357 00358 if(RegQueryValueEx(hClassKey, 00359 _T("DriverDesc"), 00360 NULL, 00361 &dwType, 00362 (PBYTE)lpConDesc, 00363 &dwDataSize) != ERROR_SUCCESS) 00364 { 00365 lpConDesc = NULL; 00366 goto CLEANUP; 00367 } 00368 } 00369 else 00370 lpConDesc = NULL; 00371 00372 break; 00373 } 00374 } 00375 00376 CLEANUP: 00377 if (hBaseKey != NULL) 00378 RegCloseKey(hBaseKey); 00379 if (hClassKey != NULL) 00380 RegCloseKey(hClassKey); 00381 if (lpConDesc != NULL) 00382 HeapFree(ProcessHeap, 0, lpPath); 00383 if (lpConDesc != NULL) 00384 HeapFree(ProcessHeap, 0, lpKeyClass); 00385 00386 return lpConDesc; 00387 } 00388 00389 00390 VOID ShowInfo(BOOL bAll) 00391 { 00392 MIB_IFROW mibEntry; 00393 PIP_ADAPTER_INFO pAdapterInfo = NULL; 00394 PIP_ADAPTER_INFO pAdapter = NULL; 00395 ULONG adaptOutBufLen = 0; 00396 PFIXED_INFO pFixedInfo = NULL; 00397 ULONG netOutBufLen = 0; 00398 ULONG ret = 0; 00399 00400 /* call GetAdaptersInfo to obtain the adapter info */ 00401 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen); 00402 if (ret == ERROR_BUFFER_OVERFLOW) 00403 { 00404 pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen); 00405 if (pAdapterInfo == NULL) 00406 return; 00407 00408 ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen); 00409 if (ret != NO_ERROR) 00410 { 00411 DoFormatMessage(0); 00412 HeapFree(ProcessHeap, 0, pAdapterInfo); 00413 return; 00414 } 00415 } 00416 else 00417 { 00418 if( ERROR_NO_DATA != ret ) 00419 { 00420 DoFormatMessage(0); 00421 return; 00422 } 00423 } 00424 00425 /* call GetNetworkParams to obtain the network info */ 00426 if(GetNetworkParams(pFixedInfo, &netOutBufLen) == ERROR_BUFFER_OVERFLOW) 00427 { 00428 pFixedInfo = (FIXED_INFO *)HeapAlloc(ProcessHeap, 0, netOutBufLen); 00429 if (pFixedInfo == NULL) 00430 { 00431 if (pAdapterInfo) 00432 HeapFree(ProcessHeap, 0, pAdapterInfo); 00433 return; 00434 } 00435 if (GetNetworkParams(pFixedInfo, &netOutBufLen) != NO_ERROR) 00436 { 00437 DoFormatMessage(0); 00438 if (pAdapterInfo) 00439 HeapFree(ProcessHeap, 0, pAdapterInfo); 00440 HeapFree(ProcessHeap, 0, pFixedInfo); 00441 return; 00442 } 00443 } 00444 else 00445 { 00446 if (pAdapterInfo) 00447 HeapFree(ProcessHeap, 0, pAdapterInfo); 00448 DoFormatMessage(0); 00449 return; 00450 } 00451 00452 pAdapter = pAdapterInfo; 00453 00454 _tprintf(_T("\nReactOS IP Configuration\n\n")); 00455 if (bAll) 00456 { 00457 _tprintf(_T("\tHost Name . . . . . . . . . . . . : %s\n"), pFixedInfo->HostName); 00458 _tprintf(_T("\tPrimary DNS Suffix. . . . . . . . : \n")); 00459 _tprintf(_T("\tNode Type . . . . . . . . . . . . : %s\n"), GetNodeTypeName(pFixedInfo->NodeType)); 00460 if (pFixedInfo->EnableRouting) 00461 _tprintf(_T("\tIP Routing Enabled. . . . . . . . : Yes\n")); 00462 else 00463 _tprintf(_T("\tIP Routing Enabled. . . . . . . . : No\n")); 00464 if (pAdapter && pAdapter->HaveWins) 00465 _tprintf(_T("\tWINS Proxy enabled. . . . . . . . : Yes\n")); 00466 else 00467 _tprintf(_T("\tWINS Proxy enabled. . . . . . . . : No\n")); 00468 _tprintf(_T("\tDNS Suffix Search List. . . . . . : %s\n"), pFixedInfo->DomainName); 00469 } 00470 00471 while (pAdapter) 00472 { 00473 LPTSTR IntType, myConType; 00474 00475 mibEntry.dwIndex = pAdapter->Index; 00476 GetIfEntry(&mibEntry); 00477 00478 IntType = GetInterfaceTypeName(pAdapter->Type); 00479 myConType = GetConnectionType(pAdapter->AdapterName); 00480 00481 _tprintf(_T("\n%s %s: \n\n"), IntType , myConType); 00482 00483 if (myConType != NULL) HeapFree(ProcessHeap, 0, myConType); 00484 00485 /* check if the adapter is connected to the media */ 00486 if (mibEntry.dwOperStatus != MIB_IF_OPER_STATUS_CONNECTED && mibEntry.dwOperStatus != MIB_IF_OPER_STATUS_OPERATIONAL) 00487 { 00488 _tprintf(_T("\tMedia State . . . . . . . . . . . : Media disconnected\n")); 00489 pAdapter = pAdapter->Next; 00490 continue; 00491 } 00492 00493 _tprintf(_T("\tConnection-specific DNS Suffix. . : %s\n"), pFixedInfo->DomainName); 00494 00495 if (bAll) 00496 { 00497 LPTSTR lpDesc = GetConnectionDescription(pAdapter->AdapterName); 00498 _tprintf(_T("\tDescription . . . . . . . . . . . : %s\n"), lpDesc); 00499 HeapFree(ProcessHeap, 0, lpDesc); 00500 _tprintf(_T("\tPhysical Address. . . . . . . . . : %s\n"), PrintMacAddr(pAdapter->Address)); 00501 if (pAdapter->DhcpEnabled) 00502 _tprintf(_T("\tDHCP Enabled. . . . . . . . . . . : Yes\n")); 00503 else 00504 _tprintf(_T("\tDHCP Enabled. . . . . . . . . . . : No\n")); 00505 _tprintf(_T("\tAutoconfiguration Enabled . . . . : \n")); 00506 } 00507 00508 _tprintf(_T("\tIP Address. . . . . . . . . . . . : %s\n"), pAdapter->IpAddressList.IpAddress.String); 00509 _tprintf(_T("\tSubnet Mask . . . . . . . . . . . : %s\n"), pAdapter->IpAddressList.IpMask.String); 00510 if (pAdapter->GatewayList.IpAddress.String[0] != '0') 00511 _tprintf(_T("\tDefault Gateway . . . . . . . . . : %s\n"), pAdapter->GatewayList.IpAddress.String); 00512 else 00513 _tprintf(_T("\tDefault Gateway . . . . . . . . . :\n")); 00514 00515 if (bAll) 00516 { 00517 PIP_ADDR_STRING pIPAddr; 00518 00519 if (pAdapter->DhcpEnabled) 00520 _tprintf(_T("\tDHCP Server . . . . . . . . . . . : %s\n"), pAdapter->DhcpServer.IpAddress.String); 00521 00522 _tprintf(_T("\tDNS Servers . . . . . . . . . . . : ")); 00523 _tprintf(_T("%s\n"), pFixedInfo->DnsServerList.IpAddress.String); 00524 pIPAddr = pFixedInfo->DnsServerList.Next; 00525 while (pIPAddr) 00526 { 00527 _tprintf(_T("\t\t\t\t\t %s\n"), pIPAddr ->IpAddress.String ); 00528 pIPAddr = pIPAddr->Next; 00529 } 00530 00531 if (pAdapter->HaveWins) 00532 { 00533 _tprintf(_T("\tPrimary WINS Server . . . . . . . : %s\n"), pAdapter->PrimaryWinsServer.IpAddress.String); 00534 _tprintf(_T("\tSecondard WINS Server . . . . . . : %s\n"), pAdapter->SecondaryWinsServer.IpAddress.String); 00535 } 00536 00537 if (pAdapter->DhcpEnabled) 00538 { 00539 _tprintf(_T("\tLease Obtained. . . . . . . . . . : %s"), _tasctime(localtime(&pAdapter->LeaseObtained))); 00540 _tprintf(_T("\tLease Expires . . . . . . . . . . : %s"), _tasctime(localtime(&pAdapter->LeaseExpires))); 00541 } 00542 } 00543 _tprintf(_T("\n")); 00544 00545 pAdapter = pAdapter->Next; 00546 00547 } 00548 00549 HeapFree(ProcessHeap, 0, pFixedInfo); 00550 if (pAdapterInfo) 00551 HeapFree(ProcessHeap, 0, pAdapterInfo); 00552 } 00553 00554 VOID Release(LPTSTR Index) 00555 { 00556 IP_ADAPTER_INDEX_MAP AdapterInfo; 00557 DWORD ret; 00558 DWORD i; 00559 00560 /* if interface is not given, query GetInterfaceInfo */ 00561 if (Index == NULL) 00562 { 00563 PIP_INTERFACE_INFO pInfo = NULL; 00564 ULONG ulOutBufLen = 0; 00565 00566 if (GetInterfaceInfo(pInfo, &ulOutBufLen) == ERROR_INSUFFICIENT_BUFFER) 00567 { 00568 pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, ulOutBufLen); 00569 if (pInfo == NULL) 00570 return; 00571 00572 if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR ) 00573 { 00574 for (i = 0; i < pInfo->NumAdapters; i++) 00575 { 00576 CopyMemory(&AdapterInfo, &pInfo->Adapter[i], sizeof(IP_ADAPTER_INDEX_MAP)); 00577 _tprintf(_T("name - %S\n"), pInfo->Adapter[i].Name); 00578 00579 /* Call IpReleaseAddress to release the IP address on the specified adapter. */ 00580 if ((ret = IpReleaseAddress(&AdapterInfo)) != NO_ERROR) 00581 { 00582 _tprintf(_T("\nAn error occured while releasing interface %S : \n"), AdapterInfo.Name); 00583 DoFormatMessage(ret); 00584 } 00585 } 00586 00587 HeapFree(ProcessHeap, 0, pInfo); 00588 } 00589 else 00590 { 00591 DoFormatMessage(0); 00592 HeapFree(ProcessHeap, 0, pInfo); 00593 return; 00594 } 00595 } 00596 else 00597 { 00598 DoFormatMessage(0); 00599 return; 00600 } 00601 } 00602 else 00603 { 00604 ; 00605 /* FIXME: 00606 * we need to be able to release connections by name with support for globbing 00607 * i.e. ipconfig /release Eth* will release all cards starting with Eth... 00608 * ipconfig /release *con* will release all cards with 'con' in their name 00609 */ 00610 } 00611 } 00612 00613 00614 00615 00616 VOID Renew(LPTSTR Index) 00617 { 00618 IP_ADAPTER_INDEX_MAP AdapterInfo; 00619 DWORD i; 00620 00621 /* if interface is not given, query GetInterfaceInfo */ 00622 if (Index == NULL) 00623 { 00624 PIP_INTERFACE_INFO pInfo; 00625 ULONG ulOutBufLen = 0; 00626 00627 pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, sizeof(IP_INTERFACE_INFO)); 00628 if (pInfo == NULL) 00629 { 00630 _tprintf(_T("memory allocation error")); 00631 return; 00632 } 00633 00634 /* Make an initial call to GetInterfaceInfo to get 00635 * the necessary size into the ulOutBufLen variable */ 00636 if ( GetInterfaceInfo(pInfo, &ulOutBufLen) == ERROR_INSUFFICIENT_BUFFER) 00637 { 00638 HeapFree(ProcessHeap, 0, pInfo); 00639 pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, ulOutBufLen); 00640 if (pInfo == NULL) 00641 { 00642 _tprintf(_T("memory allocation error")); 00643 return; 00644 } 00645 } 00646 00647 /* Make a second call to GetInterfaceInfo to get the actual data we want */ 00648 if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR ) 00649 { 00650 for (i = 0; i < pInfo->NumAdapters; i++) 00651 { 00652 CopyMemory(&AdapterInfo, &pInfo->Adapter[i], sizeof(IP_ADAPTER_INDEX_MAP)); 00653 _tprintf(_T("name - %S\n"), pInfo->Adapter[i].Name); 00654 00655 00656 /* Call IpRenewAddress to renew the IP address on the specified adapter. */ 00657 if (IpRenewAddress(&AdapterInfo) != NO_ERROR) 00658 { 00659 _tprintf(_T("\nAn error occured while renew interface %s : "), _T("*name*")); 00660 DoFormatMessage(0); 00661 } 00662 } 00663 } 00664 else 00665 { 00666 _tprintf(_T("\nGetInterfaceInfo failed : ")); 00667 DoFormatMessage(0); 00668 } 00669 00670 HeapFree(ProcessHeap, 0, pInfo); 00671 } 00672 else 00673 { 00674 ; 00675 /* FIXME: 00676 * we need to be able to renew connections by name with support for globbing 00677 * i.e. ipconfig /renew Eth* will renew all cards starting with Eth... 00678 * ipconfig /renew *con* will renew all cards with 'con' in their name 00679 */ 00680 } 00681 } 00682 00683 00684 00685 VOID Usage(VOID) 00686 { 00687 HRSRC hRes; 00688 LPTSTR lpUsage; 00689 DWORD Size; 00690 00691 LPTSTR lpName = (LPTSTR)MAKEINTRESOURCE((IDS_USAGE >> 4) + 1); 00692 00693 hRes = FindResource(hInstance, 00694 lpName, 00695 RT_STRING); 00696 if (hRes != NULL) 00697 { 00698 if ((Size = SizeofResource(hInstance, 00699 hRes))) 00700 { 00701 lpUsage = (LPTSTR)HeapAlloc(ProcessHeap, 00702 0, 00703 Size); 00704 if (lpUsage == NULL) 00705 return; 00706 00707 if (LoadStringAndOem(hInstance, 00708 IDS_USAGE, 00709 lpUsage, 00710 Size)) 00711 { 00712 _tprintf(_T("%s"), lpUsage); 00713 } 00714 } 00715 } 00716 00717 00718 } 00719 00720 int main(int argc, char *argv[]) 00721 { 00722 BOOL DoUsage=FALSE; 00723 BOOL DoAll=FALSE; 00724 BOOL DoRelease=FALSE; 00725 BOOL DoRenew=FALSE; 00726 BOOL DoFlushdns=FALSE; 00727 BOOL DoRegisterdns=FALSE; 00728 BOOL DoDisplaydns=FALSE; 00729 BOOL DoShowclassid=FALSE; 00730 BOOL DoSetclassid=FALSE; 00731 00732 hInstance = GetModuleHandle(NULL); 00733 ProcessHeap = GetProcessHeap(); 00734 00735 /* Parse command line for options we have been given. */ 00736 if ( (argc > 1)&&(argv[1][0]=='/' || argv[1][0]=='-') ) 00737 { 00738 if( !_tcsicmp( &argv[1][1], _T("?") )) 00739 { 00740 DoUsage = TRUE; 00741 } 00742 else if( !_tcsnicmp( &argv[1][1], _T("ALL"), _tcslen(&argv[1][1]) )) 00743 { 00744 DoAll = TRUE; 00745 } 00746 else if( !_tcsnicmp( &argv[1][1], _T("RELEASE"), _tcslen(&argv[1][1]) )) 00747 { 00748 DoRelease = TRUE; 00749 } 00750 else if( ! _tcsnicmp( &argv[1][1], _T("RENEW"), _tcslen(&argv[1][1]) )) 00751 { 00752 DoRenew = TRUE; 00753 } 00754 else if( ! _tcsnicmp( &argv[1][1], _T("FLUSHDNS"), _tcslen(&argv[1][1]) )) 00755 { 00756 DoFlushdns = TRUE; 00757 } 00758 else if( ! _tcsnicmp( &argv[1][1], _T("FLUSHREGISTERDNS"), _tcslen(&argv[1][1]) )) 00759 { 00760 DoRegisterdns = TRUE; 00761 } 00762 else if( ! _tcsnicmp( &argv[1][1], _T("DISPLAYDNS"), _tcslen(&argv[1][1]) )) 00763 { 00764 DoDisplaydns = TRUE; 00765 } 00766 else if( ! _tcsnicmp( &argv[1][1], _T("SHOWCLASSID"), _tcslen(&argv[1][1]) )) 00767 { 00768 DoShowclassid = TRUE; 00769 } 00770 else if( ! _tcsnicmp( &argv[1][1], _T("SETCLASSID"), _tcslen(&argv[1][1]) )) 00771 { 00772 DoSetclassid = TRUE; 00773 } 00774 } 00775 00776 switch (argc) 00777 { 00778 case 1: /* Default behaviour if no options are given*/ 00779 ShowInfo(FALSE); 00780 break; 00781 case 2: /* Process all the options that take no parameters */ 00782 if (DoUsage) 00783 Usage(); 00784 else if (DoAll) 00785 ShowInfo(TRUE); 00786 else if (DoRelease) 00787 Release(NULL); 00788 else if (DoRenew) 00789 Renew(NULL); 00790 else if (DoFlushdns) 00791 _tprintf(_T("\nSorry /flushdns is not implemented yet\n")); 00792 else if (DoRegisterdns) 00793 _tprintf(_T("\nSorry /registerdns is not implemented yet\n")); 00794 else if (DoDisplaydns) 00795 _tprintf(_T("\nSorry /displaydns is not implemented yet\n")); 00796 else 00797 Usage(); 00798 break; 00799 case 3: /* Process all the options that can have 1 parameter */ 00800 if (DoRelease) 00801 _tprintf(_T("\nSorry /release [adapter] is not implemented yet\n")); 00802 //Release(argv[2]); 00803 else if (DoRenew) 00804 _tprintf(_T("\nSorry /renew [adapter] is not implemented yet\n")); 00805 else if (DoShowclassid) 00806 _tprintf(_T("\nSorry /showclassid adapter is not implemented yet\n")); 00807 else if (DoSetclassid) 00808 _tprintf(_T("\nSorry /setclassid adapter is not implemented yet\n")); 00809 else 00810 Usage(); 00811 break; 00812 case 4: /* Process all the options that can have 2 parameters */ 00813 if (DoSetclassid) 00814 _tprintf(_T("\nSorry /setclassid adapter [classid]is not implemented yet\n")); 00815 else 00816 Usage(); 00817 break; 00818 default: 00819 Usage(); 00820 } 00821 00822 return 0; 00823 } 00824 Generated on Fri May 25 2012 04:15:31 for ReactOS by
1.7.6.1
|