Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
BroadcastCommunity.qnx.com will be offline from May 31 6:00pm until June 2 12:00AM for upcoming system upgrades. For more information please go to https://community.qnx.com/sf/discussion/do/listPosts/projects.bazaar/discussion.bazaar.topc28418
Forum Topic - Getting MAC for a given IP: Page 1 of 7 (7 Items)
   
Getting MAC for a given IP  
Hello,
I am trying to get the MAC address for a given IP.
I can do an "arp -a | grep xxx | sed yyy", but I need it within my sourcecode.

I have been trying to set up the ioctl function that should return this value, but it always fails with errno 6 "No such
 device or address".

Here is what I am trying to do:


struct arpreq req;
struct	sockaddr_in	*sin = (struct sockaddr_in *)&req.arp_pa;

memset(&req, 0, sizeof(req));

sin->sin_family = AF_INET;

memcpy(&sin->sin_addr.s_addr, &servAddr.sin_addr.s_addr, sizeof(sin->sin_addr.s_addr));

if(ioctl(sd, SIOCGARP, (caddr_t)&req)  != EOK)
	printf("errno %d %s", errno, strerror(errno));


Before this snippet, I have created a socket with 

sd = socket(AF_INET, SOCK_STREAM, 0);

and connected to the server with

connect(sd, (struct sockaddr *) &servAddr, sizeof(servAddr));


The connection is built up without Problems, so I assume the servAddr-struct is valid.

Regards
Christian