Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
95298b44
Commit
95298b44
authored
Dec 01, 2016
by
Bruno Jesus
Committed by
Alexandre Julliard
Dec 01, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
iphlpapi: Ensure GetIpAddrTable returns loopback addresses in the end.
Signed-off-by:
Bruno Jesus
<
00cpxxx@gmail.com
>
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
61cb24f4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
+24
-6
iphlpapi_main.c
dlls/iphlpapi/iphlpapi_main.c
+21
-6
iphlpapi.c
dlls/iphlpapi/tests/iphlpapi.c
+3
-0
No files found.
dlls/iphlpapi/iphlpapi_main.c
View file @
95298b44
...
@@ -134,17 +134,27 @@ DWORD WINAPI AllocateAndGetIfTableFromStack(PMIB_IFTABLE *ppIfTable,
...
@@ -134,17 +134,27 @@ DWORD WINAPI AllocateAndGetIfTableFromStack(PMIB_IFTABLE *ppIfTable,
}
}
static
int
IpAddrTableSorter
(
const
void
*
a
,
const
void
*
b
)
static
int
IpAddrTable
Numeric
Sorter
(
const
void
*
a
,
const
void
*
b
)
{
{
int
ret
;
int
ret
=
0
;
if
(
a
&&
b
)
if
(
a
&&
b
)
ret
=
((
const
MIB_IPADDRROW
*
)
a
)
->
dwAddr
-
((
const
MIB_IPADDRROW
*
)
b
)
->
dwAddr
;
ret
=
((
const
MIB_IPADDRROW
*
)
a
)
->
dwAddr
-
((
const
MIB_IPADDRROW
*
)
b
)
->
dwAddr
;
else
ret
=
0
;
return
ret
;
return
ret
;
}
}
static
int
IpAddrTableLoopbackSorter
(
const
void
*
a
,
const
void
*
b
)
{
const
MIB_IPADDRROW
*
left
=
a
,
*
right
=
b
;
int
ret
=
0
;
if
(
isIfIndexLoopback
(
left
->
dwIndex
))
ret
=
1
;
else
if
(
isIfIndexLoopback
(
right
->
dwIndex
))
ret
=
-
1
;
return
ret
;
}
/******************************************************************
/******************************************************************
* AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
* AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@)
...
@@ -173,7 +183,7 @@ DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable,
...
@@ -173,7 +183,7 @@ DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable,
ret
=
getIPAddrTable
(
ppIpAddrTable
,
heap
,
flags
);
ret
=
getIPAddrTable
(
ppIpAddrTable
,
heap
,
flags
);
if
(
!
ret
&&
bOrder
)
if
(
!
ret
&&
bOrder
)
qsort
((
*
ppIpAddrTable
)
->
table
,
(
*
ppIpAddrTable
)
->
dwNumEntries
,
qsort
((
*
ppIpAddrTable
)
->
table
,
(
*
ppIpAddrTable
)
->
dwNumEntries
,
sizeof
(
MIB_IPADDRROW
),
IpAddrTableSorter
);
sizeof
(
MIB_IPADDRROW
),
IpAddrTable
Numeric
Sorter
);
TRACE
(
"returning %d
\n
"
,
ret
);
TRACE
(
"returning %d
\n
"
,
ret
);
return
ret
;
return
ret
;
}
}
...
@@ -1988,9 +1998,14 @@ DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL
...
@@ -1988,9 +1998,14 @@ DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL
else
{
else
{
*
pdwSize
=
size
;
*
pdwSize
=
size
;
memcpy
(
pIpAddrTable
,
table
,
size
);
memcpy
(
pIpAddrTable
,
table
,
size
);
/* sort by numeric IP value */
if
(
bOrder
)
if
(
bOrder
)
qsort
(
pIpAddrTable
->
table
,
pIpAddrTable
->
dwNumEntries
,
qsort
(
pIpAddrTable
->
table
,
pIpAddrTable
->
dwNumEntries
,
sizeof
(
MIB_IPADDRROW
),
IpAddrTableSorter
);
sizeof
(
MIB_IPADDRROW
),
IpAddrTableNumericSorter
);
/* sort ensuring loopback interfaces are in the end */
else
qsort
(
pIpAddrTable
->
table
,
pIpAddrTable
->
dwNumEntries
,
sizeof
(
MIB_IPADDRROW
),
IpAddrTableLoopbackSorter
);
ret
=
NO_ERROR
;
ret
=
NO_ERROR
;
}
}
HeapFree
(
GetProcessHeap
(),
0
,
table
);
HeapFree
(
GetProcessHeap
(),
0
,
table
);
...
...
dlls/iphlpapi/tests/iphlpapi.c
View file @
95298b44
...
@@ -261,6 +261,9 @@ static void testGetIpAddrTable(void)
...
@@ -261,6 +261,9 @@ static void testGetIpAddrTable(void)
ok
(
buf
->
table
[
i
].
wType
!=
0
,
"Test[%d]: expected wType > 0
\n
"
,
i
);
ok
(
buf
->
table
[
i
].
wType
!=
0
,
"Test[%d]: expected wType > 0
\n
"
,
i
);
trace
(
"Entry[%d]: addr %s, dwIndex %u, wType 0x%x
\n
"
,
i
,
trace
(
"Entry[%d]: addr %s, dwIndex %u, wType 0x%x
\n
"
,
i
,
ntoa
(
buf
->
table
[
i
].
dwAddr
),
buf
->
table
[
i
].
dwIndex
,
buf
->
table
[
i
].
wType
);
ntoa
(
buf
->
table
[
i
].
dwAddr
),
buf
->
table
[
i
].
dwIndex
,
buf
->
table
[
i
].
wType
);
/* loopback must never be the first when more than one interface is found */
if
(
buf
->
table
[
i
].
dwAddr
==
htonl
(
INADDR_LOOPBACK
))
ok
(
buf
->
dwNumEntries
==
1
||
i
,
"Loopback interface in wrong first position
\n
"
);
}
}
}
}
HeapFree
(
GetProcessHeap
(),
0
,
buf
);
HeapFree
(
GetProcessHeap
(),
0
,
buf
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment