Use net_ifinfo how it's intended (?) to be used

This commit is contained in:
Gregor Richards 2016-11-29 23:08:48 -05:00
parent c342c103ae
commit 025993231f

View File

@ -156,7 +156,7 @@ bool natt_open_port(struct natt_status *status, struct sockaddr *addr, socklen_t
bool natt_open_port_any(struct natt_status *status, uint16_t port, enum socket_protocol proto)
{
struct net_ifinfo list;
struct net_ifinfo *list;
bool ret = false;
size_t i;
struct addrinfo hints = {0}, *addr;
@ -165,13 +165,15 @@ bool natt_open_port_any(struct natt_status *status, uint16_t port, enum socket_p
sprintf(port_str, "%hu", port);
/* get our interfaces */
if (!net_ifinfo_new(&list))
if ((list = calloc(1, sizeof(struct net_ifinfo))) == NULL)
return false;
if (!net_ifinfo_new(list))
return false;
/* loop through them */
for (i = 0; i < list.size; i++)
for (i = 0; i < list->size; i++)
{
struct net_ifinfo_entry *entry = list.entries + i;
struct net_ifinfo_entry *entry = list->entries + i;
/* ignore localhost */
if (!strcmp(entry->host, "127.0.0.1") || !strcmp(entry->host, "::1"))
@ -185,7 +187,8 @@ bool natt_open_port_any(struct natt_status *status, uint16_t port, enum socket_p
}
}
/* BUGS! net_ifinfo_free(&list); */
/* This really shouldn't free list, but does */
net_ifinfo_free(list);
return ret;
}