+
+
+/*
+ * convert error code into meaningful message
+ */
+DWORD DoFormatMessage(DWORD ErrorCode)
+{
+ LPVOID lpMsgBuf;
+ DWORD RetVal;
+ /* double brackets to silence the assignment warning message */
+ if ((RetVal = FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ ErrorCode,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
+ (LPTSTR) &lpMsgBuf,
+ 0,
+ NULL ))) {
+ _tprintf(_T("%s"), (LPTSTR)lpMsgBuf);
+
+ LocalFree(lpMsgBuf);
+ /* return number of TCHAR's stored in output buffer
+ * excluding '\0' - as FormatMessage does*/
+ return RetVal;
+ }
+ else
+ return 0;
+}
+
+
+
+/*
+ *
+ * Takes an ARP entry and prints the IP address,
+ * the MAC address and the entry type to screen
+ *
+ */
+INT PrintEntries(PMIB_IPNETROW pIpAddRow)
+{
+ IN_ADDR inaddr;
+ TCHAR cMacAddr[20];
+
+ /* print IP addresses */
+ inaddr.S_un.S_addr = pIpAddRow->dwAddr;
+ _tprintf(_T(" %-22s"), inet_ntoa(inaddr));
+
+ /* print MAC address */
+ _stprintf(cMacAddr, _T("%02x-%02x-%02x-%02x-%02x-%02x"),
+ pIpAddRow->bPhysAddr[0],
+ pIpAddRow->bPhysAddr[1],
+ pIpAddRow->bPhysAddr[2],
+ pIpAddRow->bPhysAddr[3],
+ pIpAddRow->bPhysAddr[4],
+ pIpAddRow->bPhysAddr[5]);
+ _tprintf(_T("%-22s"), cMacAddr);
+
+ /* print cache type */
+ switch (pIpAddRow->dwType)
+ {
+ case MIB_IPNET_TYPE_DYNAMIC : _tprintf(_T("dynamic\n"));
+ break;
+ case MIB_IPNET_TYPE_STATIC : _tprintf(_T("static\n"));
+ break;
+ case MIB_IPNET_TYPE_INVALID : _tprintf(_T("invalid\n"));
+ break;
+ case MIB_IPNET_TYPE_OTHER : _tprintf(_T("other\n"));
+ break;
+ }
+ return EXIT_SUCCESS;
+}
+
+