> I'm trying to detect a network connection without changing 
> the state of the
> network.  For example, my application sets an alarm when the 
> network is
> activated, and when the alarm goes off, my app wants to see 
> if the network
> is open, without actually opening the network if it is 
> closed.  This seems
> to be a much more difficult proposition than I first expected.
> <snip>

After I had posted this question to the list, someone suggested I try using
NetLibMaster to query the various interfaces and see if that worked.  In a
nutshell, it does.  I dug around in the example code with the 4.0 SDK and
looked at how the NetSample app uses NetLibIFGet and NetLibIFSettingGet in
CmdOpen() in CmdSetup.c.  I wrote a

Boolean NetworkIsUp (void);

function using NetLibIFGet and NetLibIFSettingGet, but I was able to get the
same basic functionality in a more straightforward fashion by using 

error = NetLibMaster (AppNetRefnum, netMasterInterfaceInfo, &pb, 0);

I set pb.param.interfaceInfo.index to 0 (to check the first interface of
NetLib) and then I checked to make sure that pb.param.interfaceInfo.driverUp
and pb.param.interfaceInfo.ifUp are true.  That seems to be working.  The
only other trick, is that NetLib must have an open count > 0 for
NetLibMaster to work.

So on the sysNotifyNetLibIFMediaEvent my code calls NetLibOpen to guarantee
that NetLib will be open, then at any time, I can use NetLibMaster to check
to see if the interfaces are actually up, which means there is a valid and
open network connection.

Any comments on this are welcomed.  I've been working on this in somewhat of
a vacuum, and while I don't like having to call NetLibOpen from my app, I've
been unable to uncover an alternate method for working with NetLib.  I'd
love to hear any suggestions others may have.

Cheers,

-DGA

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to