Hi all,

Here is some info on working with the NetLib library in combination
with the emulator and the real device. My application has to register
it's IP ( and preferably it's full domain/hostname ) with a lookup
service. I therefor have to find out what my ip address is. This task
has taken me a long time even though the entire communications 
module was up and running already. Here is what I found:

Pose/Emulator does not seem to be able to retrieve the network info
from windows95/98 ( on a PPP connection ) to fill in the fields 
necessary to find out information about the active interfaces. Here 
is what I did to test this. The attached textfile 'function1.txt' 
illustrates a way to find out the IP address of all running interfaces. 
When a PalmIIIx or a PalmV connects to a PPP server, the following text 
boxes would appear, generated by function1:

-------------------------------------------------------------------------

+ Interface 0

Name PPP0

netIFSettingReqIPAddr
0.0.0.0

netIFSettingDynamicIP
1.0.0.0

netIFSettingActualIPAddr
128.2.188.142

+ Interface 1

Name loop

netIFSettingReqIPAddr
127.0.0.1

Error: Unknown Setting

netIFSettingActualIPAddr
127.0.0.1

- Interface 2

Error: Interface not found

-------------------------------------------------------------------------

When the same application is run under Pose, 4 network interfaces
are found and all of them will generate the netErrPrefNotFound 
"Preference not found" error.

Two other things came up while working with the NetLib functions. The
documentation and the palm-gcc sources are not in sync. For example:
the identifier netIFSettingIPAddr as mentioned in the documentation is
netIFSettingReqIPAddr in reality. Something similar goes for the
function NetLibIFGet. When this function is called for a number of
interfaces, it should return a netErrInvalidInterface according to 
the documentation. In reality it returns: netErrInterfaceNotFound

Attached to this email is a function called GetIpAddr, this function
will determen what your active IP address is from a PPP connection.
( you will have to have done a NetLibOpen and such of course )

Martin

+----------------------------+---------------------------------------+
|      Martin van Velsen,    | Robotics Institute (RI,CIMDS),        |
| email: [EMAIL PROTECTED] | Carnegie Mellon University            |
|       [EMAIL PROTECTED] | www: http://kip.sateh.com/~martin     |
|        [EMAIL PROTECTED] |      http://www.sis.pitt.edu/~vvelsen |
+----------------------------+---------------------------------------+
/*------------------------------------------------------------------------------------*/
SWord GetIpAddrDiagnostics (CharPtr an_addr, int len)
{
 int   found  =0;
 int   index  =0;
        Err                     err1   =0;
 Err                    err2   =0;
        Word            bufLen =len;    
 DWord Creator;
 Word  Instance;
 DWord ipaddr =0;

 do 
 {  
   err1=NetLibIFGet (AppNetRefnum,index,&Creator,&Instance);

   if (err1==0)
   {
     found=1;

     StrPrintF      (errStr,"+ Interface %d",index);    
     FrmCustomAlert (ID_fGeneralAlert,errStr,NULL,NULL);        

     // first get the name
     err2 = NetLibIFSettingGet 
(AppNetRefnum,Creator,Instance,netIFSettingName,an_addr,&bufLen);
     if (err2==0)
     {
       StrPrintF      (errStr,"Name %s",an_addr);       
       FrmCustomAlert (ID_fGeneralAlert,errStr,NULL,NULL);        

              // Get the appropriate preference in the Net Library
              bufLen=len;       

       
//>------------------------------------------------------------------------------------------------

       err2=NetLibIFSettingGet 
(AppNetRefnum,Creator,Instance,netIFSettingReqIPAddr,&ipaddr,&bufLen);

       if (err2!=0)
       {
        ShowError (err2);        
       }
       else
       {
        StrPrintF      (errStr,"netIFSettingReqIPAddr\n %s",NetLibAddrINToA 
(AppNetRefnum,ipaddr,an_addr));     
        FrmCustomAlert (ID_fGeneralAlert,errStr,NULL,NULL);        
       }

       
//>------------------------------------------------------------------------------------------------

       err2 = NetLibIFSettingGet 
(AppNetRefnum,Creator,Instance,netIFSettingDynamicIP,&ipaddr,&bufLen);

       if (err2!=0)
       {
        ShowError (err2);        
       }
       else
       {
        StrPrintF      (errStr,"netIFSettingDynamicIP\n %s",NetLibAddrINToA 
(AppNetRefnum,ipaddr,an_addr));     
        FrmCustomAlert (ID_fGeneralAlert,errStr,NULL,NULL);        
       }

       
//>------------------------------------------------------------------------------------------------
    

              err2 = NetLibIFSettingGet 
(AppNetRefnum,Creator,Instance,netIFSettingActualIPAddr,&ipaddr,&bufLen);
      
       if (err2!=0)
       {
        ShowError (err2);        
       }
       else
       {
        StrPrintF      (errStr,"netIFSettingActualIPAddr\n %s",NetLibAddrINToA 
(AppNetRefnum,ipaddr,an_addr));  
        FrmCustomAlert (ID_fGeneralAlert,errStr,NULL,NULL);        
       }

      }
      else
       FrmCustomAlert (ID_fGeneralAlert,"Unable to find basic info",NULL,NULL);
   }
   else
   {
     StrPrintF      (errStr,"- Interface %d",index);    
     FrmCustomAlert (ID_fGeneralAlert,errStr,NULL,NULL);        
     ShowError (err1);
   }
   
   index++;   
 } while ((err1!=netErrInterfaceNotFound) && (index<10) && 
(err1!=netErrInvalidInterface));

 return (0);
}
/*------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------------*/
SWord GetIpAddr (CharPtr an_addr, int len)
{
 int   index  =0;
        Err                     err1   =0;
 Err                    err2   =0;
 DWord ipaddr =0;
        Word            bufLen =len;    
 DWord Creator;
 Word  Instance;

 do 
 {  
   err1=NetLibIFGet (AppNetRefnum,index,&Creator,&Instance);

   if (err1==0)
   {
     // first get the name
     err2 = NetLibIFSettingGet 
(AppNetRefnum,Creator,Instance,netIFSettingName,an_addr,&bufLen);
     if (err2==0)
     {
       if ((StrStr (an_addr,"ppp0")==0) || (StrStr (an_addr,"PPP0")==0))
       {
              // Get the appropriate preference in the Net Library
              bufLen=len;       

              err2 = NetLibIFSettingGet 
(AppNetRefnum,Creator,Instance,netIFSettingActualIPAddr,&ipaddr,&bufLen);
      
       if (err2!=0)
       {
        ShowError (err2);        
       }
       else
       {
        StrPrintF      (errStr,"IPAddr\n %s",NetLibAddrINToA 
(AppNetRefnum,ipaddr,an_addr));    
        FrmCustomAlert (ID_fGeneralAlert,errStr,NULL,NULL);        
       }        
      }
     }
   }
   
   index++;   
 } while ((err1!=netErrInterfaceNotFound) && (index<10) && 
(err1!=netErrInvalidInterface));

 return (0);
}
/*------------------------------------------------------------------------------------*/

Reply via email to