Networking Forums  

Go Back   Networking Forums > Networking Newsgroups > Linux Networking

Access to ARP Cache

Reply
 
Thread Tools Display Modes
  #1  
Old 11-10-2003, 11:44 AM
Default Access to ARP Cache



Hi all,

I have an IP Address, and I'm sure, that the corresponding MAC Address
is inside the ARP cache.
Is there a C-Function to get the MAC Address?

Regards
Dirk



=?ISO-8859-1?Q?Dirk_F=F6rster?=
Reply With Quote
  #2  
Old 11-10-2003, 11:51 AM
James Knott
Guest
 
Posts: n/a
Default Re: Access to ARP Cache

Dirk Förster wrote:

> Hi all,
>
> I have an IP Address, and I'm sure, that the corresponding MAC Address
> is inside the ARP cache.
> Is there a C-Function to get the MAC Address?


Your mac address will not be in the arp cache of your computer. It only
lists the mac of other computers.

--

Fundamentalism is fundamentally wrong.

To reply to this message, replace everything to the left of "@" with
james.knott.
Reply With Quote
  #3  
Old 11-10-2003, 12:09 PM
=?ISO-8859-15?Q?Dirk_F=F6rster?=
Guest
 
Posts: n/a
Default Re: Access to ARP Cache

James Knott wrote:
> Dirk Förster wrote:
>
>
>>Hi all,
>>
>>I have an IP Address, and I'm sure, that the corresponding MAC Address
>>is inside the ARP cache.
>>Is there a C-Function to get the MAC Address?

>
>
> Your mac address will not be in the arp cache of your computer. It only
> lists the mac of other computers.
>

That's right.
The IP Address I have is the next hop Address. And I know, that there
was an ARP request before.I want to read out the corresponding MAC Address.

Reply With Quote
  #4  
Old 11-10-2003, 12:50 PM
Rudi Swennen
Guest
 
Posts: n/a
Default Re: Access to ARP Cache

On Mon, 10 Nov 2003 13:09:44 +0100, Dirk Förster wrote:

> James Knott wrote:
>> Dirk Förster wrote:
>>
>>
>>>Hi all,
>>>
>>>I have an IP Address, and I'm sure, that the corresponding MAC Address
>>>is inside the ARP cache.
>>>Is there a C-Function to get the MAC Address?

>>
>>
>> Your mac address will not be in the arp cache of your computer. It only
>> lists the mac of other computers.
>>

> That's right.
> The IP Address I have is the next hop Address. And I know, that there
> was an ARP request before.I want to read out the corresponding MAC Address.


Try ifconfig, arp and arping. For more info the man pages can come handy.

Rudi Swennen
Reply With Quote
  #5  
Old 11-11-2003, 12:10 AM
Jim Fischer
Guest
 
Posts: n/a
Default Re: Access to ARP Cache

Dirk Förster wrote:
> Hi all,
>
> I have an IP Address, and I'm sure, that the corresponding MAC Address
> is inside the ARP cache.
> Is there a C-Function to get the MAC Address?


See,

man 7 arp

FWIW, when looking for assistance with Linux programming tasks, the
Linux programming newsgroups and mailing lists are generally your best
bet, e.g.,

comp.os.linux.development.*

--
Jim

To reply by email, remove "link" and change "now.here" to "yahoo"
jfischer_link5809{at}now.here.com


Reply With Quote
  #6  
Old 11-12-2003, 12:07 PM
Bob Smith
Guest
 
Posts: n/a
Default Re: Access to ARP Cache

I had a similar question and googled around until I
found the following ioctl. Hope this helps....



/* Try to find an entry in arp cache for the ip address specified */

printf("Find arp entry for IP : %s\n", ip);

sin = (struct sockaddr_in *) &arpreq.arp_pa;
memset(sin, 0, sizeof(struct sockaddr_in));
sin->sin_family = AF_INET;
ina.s_addr = inet_addr(ip);
memcpy(&sin->sin_addr, (char *)&ina, sizeof(struct in_addr));

strcpy(arpreq.arp_dev, "eth0");
arpreq.arp_ha.sa_family = AF_UNSPEC;
/*
rc = ioctl(sd, SIOCGARP, &arpreq);

if (rc < 0)
{
perror("Entry not available in cache. Sending arp req...\n");

send_arp_req(ip);

rc = ioctl(sd, SIOCGARP, &arpreq);
if (rc < 0)
{
printf("No arp reply. \n");
exit(1);
}
}
*/
send_arp_req(ip);

rc = ioctl(sd, SIOCGARP, &arpreq);
if (rc < 0)
{
printf("No arp reply. \n");
exit(1);
}

hw_addr = (unsigned char *) arpreq.arp_ha.sa_data;
printf("HWAddr found : %x:%x:%x:%x:%x:%x\n", hw_addr[0],
hw_addr[1], hw_addr[2], hw_addr[3], hw_addr[4], hw_addr[5]);

return 1;
}

void send_arp_req(char *ip_addr)
{
/* Sending the arp Request here */
}



Dirk Förster wrote:
> Hi all,
>
> I have an IP Address, and I'm sure, that the corresponding MAC Address
> is inside the ARP cache.
> Is there a C-Function to get the MAC Address?
>
> Regards
> Dirk
>


Reply With Quote
Reply

Tags
access, arp, cache

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 06:52 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.