Hi All,
This is my first attempt to contribute.
(patch details included below)
SUMMARY:
This patch adds the code for the Windows exe to lookup the network MAC for use by the UUID() function. It uses the same API as the windows command ipconfig.exe. (IPHLPAPI) It searches for network cards in the same order as ipconfig, which is handy for testing/verification on systems with multiple network cards.
It looks like there is not an automated test for the UUID function, as least not yet :).
To test the function manually on windows:
On a console window on the server under test run:
> ipconfig /all
Note the "Physical Address" of the first Ethernet adapter.
>From MySQL client run:
> SELECT UUID();
Compare the last 6 hex bytes of the uuid to the results from ipconfig above.
If they are the same the function passes.
Testing Caveat: Will fail under Win95,98 and WinNT 4 < sp4 the MAC will not be read, UUID generates random # instead.
This was fun...your comments, questions and input are appreciated.
Regards,
-Chris
-------------------------------------------------
--- /home/chris/my_gethwaddr.c 2008-03-10 18:55:00.000000000 -0600
+++ my_gethwaddr.c 2008-03-07 06:46:29.000000000 -0700
@@ -102,115 +102,11 @@
}
#else /* FreeBSD elif linux */
-
-#ifdef __WIN__
-
-/*
- There are header conflicts with ras.h and mprapi.h. The following
- definitions keep those from being included and defines the one constant that
- is still required.
-*/
-#define _RAS_H_
-#define __ROUTING_MPRADMIN_H__
-#define MAX_INTERFACE_NAME_LEN 256
-
-#include
-
-/*
- The following typedef is needed since we are dynamically loading
- iphlpapi.dll. Dynamic linking is used because static linking would cause
- problems with older versions of windows (WIN95, WIN98 and WINNT4 < SP4).
-*/
-
-typedef DWORD (WINAPI *pfnGetIfTable)(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder);
-
-/*
- 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
-
- @todo
- Resolve the header conflicts (affects more than just this file) -*/ -my_bool my_gethwaddr(uchar *to)
-{
- HINSTANCE hIphlpapi;
- pfnGetIfTable fnGetIfTable;
- PMIB_IFTABLE pIfTable;
- MIB_IFTABLE ifTable;
- PMIB_IFROW pIfRow;
- DWORD dwSize;
- DWORD dwRetVal;
- my_bool rval;
- int i;
-
- rval= 1;
-
- hIphlpapi= LoadLibrary("iphlpapi.dll");
-/* Iphlpapi is not available on WIN31, WIN95, or WINNT4 < sp4. */
- if (!hIphlpapi)
- goto error1;
-
- fnGetIfTable= (pfnGetIfTable) GetProcAddress(hIphlpapi,"GetIfTable");
- if (!fnGetIfTable)
- goto error1;
-
-/* Ask GetIfTable if one is enough. */
- dwSize= sizeof (MIB_IFTABLE);
- if (fnGetIfTable(&ifTable,&dwSize, FALSE) == ERROR_INSUFFICIENT_BUFFER)
- {
- pIfTable= (PMIB_IFTABLE) my_malloc(dwSize,0);
- if (!pIfTable)
- goto error2;
- }
- else
-/* One is enough we don't need to alloc. */
- pIfTable= &ifTable;
-
-/* Get the hardware info. */
- if ((dwRetVal= fnGetIfTable(pIfTable,&dwSize,FALSE)) == NO_ERROR)
- {
- for (i= 0; i < (int) pIfTable->dwNumEntries; i++)
- {
- pIfRow= (MIB_IFROW *) & pIfTable->table[i];
- if (pIfRow->dwType == IF_TYPE_ETHERNET_CSMACD)
- {
-/* Stop on the first network card detected. */
- memcpy(to,pIfRow->bPhysAddr,6);
- rval= 0; /* success */
- break;
- }
- }
- }
-
-/* Clean up memory allocation. */
- if (pIfTable != &ifTable)
- my_free(pIfTable,0);
-
-error2:
-/* Perform library clean up. */
- FreeLibrary(hIphlpapi);
-
-error1:
- return rval;
-}
-
-#elif
-
/* just fail */
my_bool my_gethwaddr(uchar *to __attribute__((unused))) {
return 1;
}
-
-#endif
-
#endif
#else /* MAIN */
Wednesday, March 12, 2008
I submitted my first patch to MySQL
Here it is:
Subscribe to:
Post Comments (Atom)
chris' shared items
Twitter Updates
Official blog of Chris Lee Runyan
Fastest C++ in the west.
No comments:
Post a Comment