From c3b25e8111dc304486537d7cc60e54ba27c04fa0 Mon Sep 17 00:00:00 2001 From: AndersBroman Date: Wed, 28 Sep 2016 13:31:14 +0200 Subject: Use g_slist_prepend, it should be faster if there's a lot of IP addresses Change-Id: I3861c0af24523315db6889b22ec93159174ba86f Reviewed-on: https://code.wireshark.org/review/17966 Petri-Dish: Anders Broman Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- caputils/capture-pcap-util-unix.c | 6 ++++++ caputils/capture-pcap-util.c | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'caputils') diff --git a/caputils/capture-pcap-util-unix.c b/caputils/capture-pcap-util-unix.c index 29be6d2b83..66a54c8591 100644 --- a/caputils/capture-pcap-util-unix.c +++ b/caputils/capture-pcap-util-unix.c @@ -211,6 +211,9 @@ get_interface_list(int *err, char **err_str) g_list_foreach(il, search_for_if_cb, &user_data); if (user_data.if_info != NULL) { if_info_add_address(user_data.if_info, &ifr->ifr_addr); + if (user_data.if_info->addrs) { + g_slist_reverse(user_data.if_info->addrs); + } goto next; } @@ -260,6 +263,9 @@ get_interface_list(int *err, char **err_str) strncmp(ifr->ifr_name, "lo", 2) == 0); if_info = if_info_new(ifr->ifr_name, NULL, loopback); if_info_add_address(if_info, &ifr->ifr_addr); + if (if_info->addrs) { + g_slist_reverse(if_info->addrs); + } if (loopback) il = g_list_append(il, if_info); else { diff --git a/caputils/capture-pcap-util.c b/caputils/capture-pcap-util.c index c014f83872..a41b7668d5 100644 --- a/caputils/capture-pcap-util.c +++ b/caputils/capture-pcap-util.c @@ -423,7 +423,7 @@ if_info_add_address(if_info_t *if_info, struct sockaddr *addr) if_addr->ifat_type = IF_AT_IPv4; if_addr->addr.ip4_addr = *((guint32 *)&(ai->sin_addr.s_addr)); - if_info->addrs = g_slist_append(if_info->addrs, if_addr); + if_info->addrs = g_slist_prepend(if_info->addrs, if_addr); break; case AF_INET6: @@ -433,7 +433,7 @@ if_info_add_address(if_info_t *if_info, struct sockaddr *addr) memcpy((void *)&if_addr->addr.ip6_addr, (void *)&ai6->sin6_addr.s6_addr, sizeof if_addr->addr.ip6_addr); - if_info->addrs = g_slist_append(if_info->addrs, if_addr); + if_info->addrs = g_slist_prepend(if_info->addrs, if_addr); break; } } @@ -452,6 +452,10 @@ if_info_ip(if_info_t *if_info, pcap_if_t *d) if (a->addr != NULL) if_info_add_address(if_info, a->addr); } + + if(if_info->addrs){ + if_info->addrs = g_slist_reverse(if_info->addrs); + } } #ifdef HAVE_PCAP_REMOTE -- cgit v1.2.1