Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2007-01-23 12:23:54 +0300
committerCorinna Vinschen <corinna@vinschen.de>2007-01-23 12:23:54 +0300
commit4b13fd15d48343a2625df0e87606032ee2b1e7af (patch)
tree647741067902775886d082636c8c47dd064b7ff9 /winsup
parentbff438913761968193960dc32b1db372ebe509ee (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')
-rw-r--r--winsup/cygwin/ChangeLog6
-rw-r--r--winsup/cygwin/net.cc53
2 files changed, 40 insertions, 19 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 19e0298fa..bccfee384 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,9 @@
+2007-01-23 Corinna Vinschen <corinna@vinschen.de>
+
+ * net.cc (if_nametoindex): Free IP_ADAPTER_ADDRESSES memory.
+ (if_indextoname): Ditto.
+ (if_nameindex): Ditto. Remove duplicate indexed entries in result.
+
2007-01-21 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (WSAIoctl): Define.
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