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
8876c3ee
Commit
8876c3ee
authored
Sep 19, 2013
by
Huw Davies
Committed by
Alexandre Julliard
Sep 19, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
iphlpapi: Combine the various interface enumeration functions into one function.
parent
8e74c895
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
109 deletions
+45
-109
ifenum.c
dlls/iphlpapi/ifenum.c
+29
-90
ifenum.h
dlls/iphlpapi/ifenum.h
+4
-9
iphlpapi_main.c
dlls/iphlpapi/iphlpapi_main.c
+10
-8
ipstats.c
dlls/iphlpapi/ipstats.c
+2
-2
No files found.
dlls/iphlpapi/ifenum.c
View file @
8876c3ee
...
...
@@ -161,103 +161,42 @@ BOOL isIfIndexLoopback(ULONG idx)
return
ret
;
}
DWORD
getNumNonLoopbackInterfaces
(
void
)
{
DWORD
numInterfaces
;
int
fd
=
socket
(
PF_INET
,
SOCK_DGRAM
,
0
);
if
(
fd
!=
-
1
)
{
struct
if_nameindex
*
indexes
=
if_nameindex
();
if
(
indexes
)
{
struct
if_nameindex
*
p
;
for
(
p
=
indexes
,
numInterfaces
=
0
;
p
&&
p
->
if_name
;
p
++
)
if
(
!
isLoopbackInterface
(
fd
,
p
->
if_name
))
numInterfaces
++
;
if_freenameindex
(
indexes
);
}
else
numInterfaces
=
0
;
close
(
fd
);
}
else
numInterfaces
=
0
;
return
numInterfaces
;
}
DWORD
get
NumInterfaces
(
void
)
DWORD
get
_interface_indices
(
BOOL
skip_loopback
,
InterfaceIndexTable
**
table
)
{
DWORD
numInterfaces
;
struct
if_nameindex
*
indexes
=
if_nameindex
();
DWORD
count
=
0
,
i
;
struct
if_nameindex
*
p
,
*
indices
=
if_nameindex
();
InterfaceIndexTable
*
ret
;
if
(
indexes
)
{
struct
if_nameindex
*
p
;
if
(
table
)
*
table
=
NULL
;
if
(
!
indices
)
return
0
;
for
(
p
=
indexes
,
numInterfaces
=
0
;
p
&&
p
->
if_name
;
p
++
)
numInterfaces
++
;
if_freenameindex
(
indexes
);
}
else
numInterfaces
=
0
;
return
numInterfaces
;
}
InterfaceIndexTable
*
getInterfaceIndexTable
(
void
)
{
DWORD
numInterfaces
;
InterfaceIndexTable
*
ret
;
struct
if_nameindex
*
indexes
=
if_nameindex
();
if
(
indexes
)
{
struct
if_nameindex
*
p
;
for
(
p
=
indexes
,
numInterfaces
=
0
;
p
&&
p
->
if_name
;
p
++
)
numInterfaces
++
;
ret
=
HeapAlloc
(
GetProcessHeap
(),
0
,
FIELD_OFFSET
(
InterfaceIndexTable
,
indexes
[
numInterfaces
]));
if
(
ret
)
{
ret
->
numIndexes
=
0
;
for
(
p
=
indexes
;
p
&&
p
->
if_name
;
p
++
)
ret
->
indexes
[
ret
->
numIndexes
++
]
=
p
->
if_index
;
for
(
p
=
indices
;
p
->
if_name
;
p
++
)
{
if
(
skip_loopback
&&
isIfIndexLoopback
(
p
->
if_index
))
continue
;
count
++
;
}
if_freenameindex
(
indexes
);
}
else
ret
=
NULL
;
return
ret
;
}
InterfaceIndexTable
*
getNonLoopbackInterfaceIndexTable
(
void
)
{
DWORD
numInterfaces
;
InterfaceIndexTable
*
ret
;
int
fd
=
socket
(
PF_INET
,
SOCK_DGRAM
,
0
);
if
(
fd
!=
-
1
)
{
struct
if_nameindex
*
indexes
=
if_nameindex
();
if
(
indexes
)
{
struct
if_nameindex
*
p
;
for
(
p
=
indexes
,
numInterfaces
=
0
;
p
&&
p
->
if_name
;
p
++
)
if
(
!
isLoopbackInterface
(
fd
,
p
->
if_name
))
numInterfaces
++
;
ret
=
HeapAlloc
(
GetProcessHeap
(),
0
,
FIELD_OFFSET
(
InterfaceIndexTable
,
indexes
[
numInterfaces
]));
if
(
ret
)
{
ret
->
numIndexes
=
0
;
for
(
p
=
indexes
;
p
&&
p
->
if_name
;
p
++
)
if
(
!
isLoopbackInterface
(
fd
,
p
->
if_name
))
ret
->
indexes
[
ret
->
numIndexes
++
]
=
p
->
if_index
;
}
if_freenameindex
(
indexes
);
if
(
table
)
{
ret
=
HeapAlloc
(
GetProcessHeap
(),
0
,
FIELD_OFFSET
(
InterfaceIndexTable
,
indexes
[
count
])
);
if
(
!
ret
)
{
count
=
0
;
goto
end
;
}
for
(
p
=
indices
,
i
=
0
;
p
->
if_name
&&
i
<
count
;
p
++
)
{
if
(
skip_loopback
&&
isIfIndexLoopback
(
p
->
if_index
))
continue
;
ret
->
indexes
[
i
++
]
=
p
->
if_index
;
}
ret
->
numIndexes
=
count
=
i
;
*
table
=
ret
;
}
else
ret
=
NULL
;
close
(
fd
);
}
else
ret
=
NULL
;
return
ret
;
end:
if_freenameindex
(
indices
);
return
count
;
}
static
DWORD
getInterfaceBCastAddrByName
(
const
char
*
name
)
...
...
dlls/iphlpapi/ifenum.h
View file @
8876c3ee
...
...
@@ -44,23 +44,18 @@
#define MAX_INTERFACE_PHYSADDR 8
#define MAX_INTERFACE_DESCRIPTION 256
DWORD
getNumInterfaces
(
void
)
DECLSPEC_HIDDEN
;
DWORD
getNumNonLoopbackInterfaces
(
void
)
DECLSPEC_HIDDEN
;
BOOL
isIfIndexLoopback
(
ULONG
idx
)
DECLSPEC_HIDDEN
;
/* A table of interface indexes, see get
*InterfaceTable
(). */
/* A table of interface indexes, see get
_interface_indices
(). */
typedef
struct
_InterfaceIndexTable
{
DWORD
numIndexes
;
IF_INDEX
indexes
[
1
];
}
InterfaceIndexTable
;
/* Returns
a table with all known interface indexes, or NULL if one could not
*
be allocated. HeapFree() the returned table
.
/* Returns
the count of all interface indexes and optionally a ptr to an interface table.
*
HeapFree() the returned table. Will optionally ignore loopback devices
.
*/
InterfaceIndexTable
*
getInterfaceIndexTable
(
void
)
DECLSPEC_HIDDEN
;
/* Like getInterfaceIndexTable, but filters out loopback interfaces. */
InterfaceIndexTable
*
getNonLoopbackInterfaceIndexTable
(
void
)
DECLSPEC_HIDDEN
;
DWORD
get_interface_indices
(
BOOL
skip_loopback
,
InterfaceIndexTable
**
table
)
DECLSPEC_HIDDEN
;
/* ByName/ByIndex versions of various getter functions. */
...
...
dlls/iphlpapi/iphlpapi_main.c
View file @
8876c3ee
...
...
@@ -463,7 +463,7 @@ DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
if
(
!
pOutBufLen
)
ret
=
ERROR_INVALID_PARAMETER
;
else
{
DWORD
numNonLoopbackInterfaces
=
get
NumNonLoopbackInterfaces
(
);
DWORD
numNonLoopbackInterfaces
=
get
_interface_indices
(
TRUE
,
NULL
);
if
(
numNonLoopbackInterfaces
>
0
)
{
DWORD
numIPAddresses
=
getNumIPAddresses
();
...
...
@@ -489,7 +489,7 @@ DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
if
(
!
ret
)
ret
=
AllocateAndGetIpForwardTableFromStack
(
&
routeTable
,
FALSE
,
GetProcessHeap
(),
0
);
if
(
!
ret
)
table
=
getNonLoopbackInterfaceIndexTable
(
);
get_interface_indices
(
TRUE
,
&
table
);
if
(
table
)
{
size
=
sizeof
(
IP_ADAPTER_INFO
)
*
table
->
numIndexes
;
size
+=
ipAddrTable
->
dwNumEntries
*
sizeof
(
IP_ADDR_STRING
);
...
...
@@ -1129,7 +1129,7 @@ ULONG WINAPI DECLSPEC_HOTPATCH GetAdaptersAddresses(ULONG family, ULONG flags, P
if
(
!
buflen
)
return
ERROR_INVALID_PARAMETER
;
table
=
getInterfaceIndexTable
(
);
get_interface_indices
(
FALSE
,
&
table
);
if
(
!
table
||
!
table
->
numIndexes
)
{
HeapFree
(
GetProcessHeap
(),
0
,
table
);
...
...
@@ -1431,7 +1431,7 @@ DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
if
(
!
pdwSize
)
ret
=
ERROR_INVALID_PARAMETER
;
else
{
DWORD
numInterfaces
=
get
NumInterfaces
(
);
DWORD
numInterfaces
=
get
_interface_indices
(
FALSE
,
NULL
);
ULONG
size
=
sizeof
(
MIB_IFTABLE
);
if
(
numInterfaces
>
1
)
...
...
@@ -1441,7 +1441,8 @@ DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
ret
=
ERROR_INSUFFICIENT_BUFFER
;
}
else
{
InterfaceIndexTable
*
table
=
getInterfaceIndexTable
();
InterfaceIndexTable
*
table
;
get_interface_indices
(
FALSE
,
&
table
);
if
(
table
)
{
size
=
sizeof
(
MIB_IFTABLE
);
...
...
@@ -1501,7 +1502,7 @@ DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
if
(
!
dwOutBufLen
)
ret
=
ERROR_INVALID_PARAMETER
;
else
{
DWORD
numInterfaces
=
get
NumInterfaces
(
);
DWORD
numInterfaces
=
get
_interface_indices
(
FALSE
,
NULL
);
ULONG
size
=
sizeof
(
IP_INTERFACE_INFO
);
if
(
numInterfaces
>
1
)
...
...
@@ -1511,7 +1512,8 @@ DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
ret
=
ERROR_INSUFFICIENT_BUFFER
;
}
else
{
InterfaceIndexTable
*
table
=
getInterfaceIndexTable
();
InterfaceIndexTable
*
table
;
get_interface_indices
(
FALSE
,
&
table
);
if
(
table
)
{
size
=
sizeof
(
IP_INTERFACE_INFO
);
...
...
@@ -1837,7 +1839,7 @@ DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
if
(
!
pdwNumIf
)
ret
=
ERROR_INVALID_PARAMETER
;
else
{
*
pdwNumIf
=
get
NumInterfaces
(
);
*
pdwNumIf
=
get
_interface_indices
(
FALSE
,
NULL
);
ret
=
NO_ERROR
;
}
TRACE
(
"returning %d
\n
"
,
ret
);
...
...
dlls/iphlpapi/ipstats.c
View file @
8876c3ee
...
...
@@ -763,7 +763,7 @@ DWORD WINAPI GetIpStatisticsEx(PMIB_IPSTATS stats, DWORD family)
if
(
family
!=
WS_AF_INET
&&
family
!=
WS_AF_INET6
)
return
ERROR_INVALID_PARAMETER
;
memset
(
stats
,
0
,
sizeof
(
*
stats
)
);
stats
->
dwNumIf
=
stats
->
dwNumAddr
=
get
NumInterfaces
(
);
stats
->
dwNumIf
=
stats
->
dwNumAddr
=
get
_interface_indices
(
FALSE
,
NULL
);
if
(
!
AllocateAndGetIpForwardTableFromStack
(
&
fwd_table
,
FALSE
,
GetProcessHeap
(),
0
))
{
stats
->
dwNumRoutes
=
fwd_table
->
dwNumEntries
;
...
...
@@ -1174,7 +1174,7 @@ DWORD WINAPI GetUdpStatisticsEx(PMIB_UDPSTATS stats, DWORD family)
if
(
family
!=
WS_AF_INET
&&
family
!=
WS_AF_INET6
)
return
ERROR_INVALID_PARAMETER
;
memset
(
stats
,
0
,
sizeof
(
*
stats
)
);
stats
->
dwNumAddrs
=
get
NumInterfaces
(
);
stats
->
dwNumAddrs
=
get
_interface_indices
(
FALSE
,
NULL
);
if
(
family
==
WS_AF_INET6
)
{
...
...
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