| 271 | #define ORDERS_SIZE(x) sizeof(x) / sizeof(x[0]) |
| 272 | |
| 273 | static int |
| 274 | calcorders(struct ifaddrs *ifa, struct ifa_queue *q) |
| 275 | { |
| 276 | struct ifaddrs *prev; |
| 277 | struct ifa_order_elt *cur; |
| 278 | unsigned int ord, af, ifa_ord; |
| 279 | |
| 280 | prev = NULL; |
| 281 | cur = NULL; |
| 282 | ord = 0; |
| 283 | ifa_ord = 0; |
| 284 | |
| 285 | while (ifa != NULL) { |
| 286 | if (prev == NULL || |
| 287 | strcmp(ifa->ifa_name, prev->ifa_name) != 0) { |
| 288 | cur = calloc(1, sizeof(*cur)); |
| 289 | |
| 290 | if (cur == NULL) |
| 291 | return (-1); |
| 292 | |
| 293 | TAILQ_INSERT_TAIL(q, cur, link); |
| 294 | cur->if_order = ifa_ord ++; |
| 295 | cur->ifa = ifa; |
| 296 | ord = 0; |
| 297 | } |
| 298 | |
| 299 | if (ifa->ifa_addr) { |
| 300 | af = ifa->ifa_addr->sa_family; |
| 301 | |
| 302 | if (af < ORDERS_SIZE(cur->af_orders) && |
| 303 | cur->af_orders[af] == 0) |
| 304 | cur->af_orders[af] = ++ord; |
| 305 | } |
| 306 | prev = ifa; |
| 307 | ifa = ifa->ifa_next; |
| 308 | } |
| 309 | |
| 310 | return (0); |
| 311 | } |
| 312 | |
| 313 | static int |
| 314 | cmpifaddrs(struct ifaddrs *a, struct ifaddrs *b, struct ifa_queue *q) |