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"));
_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);
- }
}
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("?") ))
{