/*++ Copyright (c) 1998 Microsoft Corporation Module Name: routing\monitor2\ip\utils.c Abstract: Utility functions Revision History: Anand Mahalingam 7/10/98 Created --*/ #include "precomp.h" #pragma hdrstop #define MIB_REFRESH_EVENT L"MIBEvent" DWORD GetDisplayStringT ( IN HANDLE hModule, IN DWORD dwValue, IN PVALUE_TOKEN ptvTable, IN DWORD dwNumArgs, OUT PWCHAR *ppwszString ) { DWORD i, dwErr = NO_ERROR ; for (i=0; i 1) { *pdwRR = 0; return ERROR_INVALID_PARAMETER; } // // No Index specified. Make sure refresh rate is specified // with tag. // if (_wcsnicmp(ppwcArguments[0],L"RR=",3) == 0) { // // remove tag and get the refresh rate // wcscpy(ppwcArguments[0], &ppwcArguments[0][3]); *pdwRR = wcstoul(ppwcArguments[0], NULL, 10); } else { return ERROR_INVALID_PARAMETER; } } else { // // Check for index tag // if (_wcsnicmp(ppwcArguments[0],L"INDEX=",6) == 0) { *pbIndex = TRUE; *pdwIndex = 0; // // remove tag and see if refresh rate is specified // wcscpy(ppwcArguments[0], &ppwcArguments[0][6]); if (dwArgCount > dwNumIndices) { // // Make sure that argument has RR tag // if (_wcsnicmp(ppwcArguments[dwNumIndices],L"RR=",3) == 0) { // // remove tag and get the refresh rate // wcscpy(ppwcArguments[dwNumIndices], &ppwcArguments[dwNumIndices][3]); *pdwRR = wcstoul(ppwcArguments[dwNumIndices], NULL , 10); } else { return ERROR_INVALID_PARAMETER; } } else { // // No refresh rate specified // *pdwRR = 0; return NO_ERROR; } } else { // // Not index tag, See if it has an RR tag // if (_wcsnicmp(ppwcArguments[0],L"RR=",3) == 0) { // // remove tag and get the refresh rate // wcscpy(ppwcArguments[0], &ppwcArguments[0][3]); *pdwRR = wcstoul(ppwcArguments[0], NULL , 10); // // See if the index follows // if (dwArgCount > dwNumIndices) { if (dwArgCount > 1) { if (_wcsnicmp(ppwcArguments[1],L"INDEX=",6) == 0) { wcscpy(ppwcArguments[1], &ppwcArguments[1][6]); *pbIndex = TRUE; *pdwIndex = 1; return NO_ERROR; } else { *pdwRR = 0; return ERROR_INVALID_PARAMETER; } } else { return NO_ERROR; } } } // // No RR Tag either // else if (dwArgCount > dwNumIndices) { // // Assume ppwcArguments[dwNumIndices] is the refresh rate // *pdwRR = wcstoul(ppwcArguments[dwNumIndices], NULL , 10); if (dwNumIndices != 0) { *pbIndex = TRUE; *pdwIndex = 0; } } else { // // only index present with no tag // *pbIndex = TRUE; *pdwIndex = 0; } } } return NO_ERROR; } DWORD GetIpAddress( PTCHAR pptcArg ) /*++ Routine Description: Gets the ip address from the string. Arguments: pwszIpAddr - Ip address string Return Value: ip address --*/ { CHAR pszIpAddr[ADDR_LENGTH+1]; WideCharToMultiByte(GetConsoleOutputCP(), 0, pptcArg, -1, pszIpAddr, ADDR_LENGTH, NULL, NULL); pszIpAddr[ADDR_LENGTH] = '\0'; return (DWORD) inet_addr(pszIpAddr); } BOOL WINAPI HandlerRoutine( DWORD dwCtrlType // control signal type ) { HANDLE hMib; if (dwCtrlType == CTRL_C_EVENT) { hMib = OpenEvent(EVENT_ALL_ACCESS,FALSE,MIB_REFRESH_EVENT); SetEvent(hMib); } return TRUE; } DWORD GetInfoBlockFromInterfaceInfoEx( IN LPCWSTR pwszIfName, IN DWORD dwType, OUT BYTE **ppbInfoBlk, OPTIONAL OUT PDWORD pdwSize, OPTIONAL OUT PDWORD pdwCount, OPTIONAL OUT PDWORD pdwIfType OPTIONAL ) /*++ Routine Description: calls GetInfoBlockFromInterfaceInfo and dumps error message if there is an error. --*/ { DWORD dwErr; // // get current interface config // dwErr = IpmontrGetInfoBlockFromInterfaceInfo(pwszIfName, dwType, ppbInfoBlk, pdwSize, pdwCount, pdwIfType); switch(dwErr) { case NO_ERROR: break; case ERROR_NOT_FOUND: DisplayMessage(g_hModule,EMSG_PROTO_NO_IF_INFO); break; case ERROR_INVALID_PARAMETER: DisplayMessage(g_hModule,EMSG_CORRUPT_INFO); break; case ERROR_NOT_ENOUGH_MEMORY: DisplayMessage(g_hModule,EMSG_NOT_ENOUGH_MEMORY); break; default: DisplayError(g_hModule, dwErr); break; } return dwErr; }