Esempio n. 1
0
File: arp.c Progetto: fallen/witm
void arp_request(eth_addr_t to, eth_addr_t from, eth_addr_t sha, ip_addr_t spa, eth_addr_t tha, ip_addr_t tpa) {

	int ret;
	//int i;
	struct arp_packet packet;
	//uint32_t spa2, tpa2;

	//spa2 = *(uint32_t *)spa;
	//tpa2 = *(uint32_t *)tpa;

	eth_pack_hdr(&packet, to, from, ETH_TYPE_ARP);
	arp_pack_hdr_ethip((uint8_t *)&packet + sizeof(struct eth_hdr), ARP_OP_REQUEST, sha, spa, tha, tpa);

	ret = pcap_sendpacket(handle, (u_char *)&packet, sizeof(struct arp_packet));

	if (ret < 0) {
		printf("ERROR : failed to forward packet\n");
		exit(1);
	}

//	printf("On envoie un paquet arp request : \n");
/*	for (i = 0 ; i < sizeof(struct arp_packet) ; i++)
		printf("0x%02hhX ", *((uint8_t *)&packet + i));
	printf("\n");
*/
}
Esempio n. 2
0
static void
arpd_send(eth_t *eth, int op,
    struct addr *sha, struct addr *spa,
    struct addr *tha, struct addr *tpa)
{
	u_char pkt[ETH_HDR_LEN + ARP_HDR_LEN + ARP_ETHIP_LEN];

	eth_pack_hdr(pkt, tha->addr_eth, sha->addr_eth, ETH_TYPE_ARP);
	arp_pack_hdr_ethip(pkt + ETH_HDR_LEN, op, sha->addr_eth,
	    spa->addr_ip, tha->addr_eth, tpa->addr_ip);
	
	if (op == ARP_OP_REQUEST) {
		syslog(LOG_DEBUG, "%s: who-has %s tell %s", __func__,
		    addr_ntoa(tpa), addr_ntoa(spa));
	} else if (op == ARP_OP_REPLY) {
		syslog(LOG_INFO, "arp reply %s is-at %s",
		    addr_ntoa(spa), addr_ntoa(sha));
	}
	if (eth_send(eth, pkt, sizeof(pkt)) != sizeof(pkt))
		syslog(LOG_ERR, "couldn't send packet: %m");
}