CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: how to display the MAC address of client?

  1. #1
    Join Date
    Mar 2012

    how to display the MAC address of client? EDITED

    I have a client server program using UPD created in MFC. In the server there are two listboxes. The first one displays the ip addresses of the connected clients.
    I want the second listbox to display the MAC address when i click the ip address from the listbox.

    So how can I display the MAC address of the client by clicking the ip address in the first listbox?

    so i used this code to get the MAC address:
    IP_ADAPTER_INFO AdapterInfo[16];			// Allocate information for up to 16 NICs
    	DWORD dwBufLen = sizeof(AdapterInfo);		// Save the memory size of buffer
    	DWORD dwStatus = GetAdaptersInfo(			// Call GetAdapterInfo
    		AdapterInfo,							// [out] buffer to receive data
    		&dwBufLen);								// [in] size of receive data buffer
    	assert(dwStatus == ERROR_SUCCESS);			// Verify return value is valid, no buffer overflow
    	PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;// Contains pointer to current adapter info
    	do {
    		PrintMACaddress(pAdapterInfo->Address);	// Print MAC address
    		pAdapterInfo = pAdapterInfo->Next;		// Progress through linked list
    	while(pAdapterInfo);						// Terminate if last adapter
    the code above just provides the currents computer mac address so it doesn't matter which ip address i click in the listbox because it only displays the same mac address
    Last edited by beginner91; March 25th, 2013 at 05:37 AM.

  2. #2
    Join Date
    Oct 2005
    Minnesota, U.S.A.

    Re: how to display the MAC address of client?

    It may be that you have too small of an array. Try calling the GetAdaptersInfo() with a NULL and a zero to get the needed size.

    You may be getting no results so your "MAC" may be garbage. Instead of a do/while, use just a while loop.

    Here is a clip of code I use all the time:

    	for(pAdapterInfo= AdapterInfo; pAdapterInfo; pAdapterInfo= pAdapterInfo->Next )
    		DWORD dwIP = ntohl(inet_addr(pAdapterInfo->IpAddressList.IpAddress.String));
    		DWORD dwMask = ntohl(inet_addr(pAdapterInfo->IpAddressList.IpMask.String));
    		BYTE MAC[6];
    		CopyMemory(MAC, pAdapterInfo->Address, 6);
    		// Do something

    P.S. Also take a look at GetIpNetTable() and SendARP().
    Last edited by egawtry; June 7th, 2013 at 08:54 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)