+ usermax = 0;
+
+ /*
+ * If there are more interfaces on the list, count
+ * them. This allows the caller to set ifmr->ifm_count
+ * to 0 on the first call to know how much space to
+ * allocate.
+ */
+ LIST_FOREACH(ep, &ifm->ifm_list, ifm_list)
+ usermax++;
+
+ /*
+ * Don't allow the user to ask for too many
+ * or a negative number.
+ */
+ if (ifmr->ifm_count > usermax)
+ ifmr->ifm_count = usermax;
+ else if (ifmr->ifm_count < 0)
+ return (EINVAL);