HINSTANCE hInstance;
HANDLE ProcessHeap;
+int LoadStringAndOem(HINSTANCE hInst,
+ UINT uID,
+ LPTSTR szNode,
+ int Siz
+)
+{
+ TCHAR szTmp[25];
+ int res = LoadString(hInst, uID, szTmp, sizeof(szTmp));
+ CharToOem(szTmp, szNode);
+ return(res);
+}
LPTSTR GetNodeTypeName(UINT NodeType)
{
switch (NodeType)
{
case 1:
- if (!LoadString(hInstance, IDS_BCAST, szNode, sizeof(szNode)))
+ if (!LoadStringAndOem(hInstance, IDS_BCAST, szNode, sizeof(szNode)))
return NULL;
break;
case 2:
- if (!LoadString(hInstance, IDS_P2P, szNode, sizeof(szNode)))
+ if (!LoadStringAndOem(hInstance, IDS_P2P, szNode, sizeof(szNode)))
return NULL;
break;
case 4:
- if (!LoadString(hInstance, IDS_MIXED, szNode, sizeof(szNode)))
+ if (!LoadStringAndOem(hInstance, IDS_MIXED, szNode, sizeof(szNode)))
return NULL;
break;
case 8:
- if (!LoadString(hInstance, IDS_HYBRID, szNode, sizeof(szNode)))
+ if (!LoadStringAndOem(hInstance, IDS_HYBRID, szNode, sizeof(szNode)))
return NULL;
break;
default :
- if (!LoadString(hInstance, IDS_UNKNOWN, szNode, sizeof(szNode)))
+ if (!LoadStringAndOem(hInstance, IDS_UNKNOWN, szNode, sizeof(szNode)))
return NULL;
break;
}
switch (InterfaceType)
{
case MIB_IF_TYPE_OTHER:
- if (!LoadString(hInstance, IDS_OTHER, szIntType, sizeof(szIntType)))
+ if (!LoadStringAndOem(hInstance, IDS_OTHER, szIntType, sizeof(szIntType)))
return NULL;
break;
case MIB_IF_TYPE_ETHERNET:
- if (!LoadString(hInstance, IDS_ETH, szIntType, sizeof(szIntType)))
+ if (!LoadStringAndOem(hInstance, IDS_ETH, szIntType, sizeof(szIntType)))
return NULL;
break;
case MIB_IF_TYPE_TOKENRING:
- if (!LoadString(hInstance, IDS_TOKEN, szIntType, sizeof(szIntType)))
+ if (!LoadStringAndOem(hInstance, IDS_TOKEN, szIntType, sizeof(szIntType)))
return NULL;
break;
case MIB_IF_TYPE_FDDI:
- if (!LoadString(hInstance, IDS_FDDI, szIntType, sizeof(szIntType)))
+ if (!LoadStringAndOem(hInstance, IDS_FDDI, szIntType, sizeof(szIntType)))
return NULL;
break;
case MIB_IF_TYPE_PPP:
- if (!LoadString(hInstance, IDS_PPP, szIntType, sizeof(szIntType)))
+ if (!LoadStringAndOem(hInstance, IDS_PPP, szIntType, sizeof(szIntType)))
return NULL;
break;
case MIB_IF_TYPE_LOOPBACK:
- if (!LoadString(hInstance, IDS_LOOP, szIntType, sizeof(szIntType)))
+ if (!LoadStringAndOem(hInstance, IDS_LOOP, szIntType, sizeof(szIntType)))
return NULL;
break;
case MIB_IF_TYPE_SLIP:
- if (!LoadString(hInstance, IDS_SLIP, szIntType, sizeof(szIntType)))
+ if (!LoadStringAndOem(hInstance, IDS_SLIP, szIntType, sizeof(szIntType)))
return NULL;
break;
default:
- if (!LoadString(hInstance, IDS_UNKNOWN, szIntType, sizeof(szIntType)))
+ if (!LoadStringAndOem(hInstance, IDS_UNKNOWN, szIntType, sizeof(szIntType)))
return NULL;
break;
}
{
HKEY hKey = NULL;
LPTSTR ConType = NULL;
+ LPTSTR ConTypeTmp = NULL;
TCHAR Path[256];
LPTSTR PrePath = _T("SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\");
LPTSTR PostPath = _T("\\Connection");
NULL,
&dwDataSize) == ERROR_SUCCESS)
{
- ConType = (LPTSTR)HeapAlloc(ProcessHeap,
+ ConTypeTmp = (LPTSTR)HeapAlloc(ProcessHeap,
0,
dwDataSize);
- if (ConType == NULL)
- return NULL;
- if(RegQueryValueEx(hKey,
- _T("Name"),
- NULL,
- &dwType,
- (PBYTE)ConType,
- &dwDataSize) != ERROR_SUCCESS)
+ ConType = (LPTSTR)HeapAlloc(ProcessHeap,
+ 0,
+ dwDataSize);
+ if (ConType && ConTypeTmp)
{
- ConType = NULL;
+ if(RegQueryValueEx(hKey,
+ _T("Name"),
+ NULL,
+ &dwType,
+ (PBYTE)ConTypeTmp,
+ &dwDataSize) != ERROR_SUCCESS)
+ {
+ HeapFree(ProcessHeap,
+ 0,
+ ConType);
+
+ HeapFree(ProcessHeap,
+ 0,
+ ConTypeTmp);
+
+ ConType = NULL;
+ }
+
+ if (ConType) CharToOem(ConTypeTmp, ConType);
}
}
}
VOID ShowInfo(BOOL bAll)
{
+ MIB_IFROW mibEntry;
PIP_ADAPTER_INFO pAdapterInfo = NULL;
PIP_ADAPTER_INFO pAdapter = NULL;
ULONG adaptOutBufLen = 0;
PFIXED_INFO pFixedInfo = NULL;
ULONG netOutBufLen = 0;
+ ULONG ret = 0;
/* call GetAdaptersInfo to obtain the adapter info */
- if (GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen) == ERROR_BUFFER_OVERFLOW)
+ ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
+ if (ret == ERROR_BUFFER_OVERFLOW)
{
pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
if (pAdapterInfo == NULL)
return;
- if (GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen) != NO_ERROR)
+ ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
+ if (ret != NO_ERROR)
{
DoFormatMessage(0);
HeapFree(ProcessHeap, 0, pAdapterInfo);
}
else
{
- DoFormatMessage(0);
- return;
+ if( ERROR_NO_DATA != ret )
+ {
+ DoFormatMessage(0);
+ return;
+ }
}
/* call GetNetworkParams to obtain the network info */
{
pFixedInfo = (FIXED_INFO *)HeapAlloc(ProcessHeap, 0, netOutBufLen);
if (pFixedInfo == NULL)
+ {
+ if (pAdapterInfo)
+ HeapFree(ProcessHeap, 0, pAdapterInfo);
return;
-
+ }
if (GetNetworkParams(pFixedInfo, &netOutBufLen) != NO_ERROR)
{
DoFormatMessage(0);
+ if (pAdapterInfo)
+ HeapFree(ProcessHeap, 0, pAdapterInfo);
HeapFree(ProcessHeap, 0, pFixedInfo);
return;
}
}
else
{
+ if (pAdapterInfo)
+ HeapFree(ProcessHeap, 0, pAdapterInfo);
DoFormatMessage(0);
return;
}
_tprintf(_T("\tIP Routing Enabled. . . . . . . . : Yes\n"));
else
_tprintf(_T("\tIP Routing Enabled. . . . . . . . : No\n"));
- if (pAdapter->HaveWins)
+ if (pAdapter && pAdapter->HaveWins)
_tprintf(_T("\tWINS Proxy enabled. . . . . . . . : Yes\n"));
else
_tprintf(_T("\tWINS Proxy enabled. . . . . . . . : No\n"));
{
LPTSTR IntType, myConType;
+ mibEntry.dwIndex = pAdapter->Index;
+ GetIfEntry(&mibEntry);
+
IntType = GetInterfaceTypeName(pAdapter->Type);
myConType = GetConnectionType(pAdapter->AdapterName);
if (myConType != NULL) HeapFree(ProcessHeap, 0, myConType);
/* check if the adapter is connected to the media */
- if (_tcscmp(pAdapter->IpAddressList.IpAddress.String, "0.0.0.0") == 0)
+ if (mibEntry.dwOperStatus != MIB_IF_OPER_STATUS_CONNECTED && mibEntry.dwOperStatus != MIB_IF_OPER_STATUS_OPERATIONAL)
{
_tprintf(_T("\tMedia State . . . . . . . . . . . : Media disconnected\n"));
pAdapter = pAdapter->Next;
if (bAll)
{
- _tprintf(_T("\tDescription . . . . . . . . . . . : %s\n"), GetConnectionDescription(pAdapter->AdapterName));
+ LPTSTR lpDesc = GetConnectionDescription(pAdapter->AdapterName);
+ _tprintf(_T("\tDescription . . . . . . . . . . . : %s\n"), lpDesc);
+ HeapFree(ProcessHeap, 0, lpDesc);
_tprintf(_T("\tPhysical Address. . . . . . . . . : %s\n"), PrintMacAddr(pAdapter->Address));
if (pAdapter->DhcpEnabled)
_tprintf(_T("\tDHCP Enabled. . . . . . . . . . . : Yes\n"));
_tprintf(_T("\tIP Address. . . . . . . . . . . . : %s\n"), pAdapter->IpAddressList.IpAddress.String);
_tprintf(_T("\tSubnet Mask . . . . . . . . . . . : %s\n"), pAdapter->IpAddressList.IpMask.String);
- _tprintf(_T("\tDefault Gateway . . . . . . . . . : %s\n"), pAdapter->GatewayList.IpAddress.String);
+ if (pAdapter->GatewayList.IpAddress.String[0] != '0')
+ _tprintf(_T("\tDefault Gateway . . . . . . . . . : %s\n"), pAdapter->GatewayList.IpAddress.String);
+ else
+ _tprintf(_T("\tDefault Gateway . . . . . . . . . :\n"));
if (bAll)
{
}
HeapFree(ProcessHeap, 0, pFixedInfo);
- HeapFree(ProcessHeap, 0, pAdapterInfo);
+ if (pAdapterInfo)
+ HeapFree(ProcessHeap, 0, pAdapterInfo);
}
VOID Release(LPTSTR Index)
{
IP_ADAPTER_INDEX_MAP AdapterInfo;
DWORD ret;
+ DWORD i;
/* if interface is not given, query GetInterfaceInfo */
if (Index == NULL)
if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR )
{
- CopyMemory(&AdapterInfo, &pInfo->Adapter[0], sizeof(IP_ADAPTER_INDEX_MAP));
- _tprintf(_T("name - %S\n"), pInfo->Adapter[0].Name);
+ for (i = 0; i < pInfo->NumAdapters; i++)
+ {
+ CopyMemory(&AdapterInfo, &pInfo->Adapter[i], sizeof(IP_ADAPTER_INDEX_MAP));
+ _tprintf(_T("name - %S\n"), pInfo->Adapter[i].Name);
+
+ /* Call IpReleaseAddress to release the IP address on the specified adapter. */
+ if ((ret = IpReleaseAddress(&AdapterInfo)) != NO_ERROR)
+ {
+ _tprintf(_T("\nAn error occured while releasing interface %S : \n"), AdapterInfo.Name);
+ DoFormatMessage(ret);
+ }
+ }
+
HeapFree(ProcessHeap, 0, pInfo);
}
else
* ipconfig /release *con* will release all cards with 'con' in their name
*/
}
-
-
- /* Call IpReleaseAddress to release the IP address on the specified adapter. */
- if ((ret = IpReleaseAddress(&AdapterInfo)) != NO_ERROR)
- {
- _tprintf(_T("\nAn error occured while releasing interface %S : \n"), AdapterInfo.Name);
- DoFormatMessage(ret);
- }
-
}
VOID Renew(LPTSTR Index)
{
IP_ADAPTER_INDEX_MAP AdapterInfo;
+ DWORD i;
/* if interface is not given, query GetInterfaceInfo */
if (Index == NULL)
/* Make a second call to GetInterfaceInfo to get the actual data we want */
if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR )
{
- CopyMemory(&AdapterInfo, &pInfo->Adapter[0], sizeof(IP_ADAPTER_INDEX_MAP));
- _tprintf(_T("name - %S\n"), pInfo->Adapter[0].Name);
+ for (i = 0; i < pInfo->NumAdapters; i++)
+ {
+ CopyMemory(&AdapterInfo, &pInfo->Adapter[i], sizeof(IP_ADAPTER_INDEX_MAP));
+ _tprintf(_T("name - %S\n"), pInfo->Adapter[i].Name);
+
+
+ /* Call IpRenewAddress to renew the IP address on the specified adapter. */
+ if (IpRenewAddress(&AdapterInfo) != NO_ERROR)
+ {
+ _tprintf(_T("\nAn error occured while renew interface %s : "), _T("*name*"));
+ DoFormatMessage(0);
+ }
+ }
}
else
{
* ipconfig /renew *con* will renew all cards with 'con' in their name
*/
}
-
-
- /* Call IpRenewAddress to renew the IP address on the specified adapter. */
- if (IpRenewAddress(&AdapterInfo) != NO_ERROR)
- {
- _tprintf(_T("\nAn error occured while renew interface %s : "), _T("*name*"));
- DoFormatMessage(0);
- }
}
if (lpUsage == NULL)
return;
- if (LoadString(hInstance,
+ if (LoadStringAndOem(hInstance,
IDS_USAGE,
lpUsage,
Size))
ProcessHeap = GetProcessHeap();
/* Parse command line for options we have been given. */
- if ( (argc > 1)&&(argv[1][0]=='/') )
+ if ( (argc > 1)&&(argv[1][0]=='/' || argv[1][0]=='-') )
{
if( !_tcsicmp( &argv[1][1], _T("?") ))
{