LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 03-19-2008, 04:16 AM   #1
karawin
LQ Newbie
 
Registered: Mar 2008
Posts: 1

Rep: Reputation: 0
arp table listing problem


Hi

I made a little soft to create arp entries, check the arp table and destroy each entry.

The arp listing produced is wrong for one entry. This entry exists really (can be deleted one time, another try is wrong).

Exemple:

creating 15 entries
/sbin/arp -Ds 10.1.1.5 eth0 pub
/sbin/arp -Ds 10.1.1.6 eth0 pub
/sbin/arp -Ds 10.1.1.7 eth0 pub
/sbin/arp -Ds 10.1.1.8 eth0 pub
/sbin/arp -Ds 10.1.1.9 eth0 pub
/sbin/arp -Ds 10.1.1.10 eth0 pub
/sbin/arp -Ds 10.1.1.11 eth0 pub
/sbin/arp -Ds 10.1.1.12 eth0 pub
/sbin/arp -Ds 10.1.1.13 eth0 pub
/sbin/arp -Ds 10.1.1.14 eth0 pub
/sbin/arp -Ds 10.1.1.15 eth0 pub
/sbin/arp -Ds 10.1.1.16 eth0 pub
/sbin/arp -Ds 10.1.1.17 eth0 pub
/sbin/arp -Ds 10.1.1.18 eth0 pub
/sbin/arp -Ds 10.1.1.19 eth0 pub
check inputs
Address HWtype HWaddress Flags Mask Iface
10.1.1.5 * * MP eth0
Address HWtype HWaddress Flags Mask Iface
10.1.1.6 * * MP eth0
Address HWtype HWaddress Flags Mask Iface
10.1.1.7 * * MP eth0
Address HWtype HWaddress Flags Mask Iface
10.1.1.8 * * MP eth0
Address HWtype HWaddress Flags Mask Iface
10.1.1.9 * * MP eth0
Address HWtype HWaddress Flags Mask Iface
10.1.1.10 * * MP eth0
Address HWtype HWaddress Flags Mask Iface
10.1.1.11 * * MP eth0
Address HWtype HWaddress Flags Mask Iface
10.1.1.12 * * MP eth0
Address HWtype HWaddress Flags Mask Iface
10.1.1.13 * * MP eth0
Address HWtype HWaddress Flags Mask Iface
10.1.1.14 * * MP eth0
Address HWtype HWaddress Flags Mask Iface
10.1.1.15 * * MP eth0
10.1.1.16 (10.1.1.16) -- no entry
Address HWtype HWaddress Flags Mask Iface
10.1.1.17 * * MP eth0
Address HWtype HWaddress Flags Mask Iface
10.1.1.18 * * MP eth0
Address HWtype HWaddress Flags Mask Iface
10.1.1.19 * * MP eth0
Sleep 3 sec
Delete entries
/sbin/arp -i eth0 -d 10.1.1.5 pub
/sbin/arp -i eth0 -d 10.1.1.6 pub
/sbin/arp -i eth0 -d 10.1.1.7 pub
/sbin/arp -i eth0 -d 10.1.1.8 pub
/sbin/arp -i eth0 -d 10.1.1.9 pub
/sbin/arp -i eth0 -d 10.1.1.10 pub
/sbin/arp -i eth0 -d 10.1.1.11 pub
/sbin/arp -i eth0 -d 10.1.1.12 pub
/sbin/arp -i eth0 -d 10.1.1.13 pub
/sbin/arp -i eth0 -d 10.1.1.14 pub
/sbin/arp -i eth0 -d 10.1.1.15 pub
/sbin/arp -i eth0 -d 10.1.1.16 pub
/sbin/arp -i eth0 -d 10.1.1.17 pub
/sbin/arp -i eth0 -d 10.1.1.18 pub
/sbin/arp -i eth0 -d 10.1.1.19 pub


For 15 entries the 12 th entry is wrongly displayed as missing,
For 20 entries the 13th entry is wrongly displayed as missing,
21 -> 14th etc

The code is
Code:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>

#include <net/if_arp.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <string.h>
#include <errno.h>
#include <assert.h>

#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || __GLIBC__ > 2

#include <netinet/if_ether.h>
#include <netpacket/packet.h>

#else

#include <linux/if_ether.h>
#include <linux/if_packet.h>

#endif

#define ERROR printf
#define FATAL_ERROR printf
#define DbgRtLib printf
#define EVENTLOG printf
//EVENTLOG, ERROR, FATAL_ERROR




#define NIPQUAD(addr) \
        ((unsigned char *)&addr)[0], \
        ((unsigned char *)&addr)[1], \
        ((unsigned char *)&addr)[2], \
        ((unsigned char *)&addr)[3]


int main(int argc, const char* argv[])
{
int i;
struct in_addr host_addr;
  char cmd[1024];
  u_int32_t msIP,omsIP;
  u_int32_t ip;
  struct sockaddr eth;

//initial values
  omsIP = 0x0A010104;
  int ii = 15;
  char interface[] = "eth0";
//
 
  if (argc == 1) 
  {
    printf("call with arptest count\n");
    return 0;
  }       
  ii = atoi( argv[1]);
  printf ("arp test with the command line arp \n");
  printf(" creating %d entries\n",ii);
  msIP=omsIP;
  for (i = 0; i < ii; i++)
  {
     //proxyarp_add_item(struct in_addr host_addr, char const *interface)
  msIP++;
  ip = htonl(msIP);
//  host_addr.s_addr = ip;
//  printf ("  rt_proxyARPon mss %d.%d.%d.%d\n", NIPQUAD(ip));
//     proxyarp_add_item(host_addr,interface);
   sprintf(cmd,"/sbin/arp  -Ds  %d.%d.%d.%d %s pub", NIPQUAD(ip),interface);
   printf ("  %s \n",cmd);
  system(cmd);
  }

  printf("check inputs\n");
  msIP=omsIP;
 
  for (i = 0; i<ii; i++)
  { 
  msIP++; 
  ip = htonl(msIP);
 // host_addr.s_addr = ip;
  sprintf(cmd,"/sbin/arp -n -i %s  %d.%d.%d.%d",interface, NIPQUAD(ip));
  system(cmd);
  }

  printf("Sleep 3 sec\n");
  sleep(3);

  printf("Delete entries\n");
  msIP=omsIP;

  for (i = 0; i<ii; i++)
  {
  msIP++;
  ip = htonl(msIP);
   sprintf(cmd,"/sbin/arp  -i %s -d  %d.%d.%d.%d  pub", interface,NIPQUAD(ip));
      printf ("  %s  \n",cmd);
        system(cmd);
        
  }

  printf("\n");
}

Done with kernel 2.6.12 on mdk but reproduced on redhat.

Is there a bug in the linux code?

Thanks for your test on any other distributions

Bye
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to modify ARP table canci Programming 1 08-22-2006 10:31 PM
very curious ping arp table problem biiiep Linux - Networking 4 12-21-2005 07:13 AM
ARP table 98steve600 Linux - General 1 03-28-2005 03:25 AM
Outputting the ARP table spud Programming 2 03-09-2005 09:38 AM
How to create an proxyarp entry in arp table by using arp command? himalayas Linux - Networking 0 06-04-2003 04:14 AM

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

All times are GMT -5. The time now is 04:21 AM.

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