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
9e919b8a
Commit
9e919b8a
authored
Jun 25, 2008
by
Juan Lang
Committed by
Alexandre Julliard
Jun 25, 2008
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inetmib1: Sort the tables keyed by IP address, and use bsearch to find entries in them.
parent
67794694
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
28 deletions
+67
-28
main.c
dlls/inetmib1/main.c
+67
-28
No files found.
dlls/inetmib1/main.c
View file @
9e919b8a
...
...
@@ -19,6 +19,7 @@
#include "config.h"
#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <limits.h>
#include "windef.h"
#include "winbase.h"
...
...
@@ -317,26 +318,35 @@ struct GenericTable
BYTE
entries
[
1
];
};
/* Finds the index in table whose IP address (at offset addressOffset within the
* entry) matches that given the OID, which is assumed to have at least 4 IDs.
*/
static
UINT
findOIDIPAddressInTable
(
AsnObjectIdentifier
*
oid
,
struct
GenericTable
*
table
,
size_t
tableEntrySize
,
size_t
addressOffset
)
static
DWORD
oidToIpAddr
(
AsnObjectIdentifier
*
oid
)
{
DWORD
addr
;
UINT
i
,
index
=
0
;
assert
(
oid
&&
oid
->
idLength
>=
4
);
/* Map the IDs to an IP address in little-endian order */
addr
=
(
BYTE
)
oid
->
ids
[
3
]
<<
24
|
(
BYTE
)
oid
->
ids
[
2
]
<<
16
|
return
(
BYTE
)
oid
->
ids
[
3
]
<<
24
|
(
BYTE
)
oid
->
ids
[
2
]
<<
16
|
(
BYTE
)
oid
->
ids
[
1
]
<<
8
|
(
BYTE
)
oid
->
ids
[
0
];
/* Find the item whose address matches */
for
(
i
=
0
;
!
index
&&
i
<
table
->
numEntries
;
i
++
)
{
DWORD
tableAddr
=
*
(
DWORD
*
)(
table
->
entries
+
i
*
tableEntrySize
+
addressOffset
);
}
typedef
void
(
*
oidToKeyFunc
)(
AsnObjectIdentifier
*
oid
,
void
*
dst
);
typedef
int
(
*
compareFunc
)(
const
void
*
key
,
const
void
*
value
);
static
UINT
findValueInTable
(
AsnObjectIdentifier
*
oid
,
struct
GenericTable
*
table
,
size_t
tableEntrySize
,
oidToKeyFunc
makeKey
,
compareFunc
compare
)
{
UINT
index
=
0
;
void
*
key
=
HeapAlloc
(
GetProcessHeap
(),
0
,
tableEntrySize
);
if
(
addr
==
tableAddr
)
index
=
i
+
1
;
if
(
key
)
{
void
*
value
;
makeKey
(
oid
,
key
);
value
=
bsearch
(
key
,
table
->
entries
,
table
->
numEntries
,
tableEntrySize
,
compare
);
if
(
value
)
index
=
((
BYTE
*
)
value
-
(
BYTE
*
)
table
->
entries
)
/
tableEntrySize
+
1
;
HeapFree
(
GetProcessHeap
(),
0
,
key
);
}
return
index
;
}
...
...
@@ -352,7 +362,8 @@ static UINT findOIDIPAddressInTable(AsnObjectIdentifier *oid,
*/
static
AsnInteger32
getItemAndIpAddressInstanceFromOid
(
AsnObjectIdentifier
*
oid
,
AsnObjectIdentifier
*
base
,
BYTE
bPduType
,
struct
GenericTable
*
table
,
size_t
tableEntrySize
,
size_t
addressOffset
,
UINT
*
item
,
UINT
*
instance
)
size_t
tableEntrySize
,
oidToKeyFunc
makeKey
,
compareFunc
compare
,
UINT
*
item
,
UINT
*
instance
)
{
AsnInteger32
ret
=
SNMP_ERRORSTATUS_NOERROR
;
...
...
@@ -398,8 +409,8 @@ static AsnInteger32 getItemAndIpAddressInstanceFromOid(AsnObjectIdentifier *oid,
AsnObjectIdentifier
ipOid
=
{
4
,
oid
->
ids
+
base
->
idLength
+
1
};
*
instance
=
find
OIDIPAddressInTable
(
&
ipOid
,
tabl
e
,
tableEntrySize
,
addressOffset
)
+
1
;
*
instance
=
find
ValueInTable
(
&
ipOid
,
table
,
tableEntrySiz
e
,
makeKey
,
compare
)
+
1
;
if
(
*
instance
>
table
->
numEntries
)
ret
=
SNMP_ERRORSTATUS_NOSUCHNAME
;
}
...
...
@@ -419,8 +430,8 @@ static AsnInteger32 getItemAndIpAddressInstanceFromOid(AsnObjectIdentifier *oid,
AsnObjectIdentifier
ipOid
=
{
4
,
oid
->
ids
+
base
->
idLength
+
1
};
*
instance
=
find
OIDIPAddressInTable
(
&
ipOid
,
tabl
e
,
tableEntrySize
,
addressOffset
);
*
instance
=
find
ValueInTable
(
&
ipOid
,
table
,
tableEntrySiz
e
,
makeKey
,
compare
);
if
(
!*
instance
)
ret
=
SNMP_ERRORSTATUS_NOSUCHNAME
;
}
...
...
@@ -632,16 +643,30 @@ static struct structToAsnValue mib2IpAddrMap[] = {
static
void
mib2IpAddrInit
(
void
)
{
DWORD
size
=
0
,
ret
=
GetIpAddrTable
(
NULL
,
&
size
,
FALS
E
);
DWORD
size
=
0
,
ret
=
GetIpAddrTable
(
NULL
,
&
size
,
TRU
E
);
if
(
ret
==
ERROR_INSUFFICIENT_BUFFER
)
{
ipAddrTable
=
HeapAlloc
(
GetProcessHeap
(),
0
,
size
);
if
(
ipAddrTable
)
GetIpAddrTable
(
ipAddrTable
,
&
size
,
FALS
E
);
GetIpAddrTable
(
ipAddrTable
,
&
size
,
TRU
E
);
}
}
static
void
oidToIpAddrRow
(
AsnObjectIdentifier
*
oid
,
void
*
dst
)
{
MIB_IPADDRROW
*
row
=
dst
;
row
->
dwAddr
=
oidToIpAddr
(
oid
);
}
static
int
compareIpAddrRow
(
const
void
*
a
,
const
void
*
b
)
{
const
MIB_IPADDRROW
*
key
=
a
,
*
value
=
b
;
return
key
->
dwAddr
-
value
->
dwAddr
;
}
static
BOOL
mib2IpAddrQuery
(
BYTE
bPduType
,
SnmpVarBind
*
pVarBind
,
AsnInteger32
*
pErrorStatus
)
{
...
...
@@ -657,7 +682,7 @@ static BOOL mib2IpAddrQuery(BYTE bPduType, SnmpVarBind *pVarBind,
case
SNMP_PDU_GETNEXT
:
*
pErrorStatus
=
getItemAndIpAddressInstanceFromOid
(
&
pVarBind
->
name
,
&
myOid
,
bPduType
,
(
struct
GenericTable
*
)
ipAddrTable
,
sizeof
(
MIB_IPADDRROW
),
FIELD_OFFSET
(
MIB_IPADDRROW
,
dwAddr
)
,
&
item
,
sizeof
(
MIB_IPADDRROW
),
oidToIpAddrRow
,
compareIpAddrRow
,
&
item
,
&
tableIndex
);
if
(
!*
pErrorStatus
)
{
...
...
@@ -701,16 +726,30 @@ static struct structToAsnValue mib2IpRouteMap[] = {
static
void
mib2IpRouteInit
(
void
)
{
DWORD
size
=
0
,
ret
=
GetIpForwardTable
(
NULL
,
&
size
,
FALS
E
);
DWORD
size
=
0
,
ret
=
GetIpForwardTable
(
NULL
,
&
size
,
TRU
E
);
if
(
ret
==
ERROR_INSUFFICIENT_BUFFER
)
{
ipRouteTable
=
HeapAlloc
(
GetProcessHeap
(),
0
,
size
);
if
(
ipRouteTable
)
GetIpForwardTable
(
ipRouteTable
,
&
size
,
FALS
E
);
GetIpForwardTable
(
ipRouteTable
,
&
size
,
TRU
E
);
}
}
static
void
oidToIpForwardRow
(
AsnObjectIdentifier
*
oid
,
void
*
dst
)
{
MIB_IPFORWARDROW
*
row
=
dst
;
row
->
dwForwardDest
=
oidToIpAddr
(
oid
);
}
static
int
compareIpForwardRow
(
const
void
*
a
,
const
void
*
b
)
{
const
MIB_IPFORWARDROW
*
key
=
a
,
*
value
=
b
;
return
key
->
dwForwardDest
-
value
->
dwForwardDest
;
}
static
BOOL
mib2IpRouteQuery
(
BYTE
bPduType
,
SnmpVarBind
*
pVarBind
,
AsnInteger32
*
pErrorStatus
)
{
...
...
@@ -726,8 +765,8 @@ static BOOL mib2IpRouteQuery(BYTE bPduType, SnmpVarBind *pVarBind,
case
SNMP_PDU_GETNEXT
:
*
pErrorStatus
=
getItemAndIpAddressInstanceFromOid
(
&
pVarBind
->
name
,
&
myOid
,
bPduType
,
(
struct
GenericTable
*
)
ipRouteTable
,
sizeof
(
MIB_IPFORWARDROW
),
FIELD_OFFSET
(
MIB_IPFORWARDROW
,
dwForwardDest
),
&
item
,
&
tableIndex
);
sizeof
(
MIB_IPFORWARDROW
),
oidToIpForwardRow
,
compareIpForwardRow
,
&
item
,
&
tableIndex
);
if
(
!*
pErrorStatus
)
{
assert
(
tableIndex
);
...
...
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