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
6eba688f
Commit
6eba688f
authored
Dec 02, 2014
by
Joachim Priesner
Committed by
Alexandre Julliard
Dec 02, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ws2_32: Use qsort() to order routes by metric in WS_get_local_ips.
parent
2a8043aa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
21 deletions
+17
-21
socket.c
dlls/ws2_32/socket.c
+17
-21
No files found.
dlls/ws2_32/socket.c
View file @
6eba688f
...
@@ -5167,6 +5167,17 @@ struct WS_hostent* WINAPI WS_gethostbyaddr(const char *addr, int len, int type)
...
@@ -5167,6 +5167,17 @@ struct WS_hostent* WINAPI WS_gethostbyaddr(const char *addr, int len, int type)
}
}
/***********************************************************************
/***********************************************************************
* WS_compare_routes_by_metric_asc (INTERNAL)
*
* Comparison function for qsort(), for sorting two routes (struct route)
* by metric in ascending order.
*/
static
int
WS_compare_routes_by_metric_asc
(
const
void
*
left
,
const
void
*
right
)
{
return
((
const
struct
route
*
)
left
)
->
metric
-
((
const
struct
route
*
)
right
)
->
metric
;
}
/***********************************************************************
* WS_get_local_ips (INTERNAL)
* WS_get_local_ips (INTERNAL)
*
*
* Returns the list of local IP addresses by going through the network
* Returns the list of local IP addresses by going through the network
...
@@ -5180,7 +5191,7 @@ struct WS_hostent* WINAPI WS_gethostbyaddr(const char *addr, int len, int type)
...
@@ -5180,7 +5191,7 @@ struct WS_hostent* WINAPI WS_gethostbyaddr(const char *addr, int len, int type)
*/
*/
static
struct
WS_hostent
*
WS_get_local_ips
(
char
*
hostname
)
static
struct
WS_hostent
*
WS_get_local_ips
(
char
*
hostname
)
{
{
int
last_metric
,
numroutes
=
0
,
i
,
j
;
int
numroutes
=
0
,
i
,
j
;
DWORD
n
;
DWORD
n
;
PIP_ADAPTER_INFO
adapters
=
NULL
,
k
;
PIP_ADAPTER_INFO
adapters
=
NULL
,
k
;
struct
WS_hostent
*
hostlist
=
NULL
;
struct
WS_hostent
*
hostlist
=
NULL
;
...
@@ -5260,30 +5271,15 @@ static struct WS_hostent* WS_get_local_ips( char *hostname )
...
@@ -5260,30 +5271,15 @@ static struct WS_hostent* WS_get_local_ips( char *hostname )
hostlist
->
h_aliases
[
0
]
=
NULL
;
/* NULL-terminate the alias list */
hostlist
->
h_aliases
[
0
]
=
NULL
;
/* NULL-terminate the alias list */
hostlist
->
h_addrtype
=
AF_INET
;
hostlist
->
h_addrtype
=
AF_INET
;
hostlist
->
h_length
=
sizeof
(
struct
in_addr
);
/* = 4 */
hostlist
->
h_length
=
sizeof
(
struct
in_addr
);
/* = 4 */
/* Reorder the entries
when placing them in the host list,
Windows expects
/* Reorder the entries
before placing them in the host list.
Windows expects
* the IP list in order from highest priority to lowest (the critical thing
* the IP list in order from highest priority to lowest (the critical thing
* is that most applications expect the first IP to be the default route).
* is that most applications expect the first IP to be the default route).
*/
*/
last_metric
=
-
1
;
if
(
numroutes
>
1
)
for
(
i
=
0
;
i
<
numroutes
;
i
++
)
qsort
(
route_addrs
,
numroutes
,
sizeof
(
struct
route
),
WS_compare_routes_by_metric_asc
);
{
struct
in_addr
addr
;
int
metric
=
0xFFFF
;
memcpy
(
&
addr
,
magic_loopback_addr
,
4
);
for
(
i
=
0
;
i
<
numroutes
;
i
++
)
for
(
j
=
0
;
j
<
numroutes
;
j
++
)
(
*
(
struct
in_addr
*
)
hostlist
->
h_addr_list
[
i
])
=
route_addrs
[
i
].
addr
;
{
int
this_metric
=
route_addrs
[
j
].
metric
;
if
(
this_metric
>
last_metric
&&
this_metric
<
metric
)
{
addr
=
route_addrs
[
j
].
addr
;
metric
=
this_metric
;
}
}
last_metric
=
metric
;
(
*
(
struct
in_addr
*
)
hostlist
->
h_addr_list
[
i
])
=
addr
;
}
/* Cleanup all allocated memory except the address list,
/* Cleanup all allocated memory except the address list,
* the address list is used by the calling app.
* the address list is used by the calling app.
...
...
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