Below is the list of changes that have just been committed into a local
6.0 repository of vvaintroub. When vvaintroub does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2008-03-27 13:47:16+01:00, vvaintroub@wva. +1 -0
WL#1624 : Determine MAC address on Windows.
Use GetAdaptersAddresses from the IP helper library (iphlpapi) to get
the MAC address.
Thanks to Chris Runyan, who contributed this patch.
mysys/my_gethwaddr.c@stripped, 2008-03-27 13:47:14+01:00, vvaintroub@wva. +97 -1
WL#1624 : Determine MAC address on Windows.
Use GetAdaptersAddresses from the IP helper library (iphlpapi) to get
the MAC address.
This function is available starting with Windows XP, but this should
not be problem, because
a) We're loading it dynamically with LoadLibrary/GetProcAddress .If it
is not available, my_uuid will use a fallback and generate UUID based
on current time and rand()
b) Windows 2000 and earlier will become unsupported in 6.0
Thanks to Chris Runyan, who contributed this patch.
diff -Nrup a/mysys/my_gethwaddr.c b/mysys/my_gethwaddr.c
--- a/mysys/my_gethwaddr.c 2007-08-09 14:56:52 +02:00
+++ b/mysys/my_gethwaddr.c 2008-03-27 13:47:14 +01:00
@@ -101,7 +101,103 @@ err:
return res;
}
-#else /* FreeBSD elif linux */
+#elif defined(__WIN__)
+/* Workaround for BUG#32082 (Definition of VOID in my_global.h conflicts with windows headers) */
+#ifdef VOID
+#undef VOID
+#define VOID void
+#endif
+
+#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)))
{
| Thread |
|---|
| • bk commit into 6.0 tree (vvaintroub:1.2607) WL#1624 | vvaintroub | 27 Mar |