diff --git a/src/interface.c b/src/interface.c index 47a8c4b..fc954f9 100644 --- a/src/interface.c +++ b/src/interface.c @@ -54,7 +54,6 @@ struct ipx_interface *get_interfaces(int ifnum) { struct ipx_interface *nics = NULL, *enic = NULL; IP_ADAPTER_INFO *ifptr = ifroot; - int this_ifnum = 0; while(ifptr) { struct reg_value rv; @@ -73,11 +72,6 @@ struct ipx_interface *get_interfaces(int ifnum) { continue; } - if(ifnum >= 0 && this_ifnum++ != ifnum) { - ifptr = ifptr->Next; - continue; - } - struct ipx_interface *nnic = malloc(sizeof(struct ipx_interface)); if(!nnic) { log_printf(LOG_ERROR, "Out of memory! (Tried to allocate %u bytes)", (unsigned int)sizeof(struct ipx_interface)); @@ -135,6 +129,25 @@ struct ipx_interface *get_interfaces(int ifnum) { free(ifroot); + /* Delete every entry in the NIC list except the requested one */ + if(ifnum >= 0) { + int this_ifnum = 0; + + while(nics && this_ifnum++ < ifnum) { + struct ipx_interface *dnic = nics; + nics = nics->next; + + free(dnic); + } + + while(nics && nics->next) { + struct ipx_interface *dnic = nics->next; + nics->next = nics->next->next; + + free(dnic); + } + } + return nics; } diff --git a/src/ipxconfig.cpp b/src/ipxconfig.cpp index cb1471c..431da53 100644 --- a/src/ipxconfig.cpp +++ b/src/ipxconfig.cpp @@ -192,9 +192,10 @@ static LRESULT CALLBACK main_wproc(HWND window, UINT msg, WPARAM wp, LPARAM lp) } }else if(HIWORD(wp) == CBN_SELCHANGE && LOWORD(wp) == ID_PRI_LIST) { int nic = ComboBox_GetCurSel(windows.primary); + int this_nic = 1; for(iface_list::iterator i = nics.begin(); i != nics.end(); i++) { - i->primary = (nic > 0 && i - nics.begin() == nic - 1); + i->primary = (i->enabled && this_nic++ == nic); } }