networking with smalltalk

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

networking with smalltalk

Christian Ponti
hi all,
i need to collect data about network cards like mac address, ip address
in multiple card machines, under linux/mac/windows but didn't find
something usefull. Any idea?
In addition are there references or tutorials about networking in
smalltalk?

thx
christian

Reply | Threaded
Open this post in threaded view
|

RE: networking with smalltalk

Stew MacLean
Hi Christian,

I've been investigating this too. This is what I've come up with so
far...

MacOSXSystemSupport>>getMACAddress

        ^((ExternalProcess defaultClass cshOne: 'ifconfig | grep ether')
readStream contents reverse readStream
                upToSeparator) trimBlanks


UnixSystemSupport>>getMACAddress

        ^((ExternalProcess defaultClass cshOne: 'dmesg | grep eth0')
readStream contents reverse readStream
                upToSeparator) trimBlanks


WindowsNTSystemSupport>>getMACAddress


        ^((ExternalProcess defaultClass cshOne: 'ipconfig /all')
readStream
                skipThroughAll: 'Physical';
                upTo: $:;
                upToSeparator;
                upToSeparator) trimBlanks

I've yet to test the Mac solution, but the Terminal command works ok.

The Windows solution seems to fail intermittently, with pipe error 127.
This could be to do with the different external process interface.

