+ /* Remove all instances on carrier drop */
+ if (strcmp(i->reason, "NOCARRIER") == 0 ||
+ strcmp(i->reason, "DEPARTED") == 0 ||
+ strcmp(i->reason, "STOPPED") == 0)
+ {
+ l = NULL;
+ for (e = con->interfaces; e; e = n) {
+ n = e->next;
+ if (strcmp(e->ifname, i->ifname) == 0) {
+ if (strcmp(e->type, i->type) == 0)
+ l = nl = e;
+ else {
+ if (l)
+ l->next = e->next;
+ else
+ con->interfaces = e->next;
+ free(e);
+ }
+ } else
+ l = e;
+ }
+ }
+
+ /* Find our pointer */
+ if (nl == NULL) {
+ l = NULL;
+ for (e = con->interfaces; e; e = e->next) {
+ if (strcmp(e->ifname, i->ifname) == 0 &&
+ strcmp(e->type, i->type) == 0)
+ {
+ nl = e;
+ break;
+ }
+ l = e;
+ }
+ }
+ if (nl) {
+ /* Preserve the pointer for wireless history */
+ n = nl->next;
+ memcpy(nl, i, sizeof(*i));
+ nl->next = n;
+ free(i);
+ i = nl;
+ } else {
+ /* Append it then */
+ if (l)
+ l->next = i;
+ else
+ con->interfaces = i;
+ i->next = NULL;
+ }
+
+ /* Sort! */
+ n = nl = NULL;