Ethernet number

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Ethernet number

Smalltalkiano-3
Hi all,

    anybody knows where to search the Ethernet number on an ordinary Windows
Installation?

    It's that suposed unique number that every ethernet card has, you know?

    The idea is that an app could get it in runtime.

    best regards,

Seb


Reply | Threaded
Open this post in threaded view
|

Re: Ethernet number

Ian Bartholomew-18
Seb,

>     anybody knows where to search the Ethernet number on an ordinary
> Windows Installation?
>
>     It's that suposed unique number that every ethernet card has, you
> know?

A quick snoop around MSDN online comes up with the iphlpapi.dll (I think
that is the "IP Help API") and, more specifically, the GetAdaptersInfo
function.  I tried it by adding an ExternalLibrary subclass,
IphlpapiLibrary, with two methods -

IphlpapiLibrary class>>fileName
^'iphlpapi'

IphlpapiLibrary>>getAdaptersInfo: pIpAdapterInfo pOutBufLen: pOutBufLen
    <stdcall: dword GetAdaptersInfo lpvoid lpvoid>
    ^self invalidCall

Evaluating the following in a workspace gets the information into a
ByteArray.

buf := ByteArray new: 10000.
len := DWORD fromInteger: buf size.
IphlpapiLibrary default getAdaptersInfo: buf pOutBufLen: len.

It now gets a bit messy.  The buffer contains an Array of one or more
IP_ADAPTER_INFO structures.  If you only have one adapter then the dword at
offset 0 will be 0 (otherwise it will be a pointer to the start of the next
IP_ADAPTER_INFO) and you can just get the adaptor MAC Address (the unique id
you want) directly.

addressLength := buf dwordAtOffset: 400.
addressBytes := buf copyFrom: 405 to: 405 + addressLength - 1.

This should end up with addressBytes containing 6 (usually) bytes that
comprise the unique Id.

If you have multiple adapters then you will have to check each of the
structures to locate the adapter you want and then work out the offset.

IP_ADAPTER_INFO is one of those Windows structures that changes it's size
depending on the information it contains so adding a wrapper class to the
Dolphin image is a bit more difficult than normal - which is why I've taken
the easy way out here :-)

This should get you started anyway?.

Regards
    Ian


Reply | Threaded
Open this post in threaded view
|

Re: Ethernet number

Smalltalkiano-3
Thank you Master Ian, now I can sense the Force again.






"Ian Bartholomew" <[hidden email]> escribió en el mensaje
news:qmYl9.1735$Fv2.149667@wards...

> Seb,
>
> >     anybody knows where to search the Ethernet number on an ordinary
> > Windows Installation?
> >
> >     It's that suposed unique number that every ethernet card has, you
> > know?
>
> A quick snoop around MSDN online comes up with the iphlpapi.dll (I think
> that is the "IP Help API") and, more specifically, the GetAdaptersInfo
> function.  I tried it by adding an ExternalLibrary subclass,
> IphlpapiLibrary, with two methods -
>
> IphlpapiLibrary class>>fileName
> ^'iphlpapi'
>
> IphlpapiLibrary>>getAdaptersInfo: pIpAdapterInfo pOutBufLen: pOutBufLen
>     <stdcall: dword GetAdaptersInfo lpvoid lpvoid>
>     ^self invalidCall
>
> Evaluating the following in a workspace gets the information into a
> ByteArray.
>
> buf := ByteArray new: 10000.
> len := DWORD fromInteger: buf size.
> IphlpapiLibrary default getAdaptersInfo: buf pOutBufLen: len.
>
> It now gets a bit messy.  The buffer contains an Array of one or more
> IP_ADAPTER_INFO structures.  If you only have one adapter then the dword
at
> offset 0 will be 0 (otherwise it will be a pointer to the start of the
next
> IP_ADAPTER_INFO) and you can just get the adaptor MAC Address (the unique
id

> you want) directly.
>
> addressLength := buf dwordAtOffset: 400.
> addressBytes := buf copyFrom: 405 to: 405 + addressLength - 1.
>
> This should end up with addressBytes containing 6 (usually) bytes that
> comprise the unique Id.
>
> If you have multiple adapters then you will have to check each of the
> structures to locate the adapter you want and then work out the offset.
>
> IP_ADAPTER_INFO is one of those Windows structures that changes it's size
> depending on the information it contains so adding a wrapper class to the
> Dolphin image is a bit more difficult than normal - which is why I've
taken
> the easy way out here :-)
>
> This should get you started anyway?.
>
> Regards
>     Ian
>
>
>