From: Georg Richter Date: March 20 2008 6:50am Subject: [Fwd: Re: Community contributions - WL #1624] List-Archive: http://lists.mysql.com/contributions/5 Message-Id: <47E2094D.8020708@mysql.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040301090009060408060901" --------------040301090009060408060901 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit -- Georg Richter, Development Manager - Connectors & Client Connectivity MySQL GmbH, Dachauer Str.37, D- 80335 München, www.mysql.com Geschäftsführer: Kaj Arnö - HRB München 162140 --------------040301090009060408060901 Content-Type: message/rfc822; name="Re: Community contributions - WL #1624.eml" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="Re: Community contributions - WL #1624.eml" X-Account-Key: account2 X-Mozilla-Keys: Return-Path: Received: from mailget.mysql.com ([unix socket]) by mailget (Cyrus v2.3.1-Invoca-RPM-2.3.1-2.8.fc5) with LMTPA; Wed, 19 Mar 2008 19:53:50 +0100 X-Sieve: CMU Sieve 2.3 Received: from mail.mysql.com (mail.mysql.com [10.100.1.21]) by mailget.mysql.com (8.13.8/8.13.8) with ESMTP id m2JIrn6N032667 for ; Wed, 19 Mar 2008 19:53:49 +0100 Received: from mailgate-b.mysql.com (mailgate-b.mysql.com [10.128.18.33]) by mail.mysql.com (8.13.3/8.13.3) with ESMTP id m2JIrmqi000708 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 19 Mar 2008 19:53:48 +0100 Received: from lists.mysql.com (lists.mysql.com [10.100.1.37]) by mailgate-b.mysql.com (8.13.8/8.13.8) with SMTP id m2JIrmH3030562 for ; Wed, 19 Mar 2008 19:53:48 +0100 Received: (qmail 26172 invoked by uid 510); 19 Mar 2008 18:53:47 -0000 Mailing-List: contact contributions-help@stripped; run by ezmlm List-ID: Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Archive: http://lists.mysql.com/contributions/3 Delivered-To: mailing list contributions@stripped Received: (qmail 15970 invoked by uid 509); 19 Mar 2008 18:38:46 -0000 From: "Vladislav Vaintroub" To: "'Chris Runyan'" , Cc: References: <47DA86D9.8020405@stripped> <000401c885e2$73c5b8e0$5b512aa0$@biz> <000601c8861f$13da7050$3b8f50f0$@com> <000901c887aa$c271ff20$4755fd60$@biz> <000f01c88882$607e8710$217b9530$@com> <009501c8890f$5e0e2840$1a2a78c0$@biz> <000201c88919$cd098500$671c8f00$@com> <000001c889d7$9e946b40$dbbd41c0$@biz> In-Reply-To: <000001c889d7$9e946b40$dbbd41c0$@biz> Subject: RE: Community contributions - WL #1624 Date: Wed, 19 Mar 2008 19:37:34 +0100 Message-ID: <000201c889f0$4cf10780$e6d31680$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AciF3PwqU2KbbuRiRAi3soBMsOdFiAAAQT/AAAGMQdAAb3SMMAAycbwQACSJYJAABinhgAAwJdAAAAW6OEA= Content-Language: en-us X-Cxn-Txn: 42196490,22398228 Hi Chris, I think this revision is very decent and can be checked in. I had one = minor problem with the patch (#elif's somehow did not work) , this however can stem from the fact = that your patch is against another bitkeeper tree. Below is mine variation that compiles against current mysql-5.1 . The = difference to your patch is in only 2 lines, namely +#elif defined(__WIN__) +#else /* __FreeBSD__ || __linux__ || __WIN__ */ I have yet to find out in which MySQL version this patch will go into = (5.1, more probably into 6.0), hope Georg can provide further info on = this. Thank you, Vlad =3D=3D=3D=3D=3D my_gethwaddr.c 1.7 vs edited =3D=3D=3D=3D=3D --- 1.7/mysys/my_gethwaddr.c 2007-08-09 14:56:52 +02:00 +++ edited/mysys/my_gethwaddr.c 2008-03-19 19:14:02 +01:00 @@ -101,14 +101,117 @@ return res; } =20 -#else /* FreeBSD elif linux */ +#elif defined(__WIN__) + +/* Workaround for BUG#32082 (Definition of VOID in my_global.h = conflicts with windows headers) */=20 +#ifdef VOID=20 +#undef VOID=20 +#define VOID void=20 +#endif + +#include + +/*=20 + The following typedef is for dynamically loading=20 + iphlpapi.dll / GetAdaptersAddresses. Dynamic loading is=20 + used because GetAdaptersAddresses is not available on Windows 2000=20 + 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,=20 + IN OUT PULONG pOutBufLen); + +/* + my_gethwaddr - Windows version =20 + + @brief Retrieve MAC address from network hardware +=20 + @param[out] to MAC address exactly six bytes +=20 + @return Operation status + @retval 0 OK + @retval <>0 FAILED =20 +*/ +my_bool my_gethwaddr(uchar *to) +{ =20 + PIP_ADAPTER_ADDRESSES pAdapterAddresses; + PIP_ADAPTER_ADDRESSES pCurrAddresses; + IP_ADAPTER_ADDRESSES adapterAddresses; + ULONG address_len; + my_bool return_val=3D 1; =20 + =20 + + + static pfnGetAdaptersAddresses fnGetAdaptersAddresses=3D=20 + (pfnGetAdaptersAddresses)-1;=20 + + if(fnGetAdaptersAddresses =3D=3D (pfnGetAdaptersAddresses)-1) + { + /* Get the function from the DLL */ + fnGetAdaptersAddresses=3D (pfnGetAdaptersAddresses) + GetProcAddress(LoadLibrary("iphlpapi.dll"), + "GetAdaptersAddresses"); + } + if (!fnGetAdaptersAddresses) + return 1; /* failed to get = function */ + address_len=3D sizeof (IP_ADAPTER_ADDRESSES); + + /* Get the required size for the address data. */ + if (fnGetAdaptersAddresses(AF_UNSPEC, 0, 0, &adapterAddresses, = &address_len)=20 + =3D=3D ERROR_BUFFER_OVERFLOW) + { + pAdapterAddresses=3D my_malloc(address_len, 0); + if (!pAdapterAddresses) + return 1; /* error, alloc = failed */ + } + else + pAdapterAddresses=3D &adapterAddresses; /* one is enough = don't alloc */ + + /* Get the hardware info. */ + if (fnGetAdaptersAddresses(AF_UNSPEC, 0, 0, pAdapterAddresses, = &address_len)=20 + =3D=3D NO_ERROR) + { + pCurrAddresses=3D pAdapterAddresses; + + while (pCurrAddresses)=20 + { + /* Look for ethernet cards. */ + if (pCurrAddresses->IfType =3D=3D IF_TYPE_ETHERNET_CSMACD) + { + /* check for a good address */ + if (pCurrAddresses->PhysicalAddressLength < 6) + continue; /* bad address */ = =20 + + /* save 6 bytes of the address in the 'to' parameter */ + memcpy(to, pCurrAddresses->PhysicalAddress, 6); + + /* Network card found, we're done. */ + return_val=3D 0; + break; =20 + } + pCurrAddresses=3D pCurrAddresses->Next; + } =20 + } + + /* Clean up memory allocation. */ + if (pAdapterAddresses !=3D &adapterAddresses) + my_free(pAdapterAddresses, 0); + + return return_val; +} + +#else /* __FreeBSD__ || __linux__ || __WIN__ */ + /* just fail */ my_bool my_gethwaddr(uchar *to __attribute__((unused))) { return 1; } + #endif =20 + #else /* MAIN */ int main(int argc __attribute__((unused)),char **argv) { @@ -130,3 +233,4 @@ } #endif =20 + = =20 > -----Original Message----- > From: Chris Runyan [mailto:mysql@stripped] > Sent: Wednesday, March 19, 2008 4:41 PM > To: 'Vladislav Vaintroub' > Subject: RE: Community contributions - WL #1624 >=20 > Hi Vlad, >=20 > I've made the latest changes. Hopefully this is the last revision. ;) >=20 > -Chris >=20 >=20 >=20 > **************************** >=20 > --- my_gethwaddr.c 2008-03-07 06:46:29.000000000 -0700 > +++ /home/chris/my_gethwaddr.c 2008-03-19 09:29:00.000000000 -0600 > @@ -102,11 +102,117 @@ > } >=20 > #else /* FreeBSD elif linux */ > + > +#ifdef __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 > + > +/* > + 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=3D 1; > + > + > + > + static pfnGetAdaptersAddresses fnGetAdaptersAddresses=3D > + (pfnGetAdaptersAddresses)-1; > + > + if(fnGetAdaptersAddresses =3D=3D (pfnGetAdaptersAddresses)-1) > + { > + /* Get the function from the DLL */ > + fnGetAdaptersAddresses=3D (pfnGetAdaptersAddresses) > + > GetProcAddress(LoadLibrary("iphlpapi.dll"), > + "GetAdaptersAddresses"); > + } > + if (!fnGetAdaptersAddresses) > + return 1; /* failed to get > function */ > + address_len=3D sizeof (IP_ADAPTER_ADDRESSES); > + > + /* Get the required size for the address data. */ > + if (fnGetAdaptersAddresses(AF_UNSPEC, 0, 0, &adapterAddresses, > &address_len) > + =3D=3D ERROR_BUFFER_OVERFLOW) > + { > + pAdapterAddresses=3D my_malloc(address_len, 0); > + if (!pAdapterAddresses) > + return 1; /* error, alloc > failed */ > + } > + else > + pAdapterAddresses=3D &adapterAddresses; /* one is enough > don't alloc */ > + > + /* Get the hardware info. */ > + if (fnGetAdaptersAddresses(AF_UNSPEC, 0, 0, pAdapterAddresses, > &address_len) > + =3D=3D NO_ERROR) > + { > + pCurrAddresses=3D pAdapterAddresses; > + > + while (pCurrAddresses) > + { > + /* Look for ethernet cards. */ > + if (pCurrAddresses->IfType =3D=3D 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=3D 0; > + break; > + } > + pCurrAddresses=3D pCurrAddresses->Next; > + } > + } > + > + /* Clean up memory allocation. */ > + if (pAdapterAddresses !=3D &adapterAddresses) > + my_free(pAdapterAddresses, 0); > + > + return return_val; > +} > + > +#elif > + > /* just fail */ > my_bool my_gethwaddr(uchar *to __attribute__((unused))) > { > return 1; > } > + > +#endif > + > #endif >=20 > #else /* MAIN */ > @@ -130,3 +236,4 @@ > } > #endif >=20 > + >=20 >=20 -- MySQL Community Contributions Mailing List For list archives: http://lists.mysql.com/contributions To unsubscribe: http://lists.mysql.com/contributions?unsub=3Dgeorg@stripped --------------040301090009060408060901--