mirror of
https://github.com/nmap/nmap.git
synced 2026-01-18 12:19:02 +00:00
Made getInterfaceByName() return IPv6 interface information.
This commit is contained in:
@@ -1311,10 +1311,11 @@ int devname2ipaddr(char *dev, struct sockaddr_storage *addr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Looks for an interface with the given name (iname), and returns the
|
||||
corresponding interface_info if found. Will accept a match of
|
||||
devname or devfullname. Returns NULL if none found */
|
||||
struct interface_info *getInterfaceByName(const char *iname) {
|
||||
/* Looks for an interface with the given name (iname) and address
|
||||
family type, and returns the corresponding interface_info if found.
|
||||
Will accept a match of devname or devfullname. Returns NULL if
|
||||
none found */
|
||||
struct interface_info *getInterfaceByName(const char *iname, int af) {
|
||||
struct interface_info *ifaces;
|
||||
int numifaces = 0;
|
||||
int ifnum;
|
||||
@@ -1322,8 +1323,9 @@ struct interface_info *getInterfaceByName(const char *iname) {
|
||||
ifaces = getinterfaces(&numifaces, NULL, 0);
|
||||
|
||||
for (ifnum = 0; ifnum < numifaces; ifnum++) {
|
||||
if (strcmp(ifaces[ifnum].devfullname, iname) == 0 ||
|
||||
strcmp(ifaces[ifnum].devname, iname) == 0)
|
||||
if ((strcmp(ifaces[ifnum].devfullname, iname) == 0 ||
|
||||
strcmp(ifaces[ifnum].devname, iname) == 0) &&
|
||||
ifaces[ifnum].addr.ss_family == af)
|
||||
return &ifaces[ifnum];
|
||||
}
|
||||
|
||||
@@ -2993,7 +2995,7 @@ static int route_dst_netlink(const struct sockaddr_storage *dst,
|
||||
struct interface_info *ii;
|
||||
ii = NULL;
|
||||
if (device != NULL && device[0] != '\0') {
|
||||
ii = getInterfaceByName(device);
|
||||
ii = getInterfaceByName(device, rtmsg->rtm_family);
|
||||
if (ii == NULL)
|
||||
netutil_fatal("Could not find interface %s which was specified by -e", device);
|
||||
}
|
||||
@@ -3012,7 +3014,7 @@ static int route_dst_netlink(const struct sockaddr_storage *dst,
|
||||
intf_index = *(int *) RTA_DATA(rtattr);
|
||||
rc = intf_name(intf_index, namebuf, sizeof(namebuf));
|
||||
assert(rc != -1);
|
||||
ii = getInterfaceByName(namebuf);
|
||||
ii = getInterfaceByName(namebuf, rtmsg->rtm_family);
|
||||
if (ii == NULL)
|
||||
netutil_fatal("%s: can't find interface \"%s\"", __func__, namebuf);
|
||||
} else if (rtattr->rta_type == RTA_PREFSRC && rnfo->srcaddr.ss_family == AF_UNSPEC) {
|
||||
@@ -3108,7 +3110,7 @@ static int route_dst_generic(const struct sockaddr_storage *dst,
|
||||
}
|
||||
|
||||
if (device!=NULL && device[0]!='\0'){
|
||||
iface = getInterfaceByName(device);
|
||||
iface = getInterfaceByName(device, dst->ss_family);
|
||||
if (!iface)
|
||||
netutil_fatal("Could not find interface %s which was specified by -e", device);
|
||||
} else {
|
||||
|
||||
@@ -357,10 +357,11 @@ struct dnet_collector_route_nfo {
|
||||
int numifaces;
|
||||
};
|
||||
|
||||
/* Looks for an interface with the given name (iname), and returns the
|
||||
corresponding interface_info if found. Will accept a match of
|
||||
devname or devfullname. Returns NULL if none found */
|
||||
struct interface_info *getInterfaceByName(const char *iname);
|
||||
/* Looks for an interface with the given name (iname) and address
|
||||
family type, and returns the corresponding interface_info if found.
|
||||
Will accept a match of devname or devfullname. Returns NULL if
|
||||
none found */
|
||||
struct interface_info *getInterfaceByName(const char *iname, int af);
|
||||
|
||||
/* Parse the system routing table, converting each route into a
|
||||
sys_route entry. Returns an array of sys_routes. numroutes is set
|
||||
|
||||
@@ -51,7 +51,8 @@ LUALIB_API int l_dnet_get_interface_info (lua_State *L)
|
||||
{
|
||||
char ipstr[INET6_ADDRSTRLEN];
|
||||
struct addr src, bcast;
|
||||
struct interface_info *ii = getInterfaceByName(luaL_checkstring(L, 1));
|
||||
struct interface_info *ii = getInterfaceByName(luaL_checkstring(L, 1),
|
||||
o.af());
|
||||
|
||||
if (ii == NULL) {
|
||||
lua_pushnil(L);
|
||||
@@ -155,7 +156,7 @@ static int ethernet_open (lua_State *L)
|
||||
{
|
||||
nse_dnet_udata *udata = (nse_dnet_udata *) luaL_checkudata(L, 1, DNET_METATABLE);
|
||||
const char *interface_name = luaL_checkstring(L, 2);
|
||||
struct interface_info *ii = getInterfaceByName(interface_name);
|
||||
struct interface_info *ii = getInterfaceByName(interface_name, o.af());
|
||||
|
||||
if (ii == NULL || ii->device_type != devt_ethernet)
|
||||
return luaL_argerror(L, 2, "device is not valid ethernet interface");
|
||||
|
||||
Reference in New Issue
Block a user