ifmap
static struct ifmap *
struct ifmap *ifmap = snl_allocz(ss, sizeof(*ifmap));
if (iface->link.ifi_index >= ifmap->size) {
size_t new_size = MAX(ifmap->size, 32);
memcpy(ifaces, ifmap->ifaces, ifmap->size * sizeof(void *));
ifmap->ifaces = ifaces;
ifmap->size = new_size;
ifmap->ifaces[iface->link.ifi_index] = iface;
ifmap->count++;
iface->idx = ifmap->count;
return (ifmap);
prepare_ifaddrs(struct snl_state *ss, struct ifmap *ifmap)
if (ifindex >= ifmap->size || ifmap->ifaces[ifindex] == NULL)
struct iface *iface = ifmap->ifaces[ifindex];
struct ifmap *ifmap = prepare_ifmap(&ss, args->ifname);
struct iface **sorted_ifaces = snl_allocz(&ss, ifmap->count * sizeof(void *));
for (uint32_t i = 0, num = 0; i < ifmap->size; i++) {
if (ifmap->ifaces[i] != NULL) {
sorted_ifaces[num++] = ifmap->ifaces[i];
if (num == ifmap->count)
qsort(sorted_ifaces, ifmap->count, sizeof(void *), cmp_iface);
prepare_ifaddrs(&ss, ifmap);
for (uint32_t i = 0, num = 0; i < ifmap->count; i++) {
struct ifmaddrs *ifma, *ifmap;
if (getifmaddrs(&ifmap) != 0) {
for (ifma = ifmap; ifma; ifma = ifma->ifma_next) {
freeifmaddrs(ifmap);
if ((ifmap = realloc(ifmap, size)) == NULL)
memset(&ifmap[ifmap_size], 0,
if (*ifmap[ifindex].ifname != '\0')
strlcpy(ifmap[ifindex].ifname, ifa->ifa_name, IFNAMSIZ);
return (ifmap);
struct ifmap_entry *ifmap = NULL;
struct ifmaddrs *ifmap, *ifma;
if (aflag && getifmaddrs(&ifmap) != 0)
for (ifma = next_ifma(ifmap, ifa->ifa_name,
freeifmaddrs(ifmap);
strlcpy(iface_name, ifmap[nh->ifindex].ifname,
ifmap = prepare_ifmap(&ifmap_size);
static struct ifmap_entry *ifmap;
static struct ifmap_entry *ifmap;
strlcpy(iface_name, ifmap[nh->ifindex].ifname,
strlcpy(iface_name, ifmap[nh->aifindex].ifname,
ifmap = prepare_ifmap(&ifmap_size);
ifmap = prepare_ifmap(&ifmap_size);
strlcpy(prettyname, ifmap[rtm->rtm_index].ifname,
static struct ifmap_entry *ifmap;
if ((ifmap = realloc(ifmap, size)) == NULL)
memset(&ifmap[ifmap_size], 0,
if (*ifmap[link.ifi_index].ifname != '\0')
strlcpy(ifmap[link.ifi_index].ifname, link.ifla_ifname, IFNAMSIZ);
ifmap[link.ifi_index].mtu = link.ifla_mtu;
return (ifmap);
strlcpy(prettyname, ifmap[rt->rta_oif].ifname,
rt->rtax_mtu = ifmap[rt->rta_oif].mtu;
ifmap = prepare_ifmap_netlink(&ss, &ifmap_size);
if (ifmap == NULL) {
static struct ifmap_entry *ifmap;
struct ifmap_entry *ifmap = NULL;
struct ifmaddrs *ifmap, *ifma;
ifmap = NULL;
if (getifmaddrs(&ifmap) != 0) {
for (ifma = ifmap; ifma; ifma = ifma->ifma_next) {
if (ifmap != NULL)
freeifmaddrs(ifmap);