Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Getting MAC for a given IP: (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
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
>
>    
Re: Getting MAC for a given IP  
Okay, but it is listed in help file for ioctl ;)
Re: Getting MAC for a given IP  
On 12/03/10 02:08 AM, Christian Reinecke wrote:
> Okay, but it is listed in help file for ioctl ;)
>    
Are you referring to this entry in the table: "SIOCGARP    Get ARP 
entry    Passed to devctl()"?
http://www.qnx.com/developers/docs/6.4.1/neutrino/lib_ref/i/ioctl.html

All that means is that it is passed to devctl() :-) It is still up to 
the resource manager owning the file descriptor to implement it.

Seriously though, I don't know if it is possible to compile a list of 
supported ioctl commands. Or does anybody know if there already is one?

Cheers!
/P
Re: Getting MAC for a given IP  
> Are you referring to this entry in the table: "SIOCGARP    Get ARP 
> entry    Passed to devctl()"?
> http://www.qnx.com/developers/docs/6.4.1/neutrino/lib_ref/i/ioctl.html

Yes.

> 
> All that means is that it is passed to devctl() :-) It is still up to 
> the resource manager owning the file descriptor to implement it.

YMYD :D

> 
> Seriously though, I don't know if it is possible to compile a list of 
> supported ioctl commands. Or does anybody know if there already is one?
> 
> Cheers!
> /P


Christian

Re: Getting MAC for a given IP  
> On 12/03/10 02:08 AM, Christian Reinecke wrote:
> > Okay, but it is listed in help file for ioctl ;)
> >    
> Are you referring to this entry in the table: "SIOCGARP    Get ARP 
> entry    Passed to devctl()"?
> http://www.qnx.com/developers/docs/6.4.1/neutrino/lib_ref/i/ioctl.html
> 
> All that means is that it is passed to devctl() :-) It is still up to 
> the resource manager owning the file descriptor to implement it.
> 
> Seriously though, I don't know if it is possible to compile a list of 
> supported ioctl commands. Or does anybody know if there already is one?
> 
> Cheers!
> /P


So, what's your final solution?

You can get the MAC address for given IP?
I encounter the same problem.
Re: Getting MAC for a given IP  
Hello,

I just ran into the same problem. Again: Is there a solution? How does arp do it?

Cheers,
Christoph