LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-22-2011, 09:28 AM   #1
mutwkil
Member
 
Registered: Feb 2010
Posts: 30

Rep: Reputation: 0
Smile ARP cache


hello folk

Iam tring to develop C code to get MAC address from ARP cache after adding entry on it, can some body give me simple code or try correct this one

Code:
#include <string.h>
#include <net/if_arp.h>
#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <strings.h>
#include <stdlib.h>

int sock,sockfd,n,s,count;

char comand [61];//to handle arping command


int main(int argc, char **argv) {
  struct sockaddr_in sin;
  struct arpreq myarp;
  strcpy(myarp.arp_dev , "eth0"); 

    if(inet_aton(argv[1],&sin.sin_addr)==0){//obtain Next Router IP

          printf("%s: IP address  not valid\n",argv[1]);

          exit(0);

        }//if

     memcpy(&myarp.arp_pa,&sin,sizeof sin);//for arp cache

     count =0;//cache counter	

     while((ioctl(sockfd,SIOCGARP,&myarp)==-1)&&(count <=1)){//Get MAC from cache

	        sprintf(comand ,"arping -I eth0 %s -c 1>/dev/null ",argv[1]);

	        system(comand);//execute ARPING Command

	        count++;

        }//arp while
}
 
Old 05-23-2011, 05:46 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,748

Rep: Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ARP cache poisoning? Sum1 Linux - Security 5 09-01-2010 04:19 PM
arp cache not showing anything ramkernel Linux - Newbie 4 03-08-2010 11:34 AM
arp cache problem gr8paki Linux - Networking 9 04-26-2007 02:25 PM
arp cache shrishailnk Linux - Networking 2 04-29-2006 01:07 AM
arp cache entry............. shrishailnk Linux - Networking 2 04-22-2006 02:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration