Discussion:
Question about ARP and GetIpNetTable().
(too old to reply)
NayJo
21 years ago
Permalink
Hi:

I am using GetIpNetTable() to get a list of IP and MAC addresses. The
program runs fine for a few times but then GetIpNetTable() begins returning
ERROR_NO_DATA - The pipe is being closed.

I am sort of new to this but I'm assuming that some resource is not being
released but I'm not sure what that resource may be.

The program is compiled with VC++ 6.0 and is running on Windows 2000 Pro.

Many thanks in advance.

J

<code>
//
// Link with ws2_32.lib and iphlpapi.lib
//

#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <iphlpapi.h>

#define IP_BUFFER_SIZE 4096
char ucipTableBuffer[IP_BUFFER_SIZE];

#define FAIL 1
#define SUCCEED 0

static void DisplayErrorMessage( DWORD dwError)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Process any inserts in lpMsgBuf.
// ...
// Display the string.
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
return;
}

int __cdecl main( void )
{
DWORD dwError;
ULONG ulLen;
PMIB_IPNETTABLE pIpTable = (PMIB_IPNETTABLE)ucipTableBuffer;
size_t i, j, k;

ulLen = (ULONG)IP_BUFFER_SIZE;
dwError = GetIpNetTable( pIpTable, &ulLen, TRUE);
if (dwError)
{
DisplayErrorMessage(dwError);
return 1;
}

for (i = 0; i < (size_t)pIpTable->dwNumEntries; i++)
{
char * szMac = new char[pIpTable->table[i].dwPhysAddrLen*3];
unsigned char *paddr = (unsigned char
*)&pIpTable->table[i].dwAddr;

printf("[%d]: %u.%u.%u.%u ", i, *paddr, *(paddr+1), *(paddr+2),
*(paddr+3));

//
// Convert the binary MAC address into human-readable
//

for (j = 0, k = 0; j < pIpTable->table[i].dwPhysAddrLen-1; ++j) {
k += sprintf (szMac + k, "%02X:", pIpTable->table[i].bPhysAddr[j]);
}
sprintf (szMac + k, "%02X", pIpTable->table[i].bPhysAddr[j]);
printf ("MAC address %s\n", szMac);

delete [] szMac;
}
return 0;
}

</code>
Mohit Talwar [MSFT]
21 years ago
Permalink
The ARP cache is periodically flushed, stale ARP entries are removed.

Hence, what you observe could happen if there are no MIB_IPNETROW entries
present. You may use "arp -a" to confirm.

Mohit.

PS Perhaps there is another way to achieve what you have in mind. Could you
provide more information on why you need the IP->MAC mapping?
--
This posting is provided "AS IS" with no warranties, and confers no rights.
...
MB_ICONINFORMATION );
...
NayJo
21 years ago
Permalink
"Mohit Talwar [MSFT]" <***@online.microsoft.com> wrote in message news:OesKDvM$***@TK2MSFTNGP11.phx.gbl...
...
Post by Mohit Talwar [MSFT]
PS Perhaps there is another way to achieve what you have in mind. Could you
provide more information on why you need the IP->MAC mapping?
I am writing a program that uses ARP to set an IP address of a device on the
network. I have been told that if the device already has an address
assigned that ARP will not work so I am using GetIpNetTable() to get a list
of MAC addresses so I can determine if the MAC address entered is already
present. Then I could tell the user to reset the device and try again.

Once I use ARP then I will spawn a configuration program specifically for
the device (a network/serial adapter).

If my answers show a lack of understanding of what ARP is, I admit that is
correct.

Thank you for your help.

J

Loading...