How can I read the ARP cache programmatically? - VxWorks

This is a discussion on How can I read the ARP cache programmatically? - VxWorks ; Hi! I'm putting packets right on the wire, so I need to know the destination MAC address of my router. I have its IP address, but I need to be able to send a packet to it directly. So does ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: How can I read the ARP cache programmatically?

  1. How can I read the ARP cache programmatically?

    Hi!
    I'm putting packets right on the wire, so I need to know the
    destination MAC address of my router. I have its IP address, but I
    need to be able to send a packet to it directly. So does anyone know a
    way of extracting the MAC address programatically? Could I maybe
    redirect the output of arpShow to some section of memory and just parse
    it myself? There must be a way to do it, but the arpLib doesn't seem
    to have any obvious methods...

    Thanks!

    Best,

    Steven Harris


  2. Re: How can I read the ARP cache programmatically?

    I've not done this myself, but the arpLib docs contain this note:

    "A low level interface to the ARP table is available with the
    socket-specific SIOCSARP, SIOCDARP and SIOCGARP ioctl functions."

    SIOCGARP is used to get an arp entry. I'm assuming that you might use
    the structure arpreq which is defined in target/h/net/if_arp.h to
    retrieve the results of the ioctl request.

    So, assuming you have a socket connection to your router, I guess you'd
    do something like:

    struct arpreq arpreq;
    ioctl (sock, SIOCGARP, (int) &arpreq);

    Something like that anyway... again, I've never done this so I'm only
    surmising.


  3. Re: How can I read the ARP cache programmatically?

    steve wrote:

    >Hi!
    > I'm putting packets right on the wire, so I need to know the
    >destination MAC address of my router. I have its IP address, but I
    >need to be able to send a packet to it directly. So does anyone know a
    >way of extracting the MAC address programatically? Could I maybe
    >redirect the output of arpShow to some section of memory and just parse
    >it myself? There must be a way to do it, but the arpLib doesn't seem
    >to have any obvious methods...
    >
    >Thanks!
    >
    >Best,
    >
    >Steven Harris
    >
    >
    >

    If you're putting packets right on the wire, I guess
    you've bypassed all the functionality built in to the
    stack, so who's doing the ARP protocol? Is the VxWorks
    ARP cache even being built?

    My first suggestion to you is to examine the reasons
    you've decided to operate directly on the hardware. I
    bring this up because I've worked with a lot of talented
    people who are good with hardware who have a natural
    inclination to get right down to it and program on the
    bare metal, but every time they've done this, it has
    ended up causing more problems than it has solved.
    There is a lot of history built into the IP stack.
    A lot of problems have been solved over the preceeding
    decades. Are you prepared to handle, for example,
    large packets that may come along in the future? Does
    your code fragment? Why re-invent this stuff? You may
    be better off using sockets like the 99% of the rest
    of the world. It's really a lot easier most of the time.
    I wonder if you don't know how to do socket programming
    and don't want to take the time to learn. If so, my
    advise it to learn it. It's not hard.

    But I'll assume that you have good reasons for your
    approach. If VxWorks' ARP implementation is running,
    your ARP cache entries can be found in the kernel
    routing table. They're flagged as type RTF_LLINFO
    (link-layer info) to distinguish them from layer-3
    routes. You can find them with the Berkeley function
    rn_walktree(). The first arg to rn_walktree() is
    rt_tables[AF_INET] to search the kernel routing table.

    routeShow() "conveniently" hides a great number of the
    routes in the kernel routing table, so it's not obvious
    that that is where the ARP cache entries are stored, but
    they are. There's so much mode there than WRS lets you
    see. You'll have to dig into rn_walktree() to make use
    of it, but it may be worth it. I have done this, so I
    know it works, but I don't own the code I wrote, so I
    can't just hand it over to you.

    Your own suggestion sounds workable as well. Run arpShow()
    programatically and redirect the output to a ram disk or
    some other file. Then read and parse the results.

    Either way, it won't be trivial. Are you sure you can't
    just use sockets?

    Vic Sperry
    vsperry@sperry.homeip.net

+ Reply to Thread