uint8_t FindArcRecord(EthPacket *ppacket, arp_record *parc)
{	
	memcpy((void*)&parc->ipAddr, (void*)myip, 4);
	parc->ipAddr[3] = 105;// ppacket->destId.SubnetAddr; // Parent part of device id equals last of Ip address
	
	if(eth_arptable_get(parc))
	{
		return TRUE;
	}
	else
	{
		make_arp_request(buf, parc->ipAddr);
		return FALSE;
	}
}
示例#2
0
uint8_t connect(SOCKET s, uint8_t *destinationIp, uint16_t destinationPort) {
    uint16_t i;
    char buffer[59];
	uint8_t h=0;

	memcpy(_SOCKETS[s].destinationIp, destinationIp, 4);
	_SOCKETS[s].destinationPort = destinationPort;

    make_arp_request((uint8_t*)buffer, destinationIp);
    _SOCKETS[s].clientState = ARP_REQUEST_SENT;
#ifdef ETHERSHIELD_DEBUG
    ethershieldDebug("Sent ARP request.\r\n");
#endif

    for (i = 0; _SOCKETS[s].clientState != GOT_MAC && i < MAX_ITERATIONS; i++) {
        flushSockets(); //it'll fill destinationMac on socket struct
		
		for(h=0; h<ARP_CACHE_SIZE; h++)
			if(arp_table.n > h)
				if(memcmp(destinationIp, arp_table.t[h].ipAddr, 4) == 0)
					_SOCKETS[s].clientState = GOT_MAC;
		
    }
    if (_SOCKETS[s].clientState != GOT_MAC) {
        return 0;
    }
#ifdef ETHERSHIELD_DEBUG
    ethershieldDebug("MAC received, sending TCP SYN.\r\n");
#endif

    tcp_client_send_packet((uint8_t*)buffer, destinationPort, sourcePort++, TCP_FLAG_SYN_V,
            1, 1, 0, 0, _SOCKETS[s].destinationMac,
            destinationIp);
    _SOCKETS[s].clientState = TCP_SYN_SENT;
#ifdef ETHERSHIELD_DEBUG
    ethershieldDebug("TCP SYN sent.\r\n");
#endif

    for (i = 0; _SOCKETS[s].clientState != SOCK_ESTABLISHED && i < MAX_ITERATIONS; i++) {
        flushSockets();
    }

    return _SOCKETS[s].clientState == SOCK_ESTABLISHED;
    //TODO: Maybe use a timeout instead of MAX_ITERATIONS to receive SYN+ACK
}
示例#3
0
void EtherShield::ES_make_arp_request(uint8_t *buf, uint8_t *server_ip){
	make_arp_request(buf, server_ip);
}