|
Re: Getting MAC for a given IP
|
03/11/2010 9:01 AM
post49268
|
Re: Getting MAC for a given IP
That ioctl command (SIOCGARP) isn't supported.
The arp command uses the sysctl MIB interface to look a the ARP table
contents, see lib/io-pkt/utils/a/arp.c:dump(). If you want to trigger an
ARP request to populate the table with addresses which are of interest
to you you can simply trigger traffic to that destination in any number
of ways...
Hope this helps,
/P
On 11/03/10 04:29 AM, Christian Reinecke wrote:
> 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
>
>
>
> _______________________________________________
>
> Networking Drivers
> http://community.qnx.com/sf/go/post49249
>
>
|
|
|