From 711d5a0fa8c929eca626b668296409f0e5d39d67 Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Sat, 11 Jun 2016 14:17:01 +0200 Subject: [PATCH] Removed pointer to avoid memory leaks --- arp.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arp.c b/arp.c index d6cd8d1..e13fc10 100644 --- a/arp.c +++ b/arp.c @@ -256,6 +256,8 @@ int arp_scan(int sockfd, int ifindex, struct sockaddr_in *ipaddr, unsigned char /* The maximum address on the subnet */ unsigned long ip_max = ip_counter | (~ntohl(netmask->sin_addr.s_addr)); + struct ether_arp result; + while (ip_counter < ip_max) { char ip_string[16]; struct in_addr target_ip; @@ -267,12 +269,11 @@ int arp_scan(int sockfd, int ifindex, struct sockaddr_in *ipaddr, unsigned char send_arp_request(sockfd, ifindex, ipaddr, macaddr, target_ip); - struct ether_arp *result = malloc(sizeof(struct ether_arp)); - int isalive = listen_arp_frame(sockfd, result); + int isalive = listen_arp_frame(sockfd, &result); if (isalive == 0) { printf("Host %d.%d.%d.%d is alive!\n", - result->arp_spa[0],result->arp_spa[1], - result->arp_spa[2],result->arp_spa[3]); + result.arp_spa[0],result.arp_spa[1], + result.arp_spa[2],result.arp_spa[3]); } ++ip_counter;