Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
fc8db5e9
Commit
fc8db5e9
authored
Sep 11, 2009
by
Vladislav Vaintroub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Downport
WL#1624 -determine MAC addresses on Windows. Contribution by Chris Runyan
parent
716099e0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
1 deletion
+91
-1
mysys/my_gethwaddr.c
mysys/my_gethwaddr.c
+91
-1
No files found.
mysys/my_gethwaddr.c
View file @
fc8db5e9
...
...
@@ -101,7 +101,97 @@ err:
return
res
;
}
#else
/* FreeBSD elif linux */
#elif defined(__WIN__)
#include <iphlpapi.h>
/*
The following typedef is for dynamically loading
iphlpapi.dll / GetAdaptersAddresses. Dynamic loading is
used because GetAdaptersAddresses is not available on Windows 2000
which MySQL still supports. Static linking would cause an unresolved export.
*/
typedef
DWORD
(
WINAPI
*
pfnGetAdaptersAddresses
)(
IN
ULONG
Family
,
IN
DWORD
Flags
,
IN
PVOID
Reserved
,
OUT
PIP_ADAPTER_ADDRESSES
pAdapterAddresses
,
IN
OUT
PULONG
pOutBufLen
);
/*
my_gethwaddr - Windows version
@brief Retrieve MAC address from network hardware
@param[out] to MAC address exactly six bytes
@return Operation status
@retval 0 OK
@retval <>0 FAILED
*/
my_bool
my_gethwaddr
(
uchar
*
to
)
{
PIP_ADAPTER_ADDRESSES
pAdapterAddresses
;
PIP_ADAPTER_ADDRESSES
pCurrAddresses
;
IP_ADAPTER_ADDRESSES
adapterAddresses
;
ULONG
address_len
;
my_bool
return_val
=
1
;
static
pfnGetAdaptersAddresses
fnGetAdaptersAddresses
=
(
pfnGetAdaptersAddresses
)
-
1
;
if
(
fnGetAdaptersAddresses
==
(
pfnGetAdaptersAddresses
)
-
1
)
{
/* Get the function from the DLL */
fnGetAdaptersAddresses
=
(
pfnGetAdaptersAddresses
)
GetProcAddress
(
LoadLibrary
(
"iphlpapi.dll"
),
"GetAdaptersAddresses"
);
}
if
(
!
fnGetAdaptersAddresses
)
return
1
;
/* failed to get function */
address_len
=
sizeof
(
IP_ADAPTER_ADDRESSES
);
/* Get the required size for the address data. */
if
(
fnGetAdaptersAddresses
(
AF_UNSPEC
,
0
,
0
,
&
adapterAddresses
,
&
address_len
)
==
ERROR_BUFFER_OVERFLOW
)
{
pAdapterAddresses
=
my_malloc
(
address_len
,
0
);
if
(
!
pAdapterAddresses
)
return
1
;
/* error, alloc failed */
}
else
pAdapterAddresses
=
&
adapterAddresses
;
/* one is enough don't alloc */
/* Get the hardware info. */
if
(
fnGetAdaptersAddresses
(
AF_UNSPEC
,
0
,
0
,
pAdapterAddresses
,
&
address_len
)
==
NO_ERROR
)
{
pCurrAddresses
=
pAdapterAddresses
;
while
(
pCurrAddresses
)
{
/* Look for ethernet cards. */
if
(
pCurrAddresses
->
IfType
==
IF_TYPE_ETHERNET_CSMACD
)
{
/* check for a good address */
if
(
pCurrAddresses
->
PhysicalAddressLength
<
6
)
continue
;
/* bad address */
/* save 6 bytes of the address in the 'to' parameter */
memcpy
(
to
,
pCurrAddresses
->
PhysicalAddress
,
6
);
/* Network card found, we're done. */
return_val
=
0
;
break
;
}
pCurrAddresses
=
pCurrAddresses
->
Next
;
}
}
/* Clean up memory allocation. */
if
(
pAdapterAddresses
!=
&
adapterAddresses
)
my_free
(
pAdapterAddresses
,
0
);
return
return_val
;
}
#else
/* __FreeBSD__ || __linux__ || __WIN__ */
/* just fail */
my_bool
my_gethwaddr
(
uchar
*
to
__attribute__
((
unused
)))
{
...
...
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