Doing ARP and Inverse ARP on Linux 2.6.21 (glibc 2.3.5)

51

Solution 1

/proc/net/arp

K

Solution 2

ARP tables tend to be fairly local and short-lived. If you examine the protocol, the real MAC addresses are generally only provided when the given IP address is in the local subnet. Otherwise, the packet is forwarded to the local router, which is then responsible for forwarding it.

If you do "arp -g" on Windows or "arp -a" on UNIX, you'll see the table, but I don't think it will do you any good, due to the reasons mentioned above. That command and

That's really what DNS is for but, as you say, it may not be an option for you.

You may well have to write your own 'ARP' database at your application level.

Solution 3

As for ARP:
You could use system("/usr/bin/arp -option_of_choice"); and parse the output, but that's an ugly hack. -- Not my recommendation.

Take a look at /usr/include/linux/sockios.h -- At the SIOCGARP, SIOCDARP, and SIOCSARP details. Those are ioctls that you can perform to manage the ARP table on linux. Of course, you'll have to perform these ioctls on a socket fd. Here's some examples: SIOCGARP examples
I'm sure you can find many other examples in several other languages as well. As I'm assuming that you're using C.

As for RARP:
A quote from the linux rarp manpage: " This program is obsolete. From version 2.3, the Linux kernel no longer contains RARP support. For a replacement RARP daemon, see ftp://ftp.demen- tia.org/pub/net-tools"
So you'll have to install rarpd on the target system.

Share:
51
James.bvn
Author by

James.bvn

Updated on September 03, 2022

Comments

  • James.bvn
    James.bvn over 1 year

    I've been working on a small project to help my coding, and have run into a simple problem, So I'm trying to recreate a small game calls 'odds on' as per where I live, where you and a friend say a number, let's say between 1 and 5, at the same time, and if your friend says the same number as you, you win, basically, and I've got my code working, mostly, however it only says that I lose, even if the computer answer is equal to my answer, have a look at the whole code:

    oddsonplayer = input("")
    
    print(oddsonplayer)
    
    import random
    oddsoncomputer = (random.randint(1,5))
    
    if oddsonplayer > "5":
        print("Pick a number between 1 and 5!")
    if oddsonplayer == oddsoncomputer:
        print("You Win!")
    else:
    print("You Lose!")
    

    So long story short, it says I lose, even if both numbers are equal.

  • Mudasir Nazir
    Mudasir Nazir over 15 years
    Upmodded for the first paragraph.