mirror of
https://github.com/nmap/nmap.git
synced 2025-12-15 20:29:03 +00:00
Add intf_get_index to libdnet-stripped.
This function gets an interface from an internal interface number, such as a sockaddr_in6.sin6_scope_id.
This commit is contained in:
@@ -58,6 +58,7 @@ typedef int (*intf_handler)(const struct intf_entry *entry, void *arg);
|
||||
__BEGIN_DECLS
|
||||
intf_t *intf_open(void);
|
||||
int intf_get(intf_t *i, struct intf_entry *entry);
|
||||
int intf_get_index(intf_t *intf, struct intf_entry *entry, int af, unsigned int index);
|
||||
int intf_get_src(intf_t *i, struct intf_entry *entry, struct addr *src);
|
||||
int intf_get_dst(intf_t *i, struct intf_entry *entry, struct addr *dst);
|
||||
int intf_get_pcap_devname(const char *intf_name, char *pcapdev, int pcapdevlen);
|
||||
|
||||
@@ -257,6 +257,21 @@ _find_adapter_address(intf_t *intf, const char *device)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static IP_ADAPTER_ADDRESSES *
|
||||
_find_adapter_address_by_index(intf_t *intf, int af, unsigned int index)
|
||||
{
|
||||
IP_ADAPTER_ADDRESSES *a;
|
||||
|
||||
for (a = intf->iftable; a != NULL; a = a->Next) {
|
||||
if (af == AF_INET && index == a->IfIndex)
|
||||
return a;
|
||||
if (af == AF_INET6 && index == a->Ipv6IfIndex)
|
||||
return a;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
intf_t *
|
||||
intf_open(void)
|
||||
{
|
||||
@@ -280,6 +295,24 @@ intf_get(intf_t *intf, struct intf_entry *entry)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Look up an interface from an index, such as a sockaddr_in6.sin6_scope_id. */
|
||||
int
|
||||
intf_get_index(intf_t *intf, struct intf_entry *entry, int af, unsigned int index)
|
||||
{
|
||||
IP_ADAPTER_ADDRESSES *a;
|
||||
|
||||
if (_refresh_tables(intf) < 0)
|
||||
return (-1);
|
||||
|
||||
a = _find_adapter_address_by_index(intf, af, index);
|
||||
if (a == NULL)
|
||||
return (-1);
|
||||
|
||||
_adapter_address_to_entry(intf, a, entry);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
intf_get_src(intf_t *intf, struct intf_entry *entry, struct addr *src)
|
||||
{
|
||||
|
||||
@@ -590,6 +590,21 @@ intf_get(intf_t *intf, struct intf_entry *entry)
|
||||
return (_intf_get_aliases(intf, entry));
|
||||
}
|
||||
|
||||
/* Look up an interface from an index, such as a sockaddr_in6.sin6_scope_id. */
|
||||
int
|
||||
intf_get_index(intf_t *intf, struct intf_entry *entry, int af, unsigned int index)
|
||||
{
|
||||
char namebuf[IFNAMSIZ];
|
||||
char *devname;
|
||||
|
||||
/* af is ignored; only used in intf-win32.c. */
|
||||
devname = if_indextoname(index, namebuf);
|
||||
if (devname == NULL)
|
||||
return (-1);
|
||||
strlcpy(entry->intf_name, devname, sizeof(entry->intf_name));
|
||||
return intf_get(intf, entry);
|
||||
}
|
||||
|
||||
static int
|
||||
_match_intf_src(const struct intf_entry *entry, void *arg)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user