Skip to content

Commit

Permalink
Merge pull request #987 from greenbone/mergify/bp/stable/pr-986
Browse files Browse the repository at this point in the history
Replace own implementation of get_iface_index with if_nametoindex() (backport #986)
  • Loading branch information
ArnoStiefvater authored Dec 2, 2021
2 parents 86c2a0d + e9e2255 commit f5e0e66
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions misc/pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1340,9 +1340,7 @@ int
get_iface_index (struct in6_addr *ipaddr, int *ifindex)
{
struct in6_addr src_addr;
struct ifreq ifr;
char *if_name, *ip_address;
int soc;

// We get the local address to use, with the remote address.
memset (&src_addr, '\0', sizeof (struct in6_addr));
Expand All @@ -1358,24 +1356,7 @@ get_iface_index (struct in6_addr *ipaddr, int *ifindex)
return -1;
}

// Create the raw socket
soc = socket (AF_INET, SOCK_DGRAM, 0);
if (soc == -1)
{
g_debug ("%s: %s", __func__, strerror (errno));
return -1;
}
// Get the interface index using the iface name
memcpy (ifr.ifr_name, if_name, strlen (if_name));
g_free (if_name);
if (ioctl (soc, SIOCGIFINDEX, &ifr) == -1)
{
g_debug ("%s: %s", __func__, strerror (errno));
close (soc);
return -1;
}
*ifindex = ifr.ifr_ifindex;
*ifindex = if_nametoindex (if_name);

close (soc);
return 0;
}

0 comments on commit f5e0e66

Please sign in to comment.