int netx_send_to( struct netxsocket_s *rlpsock, const netx_addr_t *destaddr, uint8_t *data, size_t datalen ) { struct pbuf *pkt; /* Outgoing packet */ struct eth_addr *ethaddr_ret; struct ip_addr *ipaddr_ret; int result; int t_begin; struct ip_addr dest_addr; ip4addr_t addr; int arp_index; if (!rlpsock || !rlpsock->nativesock) return -1; /* struct ip_addr *ipaddr, */ addr = NETI_INADDR(destaddr); dest_addr.addr = addr; if (!is_multicast(addr)) { /* We have the arp queue turned off, so we need to make sure we have a ARP entry */ /* else it will fail on first try */ result = -1; arp_index = etharp_find_addr(netxf_default, &dest_addr, ðaddr_ret, &ipaddr_ret); if (arp_index < 0) { result = etharp_query(netxf_default, &dest_addr, NULL); if (result == ERR_OK) { result = -1; t_begin = sys_jiffies(); /* wait 2 seconds (ARP TIMEOUT)*/ while ((unsigned int)sys_jiffies() - t_begin < 2000) { arp_index = etharp_find_addr(netxf_default, &dest_addr, ðaddr_ret, &ipaddr_ret); if (arp_index >= 0) { result = 0; break; } } } else { acnlog(LOG_WARNING | LOG_NETI, "netx_send_to : ARP query failure"); return -1; } } else result = 0; if (result != 0) { acnlog(LOG_WARNING | LOG_NETI, "netx_send_to : ARP failure: %d.%d.%d.%d", ntohl(addr) >> 24 & 0x000000ff, ntohl(addr) >> 16 & 0x000000ff, ntohl(addr) >> 8 & 0x000000ff, ntohl(addr) & 0x000000ff); return result; }
extern ipal_result_t ipal_arp_request(ipal_ipv4addr_t ip, ipal_arp_cachemode_t cm) { int8_t ret; err_t err; ipal_eth_hid_netif * netif_ptr; struct ip_addr ipaddr; struct eth_addr *eth_ret; struct ip_addr *ip_ret; #warning: arp cache mode useless //in lwip i can not found something similar to cachemode. if(0 == ipal_sys_hid_started) { return(ipal_res_NOK_generic); } ipaddr.addr = ipal2lwip_ipv4addr(ip); ipal_base_hid_threadsafety_lock(); netif_ptr = ipal_eth_hid_getnetif(); ret = etharp_find_addr(&(netif_ptr->netif), &ipaddr, ð_ret, &ip_ret); if(ret != -1 ) { //ip addr presente in arp tbl, allora ritorno con sucesso ipal_base_hid_threadsafety_unlock(); return(ipal_res_OK); } //se sopno qui ==> ip addr non presente in tbl arp ==> faccio una request err = etharp_request(&(netif_ptr->netif), &ipaddr); ipal_base_hid_threadsafety_unlock(); return( (ERR_OK == err) ? (ipal_res_OK) : (ipal_res_NOK_generic) ); //se sono qui vuol dire che devoi fare una arp request e che quindi la mia arp table non contiene ancora nessuna entry relatina a @ip //return(ipal_res_NOK_generic); }