diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -341,11 +341,15 @@ free(formatstr); } +/* Skip sorting for interfaces with more IP addresses than this limit */ +#define IFADDR_SORT_LIMIT 32 + static struct ifaddrs * sortifaddrs(struct ifaddrs *list, int (*compare)(struct ifaddrs *, struct ifaddrs *, struct ifa_queue *), struct ifa_queue *q) { + int count; struct ifaddrs *right, *temp, *last, *result, *next, *tail; right = list; @@ -358,7 +362,10 @@ if (!list || !list->ifa_next) return (list); + count = 0; while (temp && temp->ifa_next) { + if (count++ >= IFADDR_SORT_LIMIT) + return (list); last = right; right = right->ifa_next; temp = temp->ifa_next->ifa_next;