Beispiel #1
0
//*******************************************************************************************
//
// Function : arp_who_is
// Description : send arp request to destination ip, and save destination mac to dest_mac.
// call this function to find the destination mac address before send other packet.
//
//*******************************************************************************************
BYTE arp_who_is ( BYTE *rxtx_buffer, BYTE *dest_mac, BYTE *dest_ip )
{
	BYTE i;
	WORD dlength;

	// send arp request packet to network
	arp_send_request ( rxtx_buffer, dest_ip );

	for ( i=0; i<10; i++ )
	{
		// Time out 10x10ms = 100ms
		_delay_ms ( 10 );
		dlength = enc28j60_packet_receive( rxtx_buffer, MAX_RXTX_BUFFER );

		// destination ip address was found on network
		if ( dlength )
		{
			if ( arp_packet_is_arp ( rxtx_buffer, (WORD_BYTES){ARP_OPCODE_REPLY_V} ) )
			{
				// copy destination mac address from arp reply packet to destination mac address
				memcpy ( dest_mac, &rxtx_buffer[ ETH_SRC_MAC_P ], sizeof(MAC_ADDR) );
				return 1;
			}
		}
	}
	
	// destination ip was not found on network
	return 0;
}
Beispiel #2
0
static void ipneigh_send_nd ( const ip_addr_t * a, int unicast, const mac_addr_t * m)
{
	// vdisp_prints_xy( 0, 56, VDISP_FONT_6x8, 0, "ND  " );
	
	if (memcmp(a, &zero_address, sizeof (zero_address.ipv4.zero) ) == 0) // is IPv4 address
	{
		arp_send_request (a, unicast, m);
	}
}
Beispiel #3
0
static int cmd_arp(int argc, const cmd_args *argv)
{
    const char *cmd;

    if (argc == 1) {
        arp_usage();
        return -1;
    }

    cmd = argv[1].str;
    if (argc == 2 && strncmp(cmd, "list", sizeof("list")) == 0) {
        arp_cache_dump();
    } else if (argc == 3 && strncmp(cmd, "query", sizeof("query")) == 0) {
        const char *addr_s = argv[2].str;
        uint32_t addr = str_ip_to_int(addr_s, strlen(addr_s));

        arp_send_request(addr);
    } else {
        arp_usage();
    }

    return 0;
}
Beispiel #4
0
Datei: arp.c Projekt: bkbme/avr
/**Gets an entry out of the arp table.
 *
 */
arp_table_entry* arp_get_entry(ip_addr* ip)
{
	return NULL;
	printf("arp_get_entry 0\n");
	int8_t pos = arp_table_contains(ip);
	if(pos == -1)
	{
		arp_send_request(ip);
		while(pos == -1)
		{
			printf("arp_get_entry 1\n");
			pos = arp_table_contains(ip);
		}
	}

	if(pos >= 0 && pos < arp_table_pos)
	{
		return arp_table+pos;
	}
	else
	{
		return NULL;
	}
}