#!/bin/bash

#used for cli command "show arp"
#no input and outpur var

echo|awk '{print "Address          HW Address         HW Type    Interface"}'
echo|awk '{print "---------------  -----------------  ---------  ---------"}'

if [ $(expr "`uname -a`" : ".*ppc.*") -ne 0 ] ; then
    filename="/tmp/arp.txt"
    mapfile="/tmp/run/vlan_interfaces"
    arp -n | sed 's+(++;s+)++;/incomplete/d' | awk '{printf("%-15s  %-17s  %-9s  %-9s\n",$2,$4,$5,$(NF))}'>$filename
    awk -v myreal=eth0 '{for(i=NF;i<=NF;i++) if($i ~/'eth0'$/){printf("%-15s  %-17s  %-9s  %-9s\n",$1,$2,$3,myreal)}}' $filename
    awk -v myreal=eth1 '{for(i=NF;i<=NF;i++) if($i ~/'eth1'$/){printf("%-15s  %-17s  %-9s  %-9s\n",$1,$2,$3,myreal)}}' $filename
    if [ -f $mapfile ]
    then
        while read line
        do
            printname=`echo $line | awk '{print $1}'`
            realname=`echo $line | awk '{print $2}'`
            awk -v myreal=$printname '{for(i=NF;i<=NF;i++) if($i ~/'$realname'$/){printf("%-15s  %-17s  %-9s  %-9s\n",$1,$2,$3,myreal)}}' $filename
        done < $mapfile
    fi
else
    arp -n | sed '1d;/incomplete/d' | awk '{print $1 "\t" $3 "\t" $2 "\t\t" $5}'
fi

exit 0
