%constinteger ARP tables size = 1023

%systemroutinespec phex2(%integer x)

%externalpredicatespec FS lookup(%string(31) what, %integername value)

%recordformat ether address fm(%bytearray x(0 : 5))

%recordformat ARP entry fm(%integer IP address,
                           %record(ether address fm) ether address)
%recordformat ARP tables fm(%record(ARP entry fm)%array e(0 : ARP tables size))

%externalroutine print INet address(%integer addr)
   write(addr >> 24 & 255, 0);  print symbol('.')
   write(addr >> 16 & 255, 0);  print symbol('.')
   write(addr >>  8 & 255, 0);  print symbol('.')
   write(addr       & 255, 0)
%end

%externalroutine print ether address(%record(ether address fm)%name a)
   %integer i
      %for i = 0, 1, 5 %cycle
         print symbol('-') %unless i = 0
         phex2(a_x(i))
      %repeat
%end

%begin
   %record(ARP tables fm)%name T
   %record(ARP entry fm)%name E
   %string(255) out
   %integer i
      %on 3, 9 %start
         select output(0)
         printstring(event_message)
         newline
         %stop
      %finish
      %if FS lookup("ETHER_ARP_TABLES", i) %start
         T == record(i)
      %else
         printstring("No ARP tables");  newline
         %stop
      %finish
      out = CLI param
      out = ":T" %if out = ""
      open output(3, out);  select output(3)
      %for i = 0, 1, ARP tables size %cycle
         E == T_e(i)
         %if E_IP address # 0 %start
            print inet address(E_IP address)
            spaces(3)
            print ether address(E_ether address)
            newline
         %finish
      %repeat
      close output
      select output(0)
%end %of %program