Another alternative is to implement the low level OS calls using DLLCC.
However, my C is not up to that :(

HTH,

Cheers,

Stewart




>-----Original Message-----
>From: Christian Ponti [mailto:[hidden email]]
>Sent: 15 March 2007 5:29 a.m.
>To: [hidden email]
>Subject: networking with smalltalk
>
>hi all,
>i need to collect data about network cards like mac address, ip address
>in multiple card machines, under linux/mac/windows but didn't find
>something usefull. Any idea?
>In addition are there references or tutorials about networking in
>smalltalk?
>
>thx
>christian



Reply | Threaded
Open this post in threaded view
|

Re: networking with smalltalk

Mark Pirogovsky-3
Hello All,

Using ifConfig or ipConfig.exe is not very reliable method IMHO.  There
are cases where the user may not have appropriate privileges to run
those programs or the programs maybe removed for some security
consideration and such.

As it stands, there is no easy way to find MAC of the interface. Here is
another rub: on most of the modern computers the peripheral devices can
be enabled and/or disabled from OS.  It comes even trickier with laptops
if for example you are dealing with the PC Card type or USB  network
interfaces. As you insert one of those devices the list of the MACs
reflects this. And the same MAC may show up on few different PCs. And it
is not easy to tell if the device is built in or USB attached. another
bit of a good news: some network devices such as routers and bridges do
allow user defined MAC.

So with all that said: even though it would be nice to use the MAC as
the unique PC identifier it is not reliable and/or sufficient.

If you are dealing with more controlled environment , let say inside of
homogenous corporate network then you can try to implement the following
C code in the Smalltalk using DLLCC or just compile it into the DLL and
use it as such.

My 2c.

--Mark

P.S. the following is C/C++ code for WIN32, for all of us smalltalkers
to enjoy. I am sure there is something similar for other platforms. It
is producing an executable, and it is relatively easy to make it into
the DLL as well.

#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <windows.h>
#include <winioctl.h>


// GetMACAdapters.cpp : Defines the entry point for the console application.
//
// Author:   Khalid Shaikh [[hidden email]]
// Date:   April 5th, 2002
//
// This program fetches the MAC address of the localhost by fetching the
// information through GetAdapatersInfo.  It does not rely on the NETBIOS
// protocol and the ethernet adapter need not be connect to a network.
//
// Supported in Windows NT/2000/XP
// Supported in Windows 95/98/Me
//
// Supports multiple NIC cards on a PC.

#include <Iphlpapi.h>
#include <Assert.h>
#pragma comment(lib, "iphlpapi.lib")

#define PRINTING_TO_CONSOLE_ALLOWED

// Prints the MAC address stored in a 6 byte array to stdout
static void PrintMACaddress(unsigned char MACData[])
{

#ifdef PRINTING_TO_CONSOLE_ALLOWED

    printf("\nMAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n",
       MACData[0], MACData[1], MACData[2], MACData[3], MACData[4],
MACData[5]);

#endif

    char string [256];
    sprintf (string, "%02X-%02X-%02X-%02X-%02X-%02X", MACData[0],
MACData[1],
             MACData[2], MACData[3], MACData[4], MACData[5]);
    WriteConstantString ("MACaddress", string);
}



// Fetches the MAC address and prints it
DWORD GetMACaddress(void)
{
   DWORD MACaddress = 0;
   IP_ADAPTER_INFO AdapterInfo[16];       // Allocate information
                                          // for up to 16 NICs
   DWORD dwBufLen = sizeof(AdapterInfo);  // Save memory size of buffer

   DWORD dwStatus = GetAdaptersInfo(      // Call GetAdapterInfo
          AdapterInfo,                 // [out] buffer to receive data
          &dwBufLen);                  // [in] size of receive data buffer
   assert(dwStatus == ERROR_SUCCESS);  // Verify return value is
                                       // valid, no buffer overflow

   PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to
                                                // current adapter info
   do {
    if (MACaddress == 0)
       MACaddress = pAdapterInfo->Address [5] + pAdapterInfo->Address
[4] * 256 +
                pAdapterInfo->Address [3] * 256 * 256 +
                pAdapterInfo->Address [2] * 256 * 256 * 256;
     PrintMACaddress(pAdapterInfo->Address); // Print MAC address
     pAdapterInfo = pAdapterInfo->Next;    // Progress through linked list
   }
   while(pAdapterInfo);                    // Terminate if last adapter

   return MACaddress;
}



int main (int argc, char * argv [])
{

    GetMACaddress ();

    return 0;
}


Stewart MacLean wrote:

> Hi Christian,
>
> I've been investigating this too. This is what I've come up with so
> far...
>
> MacOSXSystemSupport>>getMACAddress
>
> ^((ExternalProcess defaultClass cshOne: 'ifconfig | grep ether')
> readStream contents reverse readStream
> upToSeparator) trimBlanks
>
>
> UnixSystemSupport>>getMACAddress
>
> ^((ExternalProcess defaultClass cshOne: 'dmesg | grep eth0')
> readStream contents reverse readStream
> upToSeparator) trimBlanks
>
>
> WindowsNTSystemSupport>>getMACAddress
>
>
> ^((ExternalProcess defaultClass cshOne: 'ipconfig /all')
> readStream
> skipThroughAll: 'Physical';
> upTo: $:;
> upToSeparator;
> upToSeparator) trimBlanks
>
> I've yet to test the Mac solution, but the Terminal command works ok.
>
> The Windows solution seems to fail intermittently, with pipe error 127.
> This could be to do with the different external process interface.
>
> Another alternative is to implement the low level OS calls using DLLCC.
> However, my C is not up to that :(
>
> HTH,
>
> Cheers,
>
> Stewart
>
>
>
>
>
>>-----Original Message-----
>>From: Christian Ponti [mailto:[hidden email]]
>>Sent: 15 March 2007 5:29 a.m.
>>To: [hidden email]
>>Subject: networking with smalltalk
>>
>>hi all,
>>i need to collect data about network cards like mac address, ip address
>>in multiple card machines, under linux/mac/windows but didn't find
>>something usefull. Any idea?
>>In addition are there references or tutorials about networking in
>>smalltalk?
>>
>>thx
>>christian
>
>
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: networking with smalltalk

Christian Ponti
hi,
thanks for the advices.
Right now I'm working to build a distributed system using gentoo ppc to
develop and want something to setup the initial environment on machine
with more then one network card, whithout let the user insert manually
ip addresses and whatever.

At the end the folowing implementation works for my system:

((ExternalProcess defaultClass cshOne: '/sbin/ifconfig |grep -i eth0')
readStream contents reverse readStream
                upTo: $r)  readStream contents reverse.


the point is that it is very unreliable and system dependent. It is
weird because there are spaces everywhere (therefore the preceding
solution with upToSeparator doesn't work) and there is the fancy upTo:
$r ...

Christian


Reply | Threaded
Open this post in threaded view
|

Re: networking with smalltalk

kobetic
If you're only after an interface on the host, you might be interested in what we do in Opentalk.
VW does support API to get the hostname of its host and then we simply attempt to resolve the name via DNS.

        HostName := SocketAccessor getHostname.
        HostAddress := IPSocketAddress hostAddressByName: HostName.

This seems to yield reasonably good results most of the time, although it certainly can fail when networking and DNS is misconfigured. We had our share of problem reports on Mac OS8/9 especially.

HTH,

Martin

Christian Ponti wrote:

> hi,
> thanks for the advices.
> Right now I'm working to build a distributed system using gentoo ppc to
> develop and want something to setup the initial environment on machine
> with more then one network card, whithout let the user insert manually
> ip addresses and whatever.
>
> At the end the folowing implementation works for my system:
>
> ((ExternalProcess defaultClass cshOne: '/sbin/ifconfig |grep -i eth0')
> readStream contents reverse readStream
>                 upTo: $r)  readStream contents reverse.
>
>
> the point is that it is very unreliable and system dependent. It is
> weird because there are spaces everywhere (therefore the preceding
> solution with upToSeparator doesn't work) and there is the fancy upTo:
> $r ...
>
> Christian
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: networking with smalltalk

Mark Pirogovsky-3
They are also blocking calls meaning that if the DNS is slow or not
available you will wait upto 30 sec untill you get controll back.


Martin Kobetic wrote:

> If you're only after an interface on the host, you might be interested
> in what we do in Opentalk.
> VW does support API to get the hostname of its host and then we simply
> attempt to resolve the name via DNS.
>
>     HostName := SocketAccessor getHostname.
>     HostAddress := IPSocketAddress hostAddressByName: HostName.
>
> This seems to yield reasonably good results most of the time, although
> it certainly can fail when networking and DNS is misconfigured. We had
> our share of problem reports on Mac OS8/9 especially.
>
> HTH,
>
> Martin
>
> Christian Ponti wrote:
>
>> hi,
>> thanks for the advices.
>> Right now I'm working to build a distributed system using gentoo ppc to
>> develop and want something to setup the initial environment on machine
>> with more then one network card, whithout let the user insert manually
>> ip addresses and whatever.
>>
>> At the end the folowing implementation works for my system:
>>
>> ((ExternalProcess defaultClass cshOne: '/sbin/ifconfig |grep -i eth0')
>> readStream contents reverse readStream
>>                 upTo: $r)  readStream contents reverse.
>>
>>
>> the point is that it is very unreliable and system dependent. It is
>> weird because there are spaces everywhere (therefore the preceding
>> solution with upToSeparator doesn't work) and there is the fancy upTo:
>> $r ...
>>
>> Christian
>>
>>
>>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: networking with smalltalk

kobetic
Yes, good point. Although in most cases we're resolving the name of the local host which often gets resolved instantly from a local facility like /etc/hosts file and such. So it doesn't necessarily entail a network interaction. But yes, when things are not set up that way, it can take a while especially if it's about to fail.

Mark Pirogovsky wrote:

> They are also blocking calls meaning that if the DNS is slow or not
> available you will wait upto 30 sec untill you get controll back.
>
>
> Martin Kobetic wrote:
>
>> If you're only after an interface on the host, you might be interested
>> in what we do in Opentalk.
>> VW does support API to get the hostname of its host and then we simply
>> attempt to resolve the name via DNS.
>>
>>     HostName := SocketAccessor getHostname.
>>     HostAddress := IPSocketAddress hostAddressByName: HostName.
>>
>> This seems to yield reasonably good results most of the time, although
>> it certainly can fail when networking and DNS is misconfigured. We had
>> our share of problem reports on Mac OS8/9 especially.
>>
>> HTH,
>>
>> Martin
>>
>> Christian Ponti wrote:
>>
>>> hi,
>>> thanks for the advices.
>>> Right now I'm working to build a distributed system using gentoo ppc to
>>> develop and want something to setup the initial environment on machine
>>> with more then one network card, whithout let the user insert manually
>>> ip addresses and whatever.
>>>
>>> At the end the folowing implementation works for my system:
>>>
>>> ((ExternalProcess defaultClass cshOne: '/sbin/ifconfig |grep -i eth0')
>>> readStream contents reverse readStream
>>>                 upTo: $r)  readStream contents reverse.
>>>
>>>
>>> the point is that it is very unreliable and system dependent. It is
>>> weird because there are spaces everywhere (therefore the preceding
>>> solution with upToSeparator doesn't work) and there is the fancy upTo:
>>> $r ...
>>>
>>> Christian
>>>
>>>
>>>
>>
>>
>>
>

Reply | Threaded
Open this post in threaded view
|

RE: networking with smalltalk

Stew MacLean
In reply to this post by Mark Pirogovsky-3
Hi Mark and all,

I've decided to grasp the "bull by the horns" and what follows is my
initial attempt at translating something very similar to your suggested
C code, to DLLCC. After studying the manual, I've gone about as far as I
can go (given my limited C knowledge). I know what needs to be done, but
just don't know how to do it. Any help answering my questions below
greatly appreciated... [The C code I'm translating is below].

I've found a suitable Iphlpapi.h header file, parsed it, and created an
ExternalInterface subclass (after editing out the line numbers).

This is the api so far...

getMacAddresses

        | pAdapterInfo pOutBufLen status answer |

        pAdapterInfo := self _IP_ADAPTER_INFO gcMalloc: 16.

"I'm guessing that structs, not just basic types can be used in arrays,
right?"

        "From the docs... gcMalloc: numCopies Allocates a C object in
the external heap. Enough
        memory is allocated to contain numCopies of the receiver.
        A pointer to the first element is answered."

        "pOutBufLen := how do I get sizeOf(pAdapterInfo).  ???"

        "According to the docs, I already have a pointer so I don't need
to do the equivalent of PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;//
Contains pointer to current adapter info. Correct?"

        status :=
                self
                        GetAdaptersInfo: pAdapterInfo contents "we've
already got a pointer, and need to pass the data, so send contents to
the pointer, correct?"
                        with: pOutBufLen.

        status = 0
                ifFalse: [^nil].

        "Pluck off the first address..."
        answer := OrderedCollection new
                add: (pAdapterInfo memberAt: #Address);
                yourself.

        "While not at the end of the linked list, pluck of remaining
addresses..."
        [(pAdapterInfo := (pAdapterInfo memberAt: #Next)) ~= 0]
whileTrue:
                [answer add: (pAdapterInfo memberAt: #Address)].

        ^answer

========================================================================
==
This is the C code I'm working towards...
       
"
        static void GetMACaddress(void)
{
        IP_ADAPTER_INFO AdapterInfo[16]; //
Allocate information for up to 16 NICs
        DWORD dwBufLen = sizeof(AdapterInfo); // Save the
memory size of buffer

        DWORD dwStatus = GetAdaptersInfo( // Call
GetAdapterInfo
                AdapterInfo,
// [out] buffer to receive data
                &dwBufLen);
// [in] size of receive data buffer
        assert(dwStatus == ERROR_SUCCESS); // Verify return
value is valid, no buffer overflow

        PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;// Contains pointer
to current adapter info
        do {
                PrintMACaddress(pAdapterInfo->Address); // Print MAC
address
                pAdapterInfo = pAdapterInfo->Next;
// Progress through linked list
        }
        while(pAdapterInfo);
// Terminate if last adapter
}
"





>-----Original Message-----
>From: Mark Pirogovsky [mailto:[hidden email]]
>Sent: 16 March 2007 3:25 a.m.
>To: Stewart MacLean
>Cc: 'Christian Ponti'; [hidden email]
>Subject: Re: networking with smalltalk
>
>Hello All,
>
>Using ifConfig or ipConfig.exe is not very reliable method IMHO.  There
>are cases where the user may not have appropriate privileges to run
>those programs or the programs maybe removed for some security
>consideration and such.
>
>As it stands, there is no easy way to find MAC of the interface. Here
is
>another rub: on most of the modern computers the peripheral devices can
>be enabled and/or disabled from OS.  It comes even trickier with
laptops
>if for example you are dealing with the PC Card type or USB  network
>interfaces. As you insert one of those devices the list of the MACs
>reflects this. And the same MAC may show up on few different PCs. And
it
>is not easy to tell if the device is built in or USB attached. another
>bit of a good news: some network devices such as routers and bridges do
>allow user defined MAC.
>
>So with all that said: even though it would be nice to use the MAC as
>the unique PC identifier it is not reliable and/or sufficient.
>
>If you are dealing with more controlled environment , let say inside of
>homogenous corporate network then you can try to implement the
following

>C code in the Smalltalk using DLLCC or just compile it into the DLL and
>use it as such.
>
>My 2c.
>
>--Mark
>
>P.S. the following is C/C++ code for WIN32, for all of us smalltalkers
>to enjoy. I am sure there is something similar for other platforms. It
>is producing an executable, and it is relatively easy to make it into
>the DLL as well.
>
>#include <stdlib.h>
>#include <stdio.h>
>#include <stddef.h>
>#include <string.h>
>#include <windows.h>
>#include <winioctl.h>
>
>
>// GetMACAdapters.cpp : Defines the entry point for the console
>application.
>//
>// Author:   Khalid Shaikh [[hidden email]]
>// Date:   April 5th, 2002
>//
>// This program fetches the MAC address of the localhost by fetching
the
>// information through GetAdapatersInfo.  It does not rely on the
NETBIOS

>// protocol and the ethernet adapter need not be connect to a network.
>//
>// Supported in Windows NT/2000/XP
>// Supported in Windows 95/98/Me
>//
>// Supports multiple NIC cards on a PC.
>
>#include <Iphlpapi.h>
>#include <Assert.h>
>#pragma comment(lib, "iphlpapi.lib")
>
>#define PRINTING_TO_CONSOLE_ALLOWED
>
>// Prints the MAC address stored in a 6 byte array to stdout
>static void PrintMACaddress(unsigned char MACData[])
>{
>
>#ifdef PRINTING_TO_CONSOLE_ALLOWED
>
>    printf("\nMAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n",
>       MACData[0], MACData[1], MACData[2], MACData[3], MACData[4],
>MACData[5]);
>
>#endif
>
>    char string [256];
>    sprintf (string, "%02X-%02X-%02X-%02X-%02X-%02X", MACData[0],
>MACData[1],
>             MACData[2], MACData[3], MACData[4], MACData[5]);
>    WriteConstantString ("MACaddress", string);
>}
>
>
>
>// Fetches the MAC address and prints it
>DWORD GetMACaddress(void)
>{
>   DWORD MACaddress = 0;
>   IP_ADAPTER_INFO AdapterInfo[16];       // Allocate information
>                                          // for up to 16 NICs
>   DWORD dwBufLen = sizeof(AdapterInfo);  // Save memory size of buffer
>
>   DWORD dwStatus = GetAdaptersInfo(      // Call GetAdapterInfo
>          AdapterInfo,                 // [out] buffer to receive data
>          &dwBufLen);                  // [in] size of receive data
buffer

>   assert(dwStatus == ERROR_SUCCESS);  // Verify return value is
>                                       // valid, no buffer overflow
>
>   PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to
>                                                // current adapter info
>   do {
>    if (MACaddress == 0)
>       MACaddress = pAdapterInfo->Address [5] + pAdapterInfo->Address
>[4] * 256 +
>                pAdapterInfo->Address [3] * 256 * 256 +
>                pAdapterInfo->Address [2] * 256 * 256 * 256;
>     PrintMACaddress(pAdapterInfo->Address); // Print MAC address
>     pAdapterInfo = pAdapterInfo->Next;    // Progress through linked
list

>   }
>   while(pAdapterInfo);                    // Terminate if last adapter
>
>   return MACaddress;
>}
>
>
>
>int main (int argc, char * argv [])
>{
>
>    GetMACaddress ();
>
>    return 0;
>}
>
>
>Stewart MacLean wrote:
>> Hi Christian,
>>
>> I've been investigating this too. This is what I've come up with so
>> far...
>>
>> MacOSXSystemSupport>>getMACAddress
>>
>> ^((ExternalProcess defaultClass cshOne: 'ifconfig | grep ether')
>> readStream contents reverse readStream
>> upToSeparator) trimBlanks
>>
>>
>> UnixSystemSupport>>getMACAddress
>>
>> ^((ExternalProcess defaultClass cshOne: 'dmesg | grep eth0')
>> readStream contents reverse readStream
>> upToSeparator) trimBlanks
>>
>>
>> WindowsNTSystemSupport>>getMACAddress
>>
>>
>> ^((ExternalProcess defaultClass cshOne: 'ipconfig /all')
>> readStream
>> skipThroughAll: 'Physical';
>> upTo: $:;
>> upToSeparator;
>> upToSeparator) trimBlanks
>>
>> I've yet to test the Mac solution, but the Terminal command works ok.
>>
>> The Windows solution seems to fail intermittently, with pipe error
127.
>> This could be to do with the different external process interface.
>>
>> Another alternative is to implement the low level OS calls using
DLLCC.

>> However, my C is not up to that :(
>>
>> HTH,
>>
>> Cheers,
>>
>> Stewart
>>
>>
>>
>>
>>
>>>-----Original Message-----
>>>From: Christian Ponti [mailto:[hidden email]]
>>>Sent: 15 March 2007 5:29 a.m.
>>>To: [hidden email]
>>>Subject: networking with smalltalk
>>>
>>>hi all,
>>>i need to collect data about network cards like mac address, ip
address

>>>in multiple card machines, under linux/mac/windows but didn't find
>>>something usefull. Any idea?
>>>In addition are there references or tutorials about networking in
>>>smalltalk?
>>>
>>>thx
>>>christian
>>
>>
>>
>>
>>
>>



Reply | Threaded
Open this post in threaded view
|

Re: networking with smalltalk

Ralf Propach
Stewart MacLean wrote:

> Hi Mark and all,
>
> I've decided to grasp the "bull by the horns" and what follows is my
> initial attempt at translating something very similar to your suggested
> C code, to DLLCC. After studying the manual, I've gone about as far as I
> can go (given my limited C knowledge). I know what needs to be done, but
> just don't know how to do it. Any help answering my questions below
> greatly appreciated... [The C code I'm translating is below].
>
> I've found a suitable Iphlpapi.h header file, parsed it, and created an
> ExternalInterface subclass (after editing out the line numbers).
>
> This is the api so far...
>
> getMacAddresses
>
> | pAdapterInfo pOutBufLen status answer |
>
> pAdapterInfo := self _IP_ADAPTER_INFO gcMalloc: 16.
>
> "I'm guessing that structs, not just basic types can be used in arrays,
> right?"

Yes, correct.

>
> "From the docs... gcMalloc: numCopies Allocates a C object in
> the external heap. Enough
> memory is allocated to contain numCopies of the receiver.
> A pointer to the first element is answered."
>
> "pOutBufLen := how do I get sizeOf(pAdapterInfo).  ???"

        pOutBufLen := self _IP_ADAPTER_INFO sizeof * 16.
        "I have not tested that, since I don't have your definition of _IP_ADAPTER_INFO"
>
> "According to the docs, I already have a pointer so I don't need
> to do the equivalent of PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;//
> Contains pointer to current adapter info. Correct?"
        Yes, correct.
>
> status :=
> self
> GetAdaptersInfo: pAdapterInfo contents "we've
> already got a pointer, and need to pass the data, so send contents to
> the pointer, correct?"

        No. You want to pass the pointer, so that the GetAdaptersInfo
        can fill the array with the data you want. The C program below
        also passes the adress.

> with: pOutBufLen.
>
> status = 0
> ifFalse: [^nil].
>
> "Pluck off the first address..."
> answer := OrderedCollection new
> add: (pAdapterInfo memberAt: #Address);
> yourself.
>
> "While not at the end of the linked list, pluck of remaining
> addresses..."
> [(pAdapterInfo := (pAdapterInfo memberAt: #Next)) ~= 0]
> whileTrue:
> [answer add: (pAdapterInfo memberAt: #Address)].
>
> ^answer
>

This looks correct, but I expect (pAdapterInfo memberAt: #Next) is some kind of CDatum object
and you will want to convert it into something more useable.


Ralf

> ========================================================================
> ==
> This is the C code I'm working towards...
>
> "
> static void GetMACaddress(void)
> {
> IP_ADAPTER_INFO AdapterInfo[16]; //
> Allocate information for up to 16 NICs
> DWORD dwBufLen = sizeof(AdapterInfo); // Save the
> memory size of buffer
>
> DWORD dwStatus = GetAdaptersInfo( // Call
> GetAdapterInfo
> AdapterInfo,
> // [out] buffer to receive data
> &dwBufLen);
> // [in] size of receive data buffer
> assert(dwStatus == ERROR_SUCCESS); // Verify return
> value is valid, no buffer overflow
>
> PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;// Contains pointer
> to current adapter info
> do {
> PrintMACaddress(pAdapterInfo->Address); // Print MAC
> address
> pAdapterInfo = pAdapterInfo->Next;
> // Progress through linked list
> }
> while(pAdapterInfo);
> // Terminate if last adapter
> }
> "
>
>
>
>
>
>>-----Original Message-----
>>From: Mark Pirogovsky [mailto:[hidden email]]
>>Sent: 16 March 2007 3:25 a.m.
>>To: Stewart MacLean
>>Cc: 'Christian Ponti'; [hidden email]
>>Subject: Re: networking with smalltalk
>>
>>Hello All,
>>
>>Using ifConfig or ipConfig.exe is not very reliable method IMHO.  There
>>are cases where the user may not have appropriate privileges to run
>>those programs or the programs maybe removed for some security
>>consideration and such.
>>
>>As it stands, there is no easy way to find MAC of the interface. Here
> is
>>another rub: on most of the modern computers the peripheral devices can
>>be enabled and/or disabled from OS.  It comes even trickier with
> laptops
>>if for example you are dealing with the PC Card type or USB  network
>>interfaces. As you insert one of those devices the list of the MACs
>>reflects this. And the same MAC may show up on few different PCs. And
> it
>>is not easy to tell if the device is built in or USB attached. another
>>bit of a good news: some network devices such as routers and bridges do
>>allow user defined MAC.
>>
>>So with all that said: even though it would be nice to use the MAC as
>>the unique PC identifier it is not reliable and/or sufficient.
>>
>>If you are dealing with more controlled environment , let say inside of
>>homogenous corporate network then you can try to implement the
> following
>>C code in the Smalltalk using DLLCC or just compile it into the DLL and
>>use it as such.
>>
>>My 2c.
>>
>>--Mark
>>
>>P.S. the following is C/C++ code for WIN32, for all of us smalltalkers
>>to enjoy. I am sure there is something similar for other platforms. It
>>is producing an executable, and it is relatively easy to make it into
>>the DLL as well.
>>
>>#include <stdlib.h>
>>#include <stdio.h>
>>#include <stddef.h>
>>#include <string.h>
>>#include <windows.h>
>>#include <winioctl.h>
>>
>>
>>// GetMACAdapters.cpp : Defines the entry point for the console
>>application.
>>//
>>// Author:   Khalid Shaikh [[hidden email]]
>>// Date:   April 5th, 2002
>>//
>>// This program fetches the MAC address of the localhost by fetching
> the
>>// information through GetAdapatersInfo.  It does not rely on the
> NETBIOS
>>// protocol and the ethernet adapter need not be connect to a network.
>>//
>>// Supported in Windows NT/2000/XP
>>// Supported in Windows 95/98/Me
>>//
>>// Supports multiple NIC cards on a PC.
>>
>>#include <Iphlpapi.h>
>>#include <Assert.h>
>>#pragma comment(lib, "iphlpapi.lib")
>>
>>#define PRINTING_TO_CONSOLE_ALLOWED
>>
>>// Prints the MAC address stored in a 6 byte array to stdout
>>static void PrintMACaddress(unsigned char MACData[])
>>{
>>
>>#ifdef PRINTING_TO_CONSOLE_ALLOWED
>>
>>   printf("\nMAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n",
>>      MACData[0], MACData[1], MACData[2], MACData[3], MACData[4],
>>MACData[5]);
>>
>>#endif
>>
>>   char string [256];
>>   sprintf (string, "%02X-%02X-%02X-%02X-%02X-%02X", MACData[0],
>>MACData[1],
>>            MACData[2], MACData[3], MACData[4], MACData[5]);
>>   WriteConstantString ("MACaddress", string);
>>}
>>
>>
>>
>>// Fetches the MAC address and prints it
>>DWORD GetMACaddress(void)
>>{
>>  DWORD MACaddress = 0;
>>  IP_ADAPTER_INFO AdapterInfo[16];       // Allocate information
>>                                         // for up to 16 NICs
>>  DWORD dwBufLen = sizeof(AdapterInfo);  // Save memory size of buffer
>>
>>  DWORD dwStatus = GetAdaptersInfo(      // Call GetAdapterInfo
>>         AdapterInfo,                 // [out] buffer to receive data
>>         &dwBufLen);                  // [in] size of receive data
> buffer
>>  assert(dwStatus == ERROR_SUCCESS);  // Verify return value is
>>                                      // valid, no buffer overflow
>>
>>  PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to
>>                                               // current adapter info
>>  do {
>>   if (MACaddress == 0)
>>      MACaddress = pAdapterInfo->Address [5] + pAdapterInfo->Address
>>[4] * 256 +
>>               pAdapterInfo->Address [3] * 256 * 256 +
>>               pAdapterInfo->Address [2] * 256 * 256 * 256;
>>    PrintMACaddress(pAdapterInfo->Address); // Print MAC address
>>    pAdapterInfo = pAdapterInfo->Next;    // Progress through linked
> list
>>  }
>>  while(pAdapterInfo);                    // Terminate if last adapter
>>
>>  return MACaddress;
>>}
>>
>>
>>
>>int main (int argc, char * argv [])
>>{
>>
>>   GetMACaddress ();
>>
>>   return 0;
>>}
>>
>>
>>Stewart MacLean wrote:
>>>Hi Christian,
>>>
>>>I've been investigating this too. This is what I've come up with so
>>>far...
>>>
>>>MacOSXSystemSupport>>getMACAddress
>>>
>>> ^((ExternalProcess defaultClass cshOne: 'ifconfig | grep ether')
>>>readStream contents reverse readStream
>>> upToSeparator) trimBlanks
>>>
>>>
>>>UnixSystemSupport>>getMACAddress
>>>
>>> ^((ExternalProcess defaultClass cshOne: 'dmesg | grep eth0')
>>>readStream contents reverse readStream
>>> upToSeparator) trimBlanks
>>>
>>>
>>>WindowsNTSystemSupport>>getMACAddress
>>>
>>>
>>> ^((ExternalProcess defaultClass cshOne: 'ipconfig /all')
>>>readStream
>>> skipThroughAll: 'Physical';
>>> upTo: $:;
>>> upToSeparator;
>>> upToSeparator) trimBlanks
>>>
>>>I've yet to test the Mac solution, but the Terminal command works ok.
>>>
>>>The Windows solution seems to fail intermittently, with pipe error
> 127.
>>>This could be to do with the different external process interface.
>>>
>>>Another alternative is to implement the low level OS calls using
> DLLCC.
>>>However, my C is not up to that :(
>>>
>>>HTH,
>>>
>>>Cheers,
>>>
>>>Stewart
>>>
>>>
>>>
>>>
>>>
>>>>-----Original Message-----
>>>>From: Christian Ponti [mailto:[hidden email]]
>>>>Sent: 15 March 2007 5:29 a.m.
>>>>To: [hidden email]
>>>>Subject: networking with smalltalk
>>>>
>>>>hi all,
>>>>i need to collect data about network cards like mac address, ip
> address
>>>>in multiple card machines, under linux/mac/windows but didn't find
>>>>something usefull. Any idea?
>>>>In addition are there references or tutorials about networking in
>>>>smalltalk?
>>>>
>>>>thx
>>>>christian
>>>
>>>
>>>
>>>
>>>
>
>
>
>


--
Ralf Propach, [hidden email]
Tel: +49 231 975 99 38   Fax: +49 231 975 99 20
Georg Heeg eK (Dortmund)
Handelsregister: Amtsgericht Dortmund  A 12812

Reply | Threaded
Open this post in threaded view
|

RE: networking with smalltalk

Stew MacLean
Hi Ralf,

Thank you for your very helpful comments.

Subsequently, I've realised that I needed to actually get the library.
(I thought it was on the system). After hunting around, I found one from
Microsoft Platform SDK, February 2001 Edition. However, it is
complaining with:

ERROR_BAD_EXE_FORMAT
193 %1 is not a valid Win32 application.

I'm running XP and I'm guessing that this version is too old?

I've looked at downloading the SDK, but as I'm running out of disk
space, I'd rather not - just for one file.

Can someone please send me suitable copy of "my little helper"
iphlpapi.lib

Thanks,

Stewart

>-----Original Message-----
>From: Ralf Propach [mailto:[hidden email]]
>Sent: 17 March 2007 3:01 a.m.
>To: Stewart MacLean; [hidden email]
>Subject: Re: networking with smalltalk
>
>Stewart MacLean wrote:
>> Hi Mark and all,
>>
>> I've decided to grasp the "bull by the horns" and what follows is my
>> initial attempt at translating something very similar to your
suggested
>> C code, to DLLCC. After studying the manual, I've gone about as far
as I
>> can go (given my limited C knowledge). I know what needs to be done,
but
>> just don't know how to do it. Any help answering my questions below
>> greatly appreciated... [The C code I'm translating is below].
>>
>> I've found a suitable Iphlpapi.h header file, parsed it, and created
an

>> ExternalInterface subclass (after editing out the line numbers).
>>
>> This is the api so far...
>>
>> getMacAddresses
>>
>> | pAdapterInfo pOutBufLen status answer |
>>
>> pAdapterInfo := self _IP_ADAPTER_INFO gcMalloc: 16.
>>
>> "I'm guessing that structs, not just basic types can be used in
arrays,

>> right?"
>
>Yes, correct.
>
>>
>> "From the docs... gcMalloc: numCopies Allocates a C object in
>> the external heap. Enough
>> memory is allocated to contain numCopies of the receiver.
>> A pointer to the first element is answered."
>>
>> "pOutBufLen := how do I get sizeOf(pAdapterInfo).  ???"
>
> pOutBufLen := self _IP_ADAPTER_INFO sizeof * 16.
> "I have not tested that, since I don't have your definition of
>_IP_ADAPTER_INFO"
>>
>> "According to the docs, I already have a pointer so I don't need
>> to do the equivalent of PIP_ADAPTER_INFO pAdapterInfo =
AdapterInfo;//

>> Contains pointer to current adapter info. Correct?"
> Yes, correct.
>>
>> status :=
>> self
>> GetAdaptersInfo: pAdapterInfo contents "we've
>> already got a pointer, and need to pass the data, so send contents to
>> the pointer, correct?"
>
> No. You want to pass the pointer, so that the GetAdaptersInfo
> can fill the array with the data you want. The C program below
> also passes the adress.
>
>> with: pOutBufLen.
>>
>> status = 0
>> ifFalse: [^nil].
>>
>> "Pluck off the first address..."
>> answer := OrderedCollection new
>> add: (pAdapterInfo memberAt: #Address);
>> yourself.
>>
>> "While not at the end of the linked list, pluck of remaining
>> addresses..."
>> [(pAdapterInfo := (pAdapterInfo memberAt: #Next)) ~= 0]
>> whileTrue:
>> [answer add: (pAdapterInfo memberAt: #Address)].
>>
>> ^answer
>>
>
>This looks correct, but I expect (pAdapterInfo memberAt: #Next) is some
>kind of CDatum object
>and you will want to convert it into something more useable.
>
>
>Ralf
>
>>
========================================================================

>> ==
>> This is the C code I'm working towards...
>>
>> "
>> static void GetMACaddress(void)
>> {
>> IP_ADAPTER_INFO AdapterInfo[16]; //
>> Allocate information for up to 16 NICs
>> DWORD dwBufLen = sizeof(AdapterInfo); // Save the
>> memory size of buffer
>>
>> DWORD dwStatus = GetAdaptersInfo( // Call
>> GetAdapterInfo
>> AdapterInfo,
>> // [out] buffer to receive data
>> &dwBufLen);
>> // [in] size of receive data buffer
>> assert(dwStatus == ERROR_SUCCESS); // Verify return
>> value is valid, no buffer overflow
>>
>> PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;// Contains pointer
>> to current adapter info
>> do {
>> PrintMACaddress(pAdapterInfo->Address); // Print MAC
>> address
>> pAdapterInfo = pAdapterInfo->Next;
>> // Progress through linked list
>> }
>> while(pAdapterInfo);
>> // Terminate if last adapter
>> }
>> "
>>
>>
>>
>>
>>
>>>-----Original Message-----
>>>From: Mark Pirogovsky [mailto:[hidden email]]
>>>Sent: 16 March 2007 3:25 a.m.
>>>To: Stewart MacLean
>>>Cc: 'Christian Ponti'; [hidden email]
>>>Subject: Re: networking with smalltalk
>>>
>>>Hello All,
>>>
>>>Using ifConfig or ipConfig.exe is not very reliable method IMHO.
There
>>>are cases where the user may not have appropriate privileges to run
>>>those programs or the programs maybe removed for some security
>>>consideration and such.
>>>
>>>As it stands, there is no easy way to find MAC of the interface. Here
>> is
>>>another rub: on most of the modern computers the peripheral devices
can
>>>be enabled and/or disabled from OS.  It comes even trickier with
>> laptops
>>>if for example you are dealing with the PC Card type or USB  network
>>>interfaces. As you insert one of those devices the list of the MACs
>>>reflects this. And the same MAC may show up on few different PCs. And
>> it
>>>is not easy to tell if the device is built in or USB attached.
another
>>>bit of a good news: some network devices such as routers and bridges
do
>>>allow user defined MAC.
>>>
>>>So with all that said: even though it would be nice to use the MAC as
>>>the unique PC identifier it is not reliable and/or sufficient.
>>>
>>>If you are dealing with more controlled environment , let say inside
of
>>>homogenous corporate network then you can try to implement the
>> following
>>>C code in the Smalltalk using DLLCC or just compile it into the DLL
and
>>>use it as such.
>>>
>>>My 2c.
>>>
>>>--Mark
>>>
>>>P.S. the following is C/C++ code for WIN32, for all of us
smalltalkers
>>>to enjoy. I am sure there is something similar for other platforms.
It

>>>is producing an executable, and it is relatively easy to make it into
>>>the DLL as well.
>>>
>>>#include <stdlib.h>
>>>#include <stdio.h>
>>>#include <stddef.h>
>>>#include <string.h>
>>>#include <windows.h>
>>>#include <winioctl.h>
>>>
>>>
>>>// GetMACAdapters.cpp : Defines the entry point for the console
>>>application.
>>>//
>>>// Author:   Khalid Shaikh [[hidden email]]
>>>// Date:   April 5th, 2002
>>>//
>>>// This program fetches the MAC address of the localhost by fetching
>> the
>>>// information through GetAdapatersInfo.  It does not rely on the
>> NETBIOS
>>>// protocol and the ethernet adapter need not be connect to a
network.

>>>//
>>>// Supported in Windows NT/2000/XP
>>>// Supported in Windows 95/98/Me
>>>//
>>>// Supports multiple NIC cards on a PC.
>>>
>>>#include <Iphlpapi.h>
>>>#include <Assert.h>
>>>#pragma comment(lib, "iphlpapi.lib")
>>>
>>>#define PRINTING_TO_CONSOLE_ALLOWED
>>>
>>>// Prints the MAC address stored in a 6 byte array to stdout
>>>static void PrintMACaddress(unsigned char MACData[])
>>>{
>>>
>>>#ifdef PRINTING_TO_CONSOLE_ALLOWED
>>>
>>>   printf("\nMAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n",
>>>      MACData[0], MACData[1], MACData[2], MACData[3], MACData[4],
>>>MACData[5]);
>>>
>>>#endif
>>>
>>>   char string [256];
>>>   sprintf (string, "%02X-%02X-%02X-%02X-%02X-%02X", MACData[0],
>>>MACData[1],
>>>            MACData[2], MACData[3], MACData[4], MACData[5]);
>>>   WriteConstantString ("MACaddress", string);
>>>}
>>>
>>>
>>>
>>>// Fetches the MAC address and prints it
>>>DWORD GetMACaddress(void)
>>>{
>>>  DWORD MACaddress = 0;
>>>  IP_ADAPTER_INFO AdapterInfo[16];       // Allocate information
>>>                                         // for up to 16 NICs
>>>  DWORD dwBufLen = sizeof(AdapterInfo);  // Save memory size of
buffer

>>>
>>>  DWORD dwStatus = GetAdaptersInfo(      // Call GetAdapterInfo
>>>         AdapterInfo,                 // [out] buffer to receive data
>>>         &dwBufLen);                  // [in] size of receive data
>> buffer
>>>  assert(dwStatus == ERROR_SUCCESS);  // Verify return value is
>>>                                      // valid, no buffer overflow
>>>
>>>  PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to
>>>                                               // current adapter
info

>>>  do {
>>>   if (MACaddress == 0)
>>>      MACaddress = pAdapterInfo->Address [5] + pAdapterInfo->Address
>>>[4] * 256 +
>>>               pAdapterInfo->Address [3] * 256 * 256 +
>>>               pAdapterInfo->Address [2] * 256 * 256 * 256;
>>>    PrintMACaddress(pAdapterInfo->Address); // Print MAC address
>>>    pAdapterInfo = pAdapterInfo->Next;    // Progress through linked
>> list
>>>  }
>>>  while(pAdapterInfo);                    // Terminate if last
adapter

>>>
>>>  return MACaddress;
>>>}
>>>
>>>
>>>
>>>int main (int argc, char * argv [])
>>>{
>>>
>>>   GetMACaddress ();
>>>
>>>   return 0;
>>>}
>>>
>>>
>>>Stewart MacLean wrote:
>>>>Hi Christian,
>>>>
>>>>I've been investigating this too. This is what I've come up with so
>>>>far...
>>>>
>>>>MacOSXSystemSupport>>getMACAddress
>>>>
>>>> ^((ExternalProcess defaultClass cshOne: 'ifconfig | grep ether')
>>>>readStream contents reverse readStream
>>>> upToSeparator) trimBlanks
>>>>
>>>>
>>>>UnixSystemSupport>>getMACAddress
>>>>
>>>> ^((ExternalProcess defaultClass cshOne: 'dmesg | grep eth0')
>>>>readStream contents reverse readStream
>>>> upToSeparator) trimBlanks
>>>>
>>>>
>>>>WindowsNTSystemSupport>>getMACAddress
>>>>
>>>>
>>>> ^((ExternalProcess defaultClass cshOne: 'ipconfig /all')
>>>>readStream
>>>> skipThroughAll: 'Physical';
>>>> upTo: $:;
>>>> upToSeparator;
>>>> upToSeparator) trimBlanks
>>>>
>>>>I've yet to test the Mac solution, but the Terminal command works
ok.

>>>>
>>>>The Windows solution seems to fail intermittently, with pipe error
>> 127.
>>>>This could be to do with the different external process interface.
>>>>
>>>>Another alternative is to implement the low level OS calls using
>> DLLCC.
>>>>However, my C is not up to that :(
>>>>
>>>>HTH,
>>>>
>>>>Cheers,
>>>>
>>>>Stewart
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>-----Original Message-----
>>>>>From: Christian Ponti [mailto:[hidden email]]
>>>>>Sent: 15 March 2007 5:29 a.m.
>>>>>To: [hidden email]
>>>>>Subject: networking with smalltalk
>>>>>
>>>>>hi all,
>>>>>i need to collect data about network cards like mac address, ip
>> address
>>>>>in multiple card machines, under linux/mac/windows but didn't find
>>>>>something usefull. Any idea?
>>>>>In addition are there references or tutorials about networking in
>>>>>smalltalk?
>>>>>
>>>>>thx
>>>>>christian
>>>>
>>>>
>>>>
>>>>
>>>>
>>
>>
>>
>>
>
>
>--
>Ralf Propach, [hidden email]
>Tel: +49 231 975 99 38   Fax: +49 231 975 99 20
>Georg Heeg eK (Dortmund)
>Handelsregister: Amtsgericht Dortmund  A 12812


Reply | Threaded
Open this post in threaded view
|

RE: networking with smalltalk

Stew MacLean
An update...

I've tried downloading the latest SDK, but it wouldn't let me, as I
don't have SP2 installed. I then downloaded the Windows 2003 Server SDK,
and tried the library that comes with that.

Unfortunately, I'm still getting the same error...

ERROR_BAD_EXE_FORMAT
193 %1 is not a valid Win32 application.

I'm stumped!

Cheers,

Stewart

>-----Original Message-----
>From: Stewart MacLean [mailto:[hidden email]]
>Sent: 17 March 2007 9:44 a.m.
>To: 'Ralf Propach'; [hidden email]
>Subject: RE: networking with smalltalk
>
>Hi Ralf,
>
>Thank you for your very helpful comments.
>
>Subsequently, I've realised that I needed to actually get the library.
>(I thought it was on the system). After hunting around, I found one
from

>Microsoft Platform SDK, February 2001 Edition. However, it is
>complaining with:
>
>ERROR_BAD_EXE_FORMAT
>193 %1 is not a valid Win32 application.
>
>I'm running XP and I'm guessing that this version is too old?
>
>I've looked at downloading the SDK, but as I'm running out of disk
>space, I'd rather not - just for one file.
>
>Can someone please send me suitable copy of "my little helper"
>iphlpapi.lib
>
>Thanks,
>
>Stewart
>
>>-----Original Message-----
>>From: Ralf Propach [mailto:[hidden email]]
>>Sent: 17 March 2007 3:01 a.m.
>>To: Stewart MacLean; [hidden email]
>>Subject: Re: networking with smalltalk
>>
>>Stewart MacLean wrote:
>>> Hi Mark and all,
>>>
>>> I've decided to grasp the "bull by the horns" and what follows is my
>>> initial attempt at translating something very similar to your
>suggested
>>> C code, to DLLCC. After studying the manual, I've gone about as far
>as I
>>> can go (given my limited C knowledge). I know what needs to be done,
>but
>>> just don't know how to do it. Any help answering my questions below
>>> greatly appreciated... [The C code I'm translating is below].
>>>
>>> I've found a suitable Iphlpapi.h header file, parsed it, and created
>an
>>> ExternalInterface subclass (after editing out the line numbers).
>>>
>>> This is the api so far...
>>>
>>> getMacAddresses
>>>
>>> | pAdapterInfo pOutBufLen status answer |
>>>
>>> pAdapterInfo := self _IP_ADAPTER_INFO gcMalloc: 16.
>>>
>>> "I'm guessing that structs, not just basic types can be used in
>arrays,
>>> right?"
>>
>>Yes, correct.
>>
>>>
>>> "From the docs... gcMalloc: numCopies Allocates a C object in
>>> the external heap. Enough
>>> memory is allocated to contain numCopies of the receiver.
>>> A pointer to the first element is answered."
>>>
>>> "pOutBufLen := how do I get sizeOf(pAdapterInfo).  ???"
>>
>> pOutBufLen := self _IP_ADAPTER_INFO sizeof * 16.
>> "I have not tested that, since I don't have your definition of
>>_IP_ADAPTER_INFO"
>>>
>>> "According to the docs, I already have a pointer so I don't need
>>> to do the equivalent of PIP_ADAPTER_INFO pAdapterInfo =
>AdapterInfo;//
>>> Contains pointer to current adapter info. Correct?"
>> Yes, correct.
>>>
>>> status :=
>>> self
>>> GetAdaptersInfo: pAdapterInfo contents "we've
>>> already got a pointer, and need to pass the data, so send contents
to

>>> the pointer, correct?"
>>
>> No. You want to pass the pointer, so that the GetAdaptersInfo
>> can fill the array with the data you want. The C program below
>> also passes the adress.
>>
>>> with: pOutBufLen.
>>>
>>> status = 0
>>> ifFalse: [^nil].
>>>
>>> "Pluck off the first address..."
>>> answer := OrderedCollection new
>>> add: (pAdapterInfo memberAt: #Address);
>>> yourself.
>>>
>>> "While not at the end of the linked list, pluck of remaining
>>> addresses..."
>>> [(pAdapterInfo := (pAdapterInfo memberAt: #Next)) ~= 0]
>>> whileTrue:
>>> [answer add: (pAdapterInfo memberAt: #Address)].
>>>
>>> ^answer
>>>
>>
>>This looks correct, but I expect (pAdapterInfo memberAt: #Next) is
some
>>kind of CDatum object
>>and you will want to convert it into something more useable.
>>
>>
>>Ralf
>>
>>>
>=======================================================================
=

>>> ==
>>> This is the C code I'm working towards...
>>>
>>> "
>>> static void GetMACaddress(void)
>>> {
>>> IP_ADAPTER_INFO AdapterInfo[16]; //
>>> Allocate information for up to 16 NICs
>>> DWORD dwBufLen = sizeof(AdapterInfo); // Save the
>>> memory size of buffer
>>>
>>> DWORD dwStatus = GetAdaptersInfo( // Call
>>> GetAdapterInfo
>>> AdapterInfo,
>>> // [out] buffer to receive data
>>> &dwBufLen);
>>> // [in] size of receive data buffer
>>> assert(dwStatus == ERROR_SUCCESS); // Verify return
>>> value is valid, no buffer overflow
>>>
>>> PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;// Contains pointer
>>> to current adapter info
>>> do {
>>> PrintMACaddress(pAdapterInfo->Address); // Print MAC
>>> address
>>> pAdapterInfo = pAdapterInfo->Next;
>>> // Progress through linked list
>>> }
>>> while(pAdapterInfo);
>>> // Terminate if last adapter
>>> }
>>> "
>>>
>>>
>>>
>>>
>>>
>>>>-----Original Message-----
>>>>From: Mark Pirogovsky [mailto:[hidden email]]
>>>>Sent: 16 March 2007 3:25 a.m.
>>>>To: Stewart MacLean
>>>>Cc: 'Christian Ponti'; [hidden email]
>>>>Subject: Re: networking with smalltalk
>>>>
>>>>Hello All,
>>>>
>>>>Using ifConfig or ipConfig.exe is not very reliable method IMHO.
>There
>>>>are cases where the user may not have appropriate privileges to run
>>>>those programs or the programs maybe removed for some security
>>>>consideration and such.
>>>>
>>>>As it stands, there is no easy way to find MAC of the interface.
Here
>>> is
>>>>another rub: on most of the modern computers the peripheral devices
>can
>>>>be enabled and/or disabled from OS.  It comes even trickier with
>>> laptops
>>>>if for example you are dealing with the PC Card type or USB  network
>>>>interfaces. As you insert one of those devices the list of the MACs
>>>>reflects this. And the same MAC may show up on few different PCs.
And
>>> it
>>>>is not easy to tell if the device is built in or USB attached.
>another
>>>>bit of a good news: some network devices such as routers and bridges
>do
>>>>allow user defined MAC.
>>>>
>>>>So with all that said: even though it would be nice to use the MAC
as

>>>>the unique PC identifier it is not reliable and/or sufficient.
>>>>
>>>>If you are dealing with more controlled environment , let say inside
>of
>>>>homogenous corporate network then you can try to implement the
>>> following
>>>>C code in the Smalltalk using DLLCC or just compile it into the DLL
>and
>>>>use it as such.
>>>>
>>>>My 2c.
>>>>
>>>>--Mark
>>>>
>>>>P.S. the following is C/C++ code for WIN32, for all of us
>smalltalkers
>>>>to enjoy. I am sure there is something similar for other platforms.
>It
>>>>is producing an executable, and it is relatively easy to make it
into

>>>>the DLL as well.
>>>>
>>>>#include <stdlib.h>
>>>>#include <stdio.h>
>>>>#include <stddef.h>
>>>>#include <string.h>
>>>>#include <windows.h>
>>>>#include <winioctl.h>
>>>>
>>>>
>>>>// GetMACAdapters.cpp : Defines the entry point for the console
>>>>application.
>>>>//
>>>>// Author:   Khalid Shaikh [[hidden email]]
>>>>// Date:   April 5th, 2002
>>>>//
>>>>// This program fetches the MAC address of the localhost by fetching
>>> the
>>>>// information through GetAdapatersInfo.  It does not rely on the
>>> NETBIOS
>>>>// protocol and the ethernet adapter need not be connect to a
>network.
>>>>//
>>>>// Supported in Windows NT/2000/XP
>>>>// Supported in Windows 95/98/Me
>>>>//
>>>>// Supports multiple NIC cards on a PC.
>>>>
>>>>#include <Iphlpapi.h>
>>>>#include <Assert.h>
>>>>#pragma comment(lib, "iphlpapi.lib")
>>>>
>>>>#define PRINTING_TO_CONSOLE_ALLOWED
>>>>
>>>>// Prints the MAC address stored in a 6 byte array to stdout
>>>>static void PrintMACaddress(unsigned char MACData[])
>>>>{
>>>>
>>>>#ifdef PRINTING_TO_CONSOLE_ALLOWED
>>>>
>>>>   printf("\nMAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n",
>>>>      MACData[0], MACData[1], MACData[2], MACData[3], MACData[4],
>>>>MACData[5]);
>>>>
>>>>#endif
>>>>
>>>>   char string [256];
>>>>   sprintf (string, "%02X-%02X-%02X-%02X-%02X-%02X", MACData[0],
>>>>MACData[1],
>>>>            MACData[2], MACData[3], MACData[4], MACData[5]);
>>>>   WriteConstantString ("MACaddress", string);
>>>>}
>>>>
>>>>
>>>>
>>>>// Fetches the MAC address and prints it
>>>>DWORD GetMACaddress(void)
>>>>{
>>>>  DWORD MACaddress = 0;
>>>>  IP_ADAPTER_INFO AdapterInfo[16];       // Allocate information
>>>>                                         // for up to 16 NICs
>>>>  DWORD dwBufLen = sizeof(AdapterInfo);  // Save memory size of
>buffer
>>>>
>>>>  DWORD dwStatus = GetAdaptersInfo(      // Call GetAdapterInfo
>>>>         AdapterInfo,                 // [out] buffer to receive
data
>>>>         &dwBufLen);                  // [in] size of receive data
>>> buffer
>>>>  assert(dwStatus == ERROR_SUCCESS);  // Verify return value is
>>>>                                      // valid, no buffer overflow
>>>>
>>>>  PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer
to

>>>>                                               // current adapter
>info
>>>>  do {
>>>>   if (MACaddress == 0)
>>>>      MACaddress = pAdapterInfo->Address [5] + pAdapterInfo->Address
>>>>[4] * 256 +
>>>>               pAdapterInfo->Address [3] * 256 * 256 +
>>>>               pAdapterInfo->Address [2] * 256 * 256 * 256;
>>>>    PrintMACaddress(pAdapterInfo->Address); // Print MAC address
>>>>    pAdapterInfo = pAdapterInfo->Next;    // Progress through linked
>>> list
>>>>  }
>>>>  while(pAdapterInfo);                    // Terminate if last
>adapter
>>>>
>>>>  return MACaddress;
>>>>}
>>>>
>>>>
>>>>
>>>>int main (int argc, char * argv [])
>>>>{
>>>>
>>>>   GetMACaddress ();
>>>>
>>>>   return 0;
>>>>}
>>>>
>>>>
>>>>Stewart MacLean wrote:
>>>>>Hi Christian,
>>>>>
>>>>>I've been investigating this too. This is what I've come up with so
>>>>>far...
>>>>>
>>>>>MacOSXSystemSupport>>getMACAddress
>>>>>
>>>>> ^((ExternalProcess defaultClass cshOne: 'ifconfig | grep ether')
>>>>>readStream contents reverse readStream
>>>>> upToSeparator) trimBlanks
>>>>>
>>>>>
>>>>>UnixSystemSupport>>getMACAddress
>>>>>
>>>>> ^((ExternalProcess defaultClass cshOne: 'dmesg | grep eth0')
>>>>>readStream contents reverse readStream
>>>>> upToSeparator) trimBlanks
>>>>>
>>>>>
>>>>>WindowsNTSystemSupport>>getMACAddress
>>>>>
>>>>>
>>>>> ^((ExternalProcess defaultClass cshOne: 'ipconfig /all')
>>>>>readStream
>>>>> skipThroughAll: 'Physical';
>>>>> upTo: $:;
>>>>> upToSeparator;
>>>>> upToSeparator) trimBlanks
>>>>>
>>>>>I've yet to test the Mac solution, but the Terminal command works
>ok.
>>>>>
>>>>>The Windows solution seems to fail intermittently, with pipe error
>>> 127.
>>>>>This could be to do with the different external process interface.
>>>>>
>>>>>Another alternative is to implement the low level OS calls using
>>> DLLCC.
>>>>>However, my C is not up to that :(
>>>>>
>>>>>HTH,
>>>>>
>>>>>Cheers,
>>>>>
>>>>>Stewart
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>-----Original Message-----
>>>>>>From: Christian Ponti [mailto:[hidden email]]
>>>>>>Sent: 15 March 2007 5:29 a.m.
>>>>>>To: [hidden email]
>>>>>>Subject: networking with smalltalk
>>>>>>
>>>>>>hi all,
>>>>>>i need to collect data about network cards like mac address, ip
>>> address
>>>>>>in multiple card machines, under linux/mac/windows but didn't find
>>>>>>something usefull. Any idea?
>>>>>>In addition are there references or tutorials about networking in
>>>>>>smalltalk?
>>>>>>
>>>>>>thx
>>>>>>christian
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>>>
>>
>>
>>--
>>Ralf Propach, [hidden email]
>>Tel: +49 231 975 99 38   Fax: +49 231 975 99 20
>>Georg Heeg eK (Dortmund)
>>Handelsregister: Amtsgericht Dortmund  A 12812
>



Reply | Threaded
Open this post in threaded view
|

Re: networking with smalltalk

Thomas Gagné-2
In reply to this post by Mark Pirogovsky-3
Here's one for Linux:

    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/ioctl.h>
    #include <sys/socket.h>
    #include <sys/types.h>
    #include <net/if.h>
    #include <netdb.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <fcntl.h>

    int main(int argc, char **argv, char **envp)
    {
            struct ifreq ifr;
            struct sockaddr_in *sin;
            int fd, i;

            if (argc == 2) {
                    sin = (struct sockaddr_in *) &ifr.ifr_addr;
                    bzero(&ifr, sizeof(ifr));

                    if ((fd = socket(AF_INET, SOCK_STREAM, 0)) >= 0) {
                            strcpy(ifr.ifr_name, argv[1]);
                            /*
                               sin->sin_family = AF_INET;
                             */
                            if (ioctl(fd, SIOCGIFADDR, &ifr) == 0)
                                    fprintf(stdout, "%s\n",
    inet_ntoa(sin->sin_addr));
                            // fputs("done", stdout);
                            else
                                    perror("ioctl()");
                            close(fd);
                    }
                    else {
                            perror(argv[1]);
                            return EXIT_FAILURE;
                    }
            }
            else
                    fprintf(stderr, "usage: %s ifname\n", argv[0]);

            return EXIT_SUCCESS;
    }



--
Visit <http://tggagne.blogspot.com/>,<http://gagne.homedns.org/> or
      <http://gagne.homedns.org/~tgagne/> for more great reading.

Reply | Threaded
Open this post in threaded view
|

RE: networking with smalltalk

Gautier Dhordain
In reply to this post by Christian Ponti
Hi Stewart,
 
With the help of Ralf, I have worked on your problem.
I have created an ExternalInterface subclass (IPHelper in my example) which used iphlpapi.dll as a library file.
 
Here is your modified method:
 
getMacAddresses
 
        | pAdapterInfo pOutBufLen status answer |
 
        pAdapterInfo := self IP_ADAPTER_INFO gcMalloc: 16. 
        pOutBufLen := self ULONG gcMalloc: 1.
        pOutBufLen at: 0 put: self IP_ADAPTER_INFO sizeof * 16.
 
        status := 
               self 
                       GetAdaptersInfo: pAdapterInfo
                       with: pOutBufLen.
 
        status = 0 
               ifFalse: [^nil].
 
        answer := OrderedCollection new
               add: (OrderedCollection new
                               add: ((0 to: 5) collect: [:i | 
                                              ((pAdapterInfo memberAt: #Address) at: i) printStringRadix: 16]));
               yourself.
 
        [(pAdapterInfo := (pAdapterInfo memberAt: #Next)) isValid]
        whileTrue:
               [answer add: 
                       (OrderedCollection new
                               add: ((0 to: 5) collect: [:i | 
                                              ((pAdapterInfo memberAt: #Address) at: i) printStringRadix: 16]))].
 
        ^answer
 
It will return to you an ordered collection which contains an ordered collection for each MAC address it has found.
I hope it can help you.
 
Gautier
Reply | Threaded
Open this post in threaded view
|

RE: networking with smalltalk

Stew MacLean

Hi Gautier and Ralf,

 

Thank you very much for helping me with this – I need all the help I can get here!

 

I have realised why my previous attempts where failing on loading the library – I was using iphlpapi.lib which is static, not dynamic (duh!).

 

I’ve then found the iphlpapi.dll on my system and have copied it to the working directory. I couldn’t find a ULONG method so I’ve used DWORD, which I think has the same effect.

 

So now, I’m getting a

 

-self:  a SystemError(#'unsupported operation',nil)

parameter:  nil

name:  #'unsupported operation'

 

using

 

GetAdaptersInfo: pAdapterInfo with: pOutBufLen

            <C: DWORD GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)>

            ^self externalAccessFailedWith: _errorCode

 

with arguments:

 

 

-bytes:  #[120 1 50 0 120 1 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 2 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0...etc...]

Next:  a CCompositePointer {00320178} (struct _IP_ADAPTER_INFO * )

ComboIndex:  3277176

AdapterName:  a CPointer {00E97618} (char * )

Description:  a CPointer {00E9771C} (char * )

AddressLength:  a CPointer {invalid} (UINT)

Address:  a CPointer {00E977A4} (void * * )

Index:  543

Type:  a CPointer {00000371} (UINT)

DhcpEnabled:  a CPointer {0000020A} (UINT)

CurrentIpAddress:  a CCompositePointer {00000386} (PIP_ADDR_STRING)

IpAddressList:  a CComposite (struct _IP_ADDR_STRING)

GatewayList:  a CComposite (struct _IP_ADDR_STRING)

DhcpServer:  a CComposite (struct _IP_ADDR_STRING)

HaveWins:  a CPointer {invalid} (BOOL)

PrimaryWinsServer:  a CComposite (struct _IP_ADDR_STRING)

SecondaryWinsServer:  a CComposite (struct _IP_ADDR_STRING)

LeaseObtained:  a CPointer {00000130} (time_t)

LeaseExpires:  a CPointer {0000001E} (time_t)

 

And:

 

-self:  a CPointer {0032F868} (unsigned long * )

theDatum:  3340392

type:  unsigned long *

 

(self at: 0) 10624

 

So it’s found the library ok, it’s found the entry point ok (I’ve also check the library using pedump within the lcc compiler (I’ve now got one!)).

 

In the docs, it says

 

#'unsupported

operation'

nil

 

 An operation unsupported on the

current platform has been

attempted (e.g. calling a _wincall

error convention function call on

a non-Windows platform).

 

Completely speculating, my guess is that the format of my procedure call is maybe wrong? This method was generated by the library builder. Or maybe I have the wrong structure for the info?

 

Any help greatly appreciated,

 

Thanks,

 

Stewart

 

_IP_ADAPTER_INFO

            <C: struct _IP_ADAPTER_INFO {

                                    struct _IP_ADAPTER_INFO * Next;

                                    DWORD ComboIndex;

                                    char AdapterName[260];

                                    char Description[132];

                                    UINT AddressLength;

                                    BYTE Address[8];

                                    DWORD Index;

                                    UINT Type, DhcpEnabled;

                                    PIP_ADDR_STRING CurrentIpAddress;

                                    IP_ADDR_STRING IpAddressList, GatewayList, DhcpServer;

                                    BOOL HaveWins;

                                    IP_ADDR_STRING PrimaryWinsServer, SecondaryWinsServer;

                                    time_t LeaseObtained, LeaseExpires;

                        }>

 

DWORD

         <C: typedef unsigned long DWORD>

 

 

 

 

-----Original Message-----
From: Gautier Dhordain [mailto:[hidden email]]
Sent: 21 March 2007 12:12 a.m.
To: [hidden email]; [hidden email]
Cc: [hidden email]
Subject: RE: networking with smalltalk

 

Hi Stewart,
 
With the help of Ralf, I have worked on your problem.
I have created an ExternalInterface subclass (IPHelper in my example) which used iphlpapi.dll as a library file.
 
Here is your modified method:
 
getMacAddresses
 
        | pAdapterInfo pOutBufLen status answer |
 
        pAdapterInfo := self IP_ADAPTER_INFO gcMalloc: 16. 
        pOutBufLen := self ULONG gcMalloc: 1.
        pOutBufLen at: 0 put: self IP_ADAPTER_INFO sizeof * 16.
 
        status := 
               self 
                       GetAdaptersInfo: pAdapterInfo
                       with: pOutBufLen.
 
        status = 0 
               ifFalse: [^nil].
 
        answer := OrderedCollection new
               add: (OrderedCollection new
                               add: ((0 to: 5) collect: [:i | 
                                              ((pAdapterInfo memberAt: #Address) at: i) printStringRadix: 16]));
               yourself.
 
        [(pAdapterInfo := (pAdapterInfo memberAt: #Next)) isValid]
        whileTrue:
               [answer add: 
                       (OrderedCollection new
                               add: ((0 to: 5) collect: [:i | 
                                              ((pAdapterInfo memberAt: #Address) at: i) printStringRadix: 16]))].
 
        ^answer
 
It will return to you an ordered collection which contains an ordered collection for each MAC address it has found.
I hope it can help you.
 
Gautier
Reply | Threaded
Open this post in threaded view
|

AW: networking with smalltalk

Gautier Dhordain

Hi Stewart,

 

For the ULONG, it’s the same as a DWORD (a unsigned long), you’re right.

 

Concerning the error, can you show me your IP_ADDR_STRING ? As you can see in my IP_ADAPTER_INFO declaration, it’s a structure for me.

 

IP_ADAPTER_INFO

            <C: struct IP_ADAPTER_INFO {

                                    struct IP_ADAPTER_INFO* Next;

                                    DWORD ComboIndex;

                                    char AdapterName[256 + 4];

                                    char Description[128 + 4];

                                    UINT AddressLength;

                                    BYTE Address[8];

                                    DWORD Index;

                                    UINT Type;

                                    UINT DhcpEnabled;

                                    PIP_ADDR_STRING CurrentIpAddress;

                                    struct IP_ADDR_STRING IpAddressList;

                                    struct IP_ADDR_STRING GatewayList;

                                    struct IP_ADDR_STRING DhcpServer;

                                    BOOL HaveWins;

                                    struct IP_ADDR_STRING PrimaryWinsServer;

                                    struct IP_ADDR_STRING SecondaryWinsServer;

                                    time_t LeaseObtained;

                                    time_t LeaseExpires;

                        }>

 

IP_ADDRESS_STRING

            <C: struct IP_ADDRESS_STRING {

                                    char String[16];

                        }>

 

Regards,

Gautier

 

-----Ursprüngliche Nachricht-----
Von: Stewart MacLean [mailto:[hidden email]]
Gesendet: Tuesday, March 20, 2007 11:10 PM
An: 'Gautier Dhordain'; [hidden email]
Cc: [hidden email]
Betreff: RE: networking with smalltalk

 

Hi Gautier and Ralf,

 

Thank you very much for helping me with this – I need all the help I can get here!

 

I have realised why my previous attempts where failing on loading the library – I was using iphlpapi.lib which is static, not dynamic (duh!).

 

I’ve then found the iphlpapi.dll on my system and have copied it to the working directory. I couldn’t find a ULONG method so I’ve used DWORD, which I think has the same effect.

 

So now, I’m getting a

 

-self:  a SystemError(#'unsupported operation',nil)

parameter:  nil

name:  #'unsupported operation'

 

using

 

GetAdaptersInfo: pAdapterInfo with: pOutBufLen

            <C: DWORD GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)>

            ^self externalAccessFailedWith: _errorCode

 

with arguments:

 

 

-bytes:  #[120 1 50 0 120 1 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 2 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0...etc...]

Next:  a CCompositePointer {00320178} (struct _IP_ADAPTER_INFO * )

ComboIndex:  3277176

AdapterName:  a CPointer {00E97618} (char * )

Description:  a CPointer {00E9771C} (char * )

AddressLength:  a CPointer {invalid} (UINT)

Address:  a CPointer {00E977A4} (void * * )

Index:  543

Type:  a CPointer {00000371} (UINT)

DhcpEnabled:  a CPointer {0000020A} (UINT)

CurrentIpAddress:  a CCompositePointer {00000386} (PIP_ADDR_STRING)

IpAddressList:  a CComposite (struct _IP_ADDR_STRING)

GatewayList:  a CComposite (struct _IP_ADDR_STRING)

DhcpServer:  a CComposite (struct _IP_ADDR_STRING)

HaveWins:  a CPointer {invalid} (BOOL)

PrimaryWinsServer:  a CComposite (struct _IP_ADDR_STRING)

SecondaryWinsServer:  a CComposite (struct _IP_ADDR_STRING)

LeaseObtained:  a CPointer {00000130} (time_t)

LeaseExpires:  a CPointer {0000001E} (time_t)

 

And:

 

-self:  a CPointer {0032F868} (unsigned long * )

theDatum:  3340392

type:  unsigned long *

 

(self at: 0) 10624

 

So it’s found the library ok, it’s found the entry point ok (I’ve also check the library using pedump within the lcc compiler (I’ve now got one!)).

 

In the docs, it says

 

#'unsupported

operation'

nil

 

 An operation unsupported on the

current platform has been

attempted (e.g. calling a _wincall

error convention function call on

a non-Windows platform).

 

Completely speculating, my guess is that the format of my procedure call is maybe wrong? This method was generated by the library builder. Or maybe I have the wrong structure for the info?

 

Any help greatly appreciated,

 

Thanks,

 

Stewart

 

_IP_ADAPTER_INFO

            <C: struct _IP_ADAPTER_INFO {

                                    struct _IP_ADAPTER_INFO * Next;

                                    DWORD ComboIndex;

                                    char AdapterName[260];

                                    char Description[132];

                                    UINT AddressLength;

                                    BYTE Address[8];

                                    DWORD Index;

                                    UINT Type, DhcpEnabled;

                                    PIP_ADDR_STRING CurrentIpAddress;

                                    IP_ADDR_STRING IpAddressList, GatewayList, DhcpServer;

                                    BOOL HaveWins;

                                    IP_ADDR_STRING PrimaryWinsServer, SecondaryWinsServer;

                                    time_t LeaseObtained, LeaseExpires;

                        }>

 

DWORD

         <C: typedef unsigned long DWORD>

 

 

 

 

-----Original Message-----
From: Gautier Dhordain [mailto:[hidden email]]
Sent:
21 March 2007 12:12 a.m.
To: [hidden email]; [hidden email]
Cc: [hidden email]
Subject: RE: networking with smalltalk

 

Hi Stewart,
 
With the help of Ralf, I have worked on your problem.
I have created an ExternalInterface subclass (IPHelper in my example) which used iphlpapi.dll as a library file.
 
Here is your modified method:
 
getMacAddresses
 
        | pAdapterInfo pOutBufLen status answer |
 
        pAdapterInfo := self IP_ADAPTER_INFO gcMalloc: 16. 
        pOutBufLen := self ULONG gcMalloc: 1.
        pOutBufLen at: 0 put: self IP_ADAPTER_INFO sizeof * 16.
 
        status := 
               self 
                       GetAdaptersInfo: pAdapterInfo
                       with: pOutBufLen.
 
        status = 0 
               ifFalse: [^nil].
 
        answer := OrderedCollection new
               add: (OrderedCollection new
                               add: ((0 to: 5) collect: [:i | 
                                              ((pAdapterInfo memberAt: #Address) at: i) printStringRadix: 16]));
               yourself.
 
        [(pAdapterInfo := (pAdapterInfo memberAt: #Next)) isValid]
        whileTrue:
               [answer add: 
                       (OrderedCollection new
                               add: ((0 to: 5) collect: [:i | 
                                              ((pAdapterInfo memberAt: #Address) at: i) printStringRadix: 16]))].
 
        ^answer
 
It will return to you an ordered collection which contains an ordered collection for each MAC address it has found.
I hope it can help you.
 
Gautier
Reply | Threaded
Open this post in threaded view
|

VisualWorks Applications for iPad and android?

bernhardHoefner
In reply to this post by Stew MacLean
Hello usegroup,
is it possible to run VisualWorks-applications on iPad or Android?

thanks for answer,
Bernhard Hoefner

Am 20.03.2007 23:10, schrieb Stewart MacLean:

Hi Gautier and Ralf,

 

Thank you very much for helping me with this – I need all the help I can get here!

 

I have realised why my previous attempts where failing on loading the library – I was using iphlpapi.lib which is static, not dynamic (duh!).

 

I’ve then found the iphlpapi.dll on my system and have copied it to the working directory. I couldn’t find a ULONG method so I’ve used DWORD, which I think has the same effect.

 

So now, I’m getting a

 

-self:  a SystemError(#'unsupported operation',nil)

parameter:  nil

name:  #'unsupported operation'

 

using

 

GetAdaptersInfo: pAdapterInfo with: pOutBufLen

            <C: DWORD GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)>

            ^self externalAccessFailedWith: _errorCode

 

with arguments:

 

 

-bytes:  #[120 1 50 0 120 1 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 2 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0...etc...]

Next:  a CCompositePointer {00320178} (struct _IP_ADAPTER_INFO * )

ComboIndex:  3277176

AdapterName:  a CPointer {00E97618} (char * )

Description:  a CPointer {00E9771C} (char * )

AddressLength:  a CPointer {invalid} (UINT)

Address:  a CPointer {00E977A4} (void * * )

Index:  543

Type:  a CPointer {00000371} (UINT)

DhcpEnabled:  a CPointer {0000020A} (UINT)

CurrentIpAddress:  a CCompositePointer {00000386} (PIP_ADDR_STRING)

IpAddressList:  a CComposite (struct _IP_ADDR_STRING)

GatewayList:  a CComposite (struct _IP_ADDR_STRING)

DhcpServer:  a CComposite (struct _IP_ADDR_STRING)

HaveWins:  a CPointer {invalid} (BOOL)

PrimaryWinsServer:  a CComposite (struct _IP_ADDR_STRING)

SecondaryWinsServer:  a CComposite (struct _IP_ADDR_STRING)

LeaseObtained:  a CPointer {00000130} (time_t)

LeaseExpires:  a CPointer {0000001E} (time_t)

 

And:

 

-self:  a CPointer {0032F868} (unsigned long * )

theDatum:  3340392

type:  unsigned long *

 

(self at: 0) 10624

 

So it’s found the library ok, it’s found the entry point ok (I’ve also check the library using pedump within the lcc compiler (I’ve now got one!)).

 

In the docs, it says

 

#'unsupported

operation'

nil

 

 An operation unsupported on the

current platform has been

attempted (e.g. calling a _wincall

error convention function call on

a non-Windows platform).

 

Completely speculating, my guess is that the format of my procedure call is maybe wrong? This method was generated by the library builder. Or maybe I have the wrong structure for the info?

 

Any help greatly appreciated,

 

Thanks,

 

Stewart

 

_IP_ADAPTER_INFO

            <C: struct _IP_ADAPTER_INFO {

                                    struct _IP_ADAPTER_INFO * Next;

                                    DWORD ComboIndex;

                                    char AdapterName[260];

                                    char Description[132];

                                    UINT AddressLength;

                                    BYTE Address[8];

                                    DWORD Index;

                                    UINT Type, DhcpEnabled;

                                    PIP_ADDR_STRING CurrentIpAddress;

                                    IP_ADDR_STRING IpAddressList, GatewayList, DhcpServer;

                                    BOOL HaveWins;

                                    IP_ADDR_STRING PrimaryWinsServer, SecondaryWinsServer;

                                    time_t LeaseObtained, LeaseExpires;

                        }>

 

DWORD

         <C: typedef unsigned long DWORD>

 

 

 

 

-----Original Message-----
From: Gautier Dhordain [[hidden email]]
Sent: 21 March 2007 12:12 a.m.
To: [hidden email]; [hidden email]
Cc: [hidden email]
Subject: RE: networking with smalltalk

 

Hi Stewart,
 
With the help of Ralf, I have worked on your problem.
I have created an ExternalInterface subclass (IPHelper in my example) which used iphlpapi.dll as a library file.
 
Here is your modified method:
 
getMacAddresses
 
        | pAdapterInfo pOutBufLen status answer |
 
        pAdapterInfo := self IP_ADAPTER_INFO gcMalloc: 16. 
        pOutBufLen := self ULONG gcMalloc: 1.
        pOutBufLen at: 0 put: self IP_ADAPTER_INFO sizeof * 16.
 
        status := 
               self 
                       GetAdaptersInfo: pAdapterInfo
                       with: pOutBufLen.
 
        status = 0 
               ifFalse: [^nil].
 
        answer := OrderedCollection new
               add: (OrderedCollection new
                               add: ((0 to: 5) collect: [:i | 
                                              ((pAdapterInfo memberAt: #Address) at: i) printStringRadix: 16]));
               yourself.
 
        [(pAdapterInfo := (pAdapterInfo memberAt: #Next)) isValid]
        whileTrue:
               [answer add: 
                       (OrderedCollection new
                               add: ((0 to: 5) collect: [:i | 
                                              ((pAdapterInfo memberAt: #Address) at: i) printStringRadix: 16]))].
 
        ^answer
 
It will return to you an ordered collection which contains an ordered collection for each MAC address it has found.
I hope it can help you.
 
Gautier


No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.16/729 - Release Date: 21.03.2007 07:52


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: VisualWorks Applications for iPad and android?

Georg Heeg

Bernhard,

 

In the recent months we added mobile support to seaBreeze. This might not be exactly what you are looking for, but at least it’s close.

 

This solution is based upon JQueryMobile and uses the technology which was presented at ESUG 2012 in Gent. We combined it with the editor capabilities of seaBreeze.

 

The typical kind of application is an online system which requires Internet access of your mobile device anyway.

 

We plan to ship it as a Heeg Contribution with VisualWorks 7.10. Currently we are in the process of writing the documentation. It does not ship yet with VisualWorks 7.10 prereleases, but we plan that step shortly. By the way this new version will also support multi language support including Internationalization and Localization.

 

If you can’t wait, please do not hesitate to contact me

 

Georg Heeg

 

Georg Heeg eK, Dortmund und Köthen, HR Dortmund A 12812

Wallstraße 22, 06366 Köthen

Tel. +49-3496-214328, Fax +49-3496-214712

 

Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Bernhard Hoefner
Gesendet: Mittwoch, 6. Februar 2013 21:36
An: [hidden email]
Betreff: [vwnc] VisualWorks Applications for iPad and android?

 

Hello usegroup,
is it possible to run VisualWorks-applications on iPad or Android?

thanks for answer,
Bernhard Hoefner

 


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: VisualWorks Applications for iPad and android?

Thomas, Arden
In reply to this post by bernhardHoefner
Hi Bernhard;

VisualWorks and ObjectStudio can be used to host web applications which can run on mobile platforms like the iPad, iPhone, and Android devices.

Currently we do not run natively on them, but product management frequently reviews this status.

Regards

Arden Thomas

On Feb 6, 2013, at 3:36 PM, Bernhard Hoefner wrote:

Hello usegroup,
is it possible to run VisualWorks-applications on iPad or Android?

thanks for answer,
Bernhard Hoefner



Arden Thomas
Cincom Smalltalk Product Manager
845 296 0686

Cincom Smalltalk - It makes hard things easier, the impossible, possible

"Simplicity is the Ultimate Sophistication" - Leonardo Da Vinci


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: VisualWorks Applications for iPad and android?

Maarten Mostert

Dear Arden,

 

Taken the huge adaption of these devises they better:

 

http://www.splatf.com/2013/01/peak-mac/

 

Regards,

 

Maarten,

 

-----Original Message-----
From: "Arden Thomas" <[hidden email]>
Sent: Thursday, 7 February, 2013 14:37
To: "Bernhard Hoefner" <[hidden email]>
Cc: [hidden email]
Subject: Re: [vwnc] VisualWorks Applications for iPad and android?

Hi Bernhard;
VisualWorks and ObjectStudio can be used to host web applications which can run on mobile platforms like the iPad, iPhone, and Android devices.
Currently we do not run natively on them, but product management frequently reviews this status.
Regards
Arden Thomas

On Feb 6, 2013, at 3:36 PM, Bernhard Hoefner wrote:

Hello usegroup,
is it possible to run VisualWorks-applications on iPad or Android?

thanks for answer,
Bernhard Hoefner


Arden Thomas
Cincom Smalltalk Product Manager
845 296 0686
Cincom Smalltalk - It makes hard things easier, the impossible, possible
"Simplicity is the Ultimate Sophistication" - Leonardo Da Vinci

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Seabreeze

Maarten Mostert-2
In reply to this post by Georg Heeg
Hi,

I have been trying to find a VW combination for which Seabreeze actually works without hitting exception after exception whenever I try to use the application wizard.

I tried 7.8, 7.9.1 and 7.10.1 without success so far.

Regards,

Maarten,


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
12