/* This file is part of Lcrzo.
*/

/*-------------------------------------------------------------*/
/* cette fonction interroge la table RARP locale (rarp -a)*/
int lcrzo_priv_ipa_init_etha_ioctlrarp(const lcrzo_etha etha, lcrzo_ipa ipa)
#if defined LCRZODEF_SYSTEM_Linux
{ int sfd, retour, ret;
  struct arpreq	ar;
  lcrzo_ipl ipl;

  memset(&ar, 0, sizeof(ar));
  ar.arp_pa.sa_family = AF_INET;
  memcpy(ar.arp_ha.sa_data, etha, LCRZO_ETHA_MAXBYTES);

  sfd=socket(AF_INET, SOCK_DGRAM, 0);
  if ( sfd == -1 ) return(LCRZO_ERR_FUSOCKET);
  
  retour=ioctl(sfd, SIOCGRARP, (char *)&ar);
  ret=close(sfd);
  if ( retour == -1 ) return(LCRZO_ERR_FUIOCTL);
  if ( ret == -1 ) return(LCRZO_ERR_FUCLOSE);

  if (ipa!=NULL) memcpy(ipa, ar.arp_pa.sa_data+2, LCRZO_IPA_MAXBYTES);

  lcrzo_er(lcrzo_ipl_init_ipa((lcrzo_data)(ar.arp_pa.sa_data+2), &ipl));
  lcrzo_er(lcrzo_priv_conf_arp_add_system("", etha, ipl, LCRZO_FALSE));
  lcrzo_err_purge();
  return(LCRZO_ERR_OK);
}
#elif defined LCRZODEF_SYSTEM_Solaris || defined LCRZODEF_SYSTEM_FreeBSD || defined LCRZODEF_SYSTEM_OpenBSD || defined LCRZODEF_SYSTEM_Windows
{ return(LCRZO_ERR_IEUNIMPLEMENTED);
  { int i; 
    /* just for the compiler warning */
    if (ipa==NULL && etha==NULL) i=0;
  }
}
#else
 #error "Unknown value for LCRZODEF_SYSTEM"
#endif

