Logged in as Guest   Sun, Oct. 21st, 7:43 AM.      
 
 
Web hazelware.luggle.com
 

Follow On Article About Retrieving Assigned IP Addresses
In a previous post about inspecting network connection settings on the PalmOS, I presented one piece of very incorrect/misleading information of particular interest to developers working on networked applications. I presented a code snippet to retrieve the assigned IP address when connecting via DHCP to a server. (Giving credit where credit is due, my error was very kindly pointed out to me by Henk Jonas.)
In my previous article, the snippet showed that you could retrieve the assigned IP address simply by querying the netIFSettingActualIPAddr using NetLibSettingGet(). In fact, the problem is slightly more complicated. The method that Henk pointed me to is implemented by looping through the NetLib interfaces after a connection has been established. While looping through the interfaces, you must look for the ones that are up and that are not the loopback interface. Once you have found an interface that is up, only then can you query netIFSettingActualIPAddr using NetLibIFSettingGet().
Here is one way to implement this:
UInt16 index = 0;
Err err = errNone;
while (err == errNone)
{
    UInt16 idx;
    UInt32 creatorID;
    UInt16 instance;
	
    //Retrieve the creator ID and instance of the indexed Interface
    err = NetLibIFGet(netLibRefNum, index, &creatorID, &instance);
    if (err == errNone)
    {
        //Check to see if the interface is up
        UInt8 isUp = false;
        UInt16 size = sizeof(isUp);
        NetLibIFSettingGet(netLibRefNum, 
                           creatorID, 
                           instance, 
                           netIFSettingUp,
                           &isUp,
                           &size);
			
        //Make sure the interface is up and is not the 
        //loopback interface
        if (isUp && creatorID != 'loop')
        {
            //Once we get here, it's simply a matter of 
            //grabbing the IP address
            UInt32 address;
            size = sizeof(address);
            NetLibIFSettingGet(netLibRefNum, 
                               creatorID, 
                               instance,
                               netIFSettingActualIPAddr, 
                               &address, 
                               &size);

            //Once you get here, you have to do something 
            //with the IP address.  Do you just get the 
            //first one and stop, or do you want all the
            //assigned IP addresses of Up Interfaces?  
            //That determines whether or not you want to 
            //break out of this loop.  I leave that as an
            //exercise for the reader.  -Jon
        }
     
        //Go on to the next Interface
        index++;
    }
} 

As always, I hope this helps you in your endeavors, and if you feel like it, I'd love to hear about it!

-Jon
Submitted by bosshogg on Wednesday the 31st 1970f December 1969, at 04:00

 
Recent Entries:
I'm BACK!!!!!!
Code Monkey
Cool 3D Code Snippet From My Former Life
YouTube: The Revival of the Internet Time Killer
WhereMate Released
Palmasaurus Released As Freeware
VM-Plus Beta
Handspring Undocumented APIs
Posting Malaise
PhoneShield Released!!!

Archive:
October - 2007
August - 2007
July - 2007
June - 2007
May - 2007
April - 2007
December - 2006
November - 2006
September - 2006
August - 2006
July - 2006
March - 2006
February - 2006
January - 2006
December - 2005
November - 2005
October - 2005
September - 2005
August - 2005
July - 2005
June - 2005
May - 2005
April - 2005
February - 2005
January - 2005
December - 2004
November - 2004
October - 2004
September - 2004
August - 2004
July - 2004
June - 2004
May - 2004
April - 2004
March - 2004