ifl_iterator = ifl;
- /* seek to end of list to show entries in original input order */
- while (ifl_iterator->next != NULL) {
- ifl_iterator = ifl_iterator->next;
- }
-
while (ifl_iterator != NULL) {
*ifacelist = (char *)realloc(*ifacelist, ((strlen(*ifacelist) + strlen(ifl_iterator->interface) + 2) * sizeof(char)));
if (*ifacelist == NULL) {
strcat(*ifacelist, temp);
}
- ifl_iterator = ifl_iterator->prev;
+ ifl_iterator = ifl_iterator->next;
}
iflistfree(&ifl);
int iflistadd(iflist **ifl, const char *iface, const uint32_t bandwidth)
{
- iflist *newif;
+ iflist *newif = NULL, *ifl_iterator = *ifl;
newif = malloc(sizeof(iflist));
if (newif == NULL) {
return 0;
}
- newif->next = *ifl;
- newif->prev = NULL;
+ newif->next = NULL;
if (*ifl != NULL) {
- (*ifl)->prev = newif;
+ while (ifl_iterator->next != NULL) {
+ ifl_iterator = ifl_iterator->next;
+ }
+ ifl_iterator->next = newif;
+ } else {
+ *ifl = newif;
}
- *ifl = newif;
-
strncpy_nt(newif->interface, iface, 32);
newif->bandwidth = bandwidth;
ret = iflistadd(&ifl, "eth0", 0);
ck_assert_int_eq(ret, 1);
- ck_assert_int_eq(ifl->bandwidth, 0);
ck_assert_str_eq(ifl->interface, "eth0");
+ ck_assert_int_eq(ifl->bandwidth, 0);
ck_assert_ptr_eq(ifl->next, NULL);
- ck_assert_ptr_eq(ifl->prev, NULL);
ret = iflistadd(&ifl, "eth1", 1);
ck_assert_int_eq(ret, 1);
- ck_assert_int_eq(ifl->bandwidth, 1);
- ck_assert_str_eq(ifl->interface, "eth1");
+ ck_assert_str_eq(ifl->interface, "eth0");
+ ck_assert_int_eq(ifl->bandwidth, 0);
ck_assert_ptr_ne(ifl->next, NULL);
- ck_assert_ptr_eq(ifl->prev, NULL);
+ ck_assert_str_eq(ifl->next->interface, "eth1");
+ ck_assert_int_eq(ifl->next->bandwidth, 1);
ret = iflistadd(&ifl, "eth0", 2);
ck_assert_int_eq(ret, 1);
- ck_assert_int_eq(ifl->bandwidth, 2);
ck_assert_str_eq(ifl->interface, "eth0");
+ ck_assert_int_eq(ifl->bandwidth, 0);
ck_assert_ptr_ne(ifl->next, NULL);
- ck_assert_ptr_eq(ifl->prev, NULL);
-
- ret = iflistadd(&ifl, "eth2", 10);
- ck_assert_int_eq(ret, 1);
- ck_assert_int_eq(ifl->bandwidth, 10);
- ck_assert_str_eq(ifl->interface, "eth2");
- ck_assert_ptr_ne(ifl->next, NULL);
- ck_assert_ptr_eq(ifl->prev, NULL);
+ ck_assert_str_eq(ifl->next->interface, "eth1");
+ ck_assert_int_eq(ifl->next->bandwidth, 1);
+ ck_assert_ptr_ne(ifl->next->next, NULL);
+ ck_assert_str_eq(ifl->next->next->interface, "eth0");
+ ck_assert_int_eq(ifl->next->next->bandwidth, 2);
iflistfree(&ifl);
ck_assert_ptr_eq(ifl, NULL);