bool ToSaMeshNode::Send(appMessage Message) { meshMessage mm = AppToMesh(Message); mm.pid = nextpid++; if ((mm.source == TOSA_MESH_BROADCAST) || (mm.source == TOSA_MESH_NOADDRESS)) mm.source = addr; if (Message.dest != TOSA_MESH_BROADCAST && mm.to == TOSA_MESH_NOADDRESS) SendArpRequest(Message.dest); Send(mm); return true; }
uchar * ArpEther(struct udpinfo *u, uchar *ecpy) { struct ether_header *ehdr; uchar *binip, *gbinip, *Ip, *ep; int size, retry, timeoutsecs; binip = (uchar *)&u->dip.s_addr; gbinip = (uchar *)&thisgip.s_addr; /* First check local cache. If found, return with pointer to MAC. */ ep = EtherFromCache(binip); if (ep) { if (ecpy) { memcpy((char *)ecpy, (char *)ep,6); ep = ecpy; } return(ep); } retry = 0; while(1) { /* If IP is not on this net, the get the GATEWAY IP address. */ if (!IpIsOnThisNet(binip)) { ep = EtherFromCache(gbinip); if (ep) { if (ecpy) { memcpy((char *)ecpy, (char *)ep,6); ep = ecpy; } return(ep); } SendArpRequest(gbinip); Ip = gbinip; } else { SendArpRequest(binip); Ip = binip; } /* Now that the request has been issued, wait for a while to see if * the ARP cache is loaded with the result of the request. */ for(timeoutsecs=0; timeoutsecs<1000000; timeoutsecs++) { ep = EtherFromCache(Ip); if (ep) break; size = mon_recvenetpkt(u->packet,u->plen); if (size == 0) continue; ehdr = (struct ether_header *)u->packet; if (!memcmp(ehdr->ether_shost.ether_addr_octet, thismac.ether_addr_octet,6)) { continue; } if (ehdr->ether_type == ecs(ETHERTYPE_ARP)) { processARP(ehdr,size); } } if (ep) { if (ecpy) { memcpy((char *)ecpy, (char *)ep,6); ep = ecpy; } return(ep); } retry++; } return(0); }