2 Replies - 408 Views - Last Post: 20 February 2013 - 08:52 AM Rate Topic: -----

#1 theshowtekfan  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 27-September 11

Retrieve MAC address of host from ip, need help.

Posted 20 February 2013 - 07:34 AM

hey guys im working with some raw networking in C++ here and i have to retrieve the mac address of a remote target that i have the ip of, i am trying to use the SendARP function but i am only receiving CC:CC:CC:CC:CC:CC mac addr from it :/ i really have no clue at what is wrong with my code, help me out ? :D

now over to the code:

ULONG DestMacAddr[2];
	ULONG PhysicalLength = 6;

	IPAddr destination = inet_addr(target.c_str());
	IPAddr source = inet_addr(host.c_str());

	SendARP(destination, source, DestMacAddr, &PhysicalLength);
	
	unsigned char mac[6];
	BYTE *bMacAddr = (BYTE *) & DestMacAddr;
	for (int p = 0; p < (int) PhysicalLength; p++)
	{
		mac[p] = (char)bMacAddr[p];
	}

	printf("DestMacAddr: %.2X:%.2X:%.2X:%.2X:%.2X:%.2X \n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);




btw i checked and the strings host and target are correct.

i would be very gratefull for advice, help and tips.

Is This A Good Question/Topic? 0
  • +

Replies To: Retrieve MAC address of host from ip, need help.

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4292
  • View blog
  • Posts: 13,458
  • Joined: 25-December 09

Re: Retrieve MAC address of host from ip, need help.

Posted 20 February 2013 - 07:51 AM

One thing I don't understand is why you're trying to convert the unsigned char to a signed char in the following snippet.
        mac[p] = (char)bMacAddr[p];

What happens if you mac address is something like fd:01:fc:...? Remember a signed char as a maximum value of 0x7F while a unsigned char can hold a value up to 0xFF.

Next you may want to view the documentation for SendARP() and see if your program has any fundamental differences from the sample code provided on that page.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 theshowtekfan  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 27-September 11

Re: Retrieve MAC address of host from ip, need help.

Posted 20 February 2013 - 08:52 AM

omg i found the issue :L my computer does not have a static ip and when i rebooted it i had it change ip's :L and when u give it the wrong SrcIP it throws u off with CC's

thanks anyways :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1