diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2007-01-23 12:23:54 +0300 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2007-01-23 12:23:54 +0300 |
commit | 4b13fd15d48343a2625df0e87606032ee2b1e7af (patch) | |
tree | 647741067902775886d082636c8c47dd064b7ff9 /winsup/cygwin/net.cc | |
parent | bff438913761968193960dc32b1db372ebe509ee (diff) |
* net.cc (if_nametoindex): Free IP_ADAPTER_ADDRESSES memory.
(if_indextoname): Ditto.
(if_nameindex): Ditto. Remove duplicate indexed entries in result.
Diffstat (limited to 'winsup/cygwin/net.cc')
-rw-r--r-- | winsup/cygwin/net.cc | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index c6cf34b60..9e5e135a8 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -2092,6 +2092,7 @@ extern "C" unsigned if_nametoindex (const char *name) { PIP_ADAPTER_ADDRESSES pap = NULL; + unsigned index = 0; myfault efault; if (efault.faulted (EFAULT)) @@ -2108,15 +2109,20 @@ if_nametoindex (const char *name) *c = '\0'; for (; pap; pap = pap->Next) if (strcasematch (lname, pap->AdapterName)) - return pap->IfIndex; + { + index = pap->IfIndex; + break; + } + free (pap); } - return 0; + return index; } extern "C" char * if_indextoname (unsigned ifindex, char *ifname) { PIP_ADAPTER_ADDRESSES pap = NULL; + char *name = NULL; myfault efault; if (efault.faulted (EFAULT)) @@ -2128,12 +2134,14 @@ if_indextoname (unsigned ifindex, char *ifname) for (; pap; pap = pap->Next) if (ifindex == pap->IfIndex) { - strcpy (ifname, pap->AdapterName); - return ifname; + name = strcpy (ifname, pap->AdapterName); + break; } + free (pap); } - set_errno (ENXIO); - return NULL; + else + set_errno (ENXIO); + return name; } extern "C" struct if_nameindex * @@ -2157,22 +2165,29 @@ if_nameindex (void) malloc ((cnt + 1) * sizeof (struct if_nameindex) + cnt * IF_NAMESIZE); if (!iflist) + set_errno (ENOBUFS); + else { - set_errno (ENOBUFS); - return NULL; - } - ifnamelist = (char (*)[IF_NAMESIZE]) (iflist + cnt + 1); - for (pap = pa0, cnt = 0; pap; pap = pap->Next, ++cnt) - { - iflist[cnt].if_index = pap->IfIndex ?: pap->Ipv6IfIndex; - strcpy (iflist[cnt].if_name = ifnamelist[cnt], pap->AdapterName); + ifnamelist = (char (*)[IF_NAMESIZE]) (iflist + cnt + 1); + for (pap = pa0, cnt = 0; pap; pap = pap->Next) + { + for (int i = 0; i < cnt; ++i) + if (iflist[i].if_index == (pap->IfIndex ?: pap->Ipv6IfIndex)) + goto outer_loop; + iflist[cnt].if_index = pap->IfIndex ?: pap->Ipv6IfIndex; + strcpy (iflist[cnt].if_name = ifnamelist[cnt], pap->AdapterName); + ++cnt; + outer_loop: + ; + } + iflist[cnt].if_index = 0; + iflist[cnt].if_name = NULL; } - iflist[cnt].if_index = 0; - iflist[cnt].if_name = NULL; - return iflist; + free (pa0); } - set_errno (ENXIO); - return NULL; + else + set_errno (ENXIO); + return iflist; } extern "C" void |