List:Contributions« Previous MessageNext Message »
From:Chris Runyan Date:March 19 2008 8:11pm
Subject:RE: Community contributions - WL #1624
View as plain text  
Thanks Vlad,

I just noticed the diff put: #ifdef VOID #undef VOID #define VOID
all on the same line.  This may be messing up the #elif.

Anyway, this was a very enlightening experience, and quite fun.  Frankly
I am considering applying for a position at MySQL and this seems to 
be a great way to get to know the company. 

What do you recommend I work on next?

Regards,

-Chris

> -----Original Message-----
> From: Vladislav Vaintroub [mailto:vaintroub@stripped]
> Sent: Wednesday, March 19, 2008 12:38 PM
> To: 'Chris Runyan'; contributions@stripped
> Cc: georg@stripped
> Subject: RE: Community contributions - WL #1624
> 
> 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
> 
> ===== my_gethwaddr.c 1.7 vs edited =====
> --- 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;
>  }
> 
> -#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)))
>  {
>    return 1;
>  }
> +
>  #endif
> 
> +
>  #else /* MAIN */
>  int main(int argc __attribute__((unused)),char **argv)
>  {
> @@ -130,3 +233,4 @@
>  }
>  #endif
> 
> +
> 
> 
> > -----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
> >
> > Hi Vlad,
> >
> > I've made the latest changes.  Hopefully this is the last revision.
> ;)
> >
> > -Chris
> >
> >
> >
> > ****************************
> >
> > --- 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 @@
> >  }
> >
> >  #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 <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;
> > +}
> > +
> > +#elif
> > +
> >  /* just fail */
> >  my_bool my_gethwaddr(uchar *to __attribute__((unused)))
> >  {
> >    return 1;
> >  }
> > +
> > +#endif
> > +
> >  #endif
> >
> >  #else /* MAIN */
> > @@ -130,3 +236,4 @@
> >  }
> >  #endif
> >
> > +
> >
> >
> 



Thread
RE: Community contributions - WL #1624Vladislav Vaintroub19 Mar
  • RE: Community contributions - WL #1624Chris Runyan19 Mar
  • Re: Community contributions - WL #1624Georg Richter20 Mar