- m_IsOnline = -1;
-
- int testResult;
-
- testResult = CheckProcNet();
- if(testResult == -1)
- testResult = CheckIfconfig();
- if(testResult == -1)
- testResult = CheckConnect();
- if(testResult == -1)
- testResult = CheckPing();
- m_IsOnline = testResult;
+ m_IsOnline = Net_Unknown;
+
+ // first do quick checks to determine what kind of network devices do we
+ // have
+ int netDeviceType = CheckProcNet();
+ if ( netDeviceType == NetDevice_Unknown )
+ {
+ // nothing found, try ifconfig too
+ netDeviceType = CheckIfconfig();
+ }
+
+ switch ( netDeviceType )
+ {
+ case NetDevice_None:
+ // no network devices, no connection
+ m_IsOnline = Net_No;
+ break;
+
+ case NetDevice_LAN:
+ // we still do ping to confirm that we're connected but we only do
+ // it once and hope that the purpose of the network card (i.e.
+ // whether it used for connecting to the Internet or just to a
+ // LAN) won't change during the program lifetime
+ if ( m_connCard == Net_Unknown )
+ {
+ m_connCard = CheckConnectAndPing();
+ }
+ m_IsOnline = m_connCard;
+ break;
+
+ case NetDevice_Unknown:
+ // try to ping just in case
+ m_IsOnline = CheckConnectAndPing();
+ break;
+
+ case NetDevice_LAN + NetDevice_Modem:
+ case NetDevice_Modem:
+ // assume we're connected
+ m_IsOnline = Net_Connected;
+ break;
+
+ default:
+ wxFAIL_MSG(_T("Unexpected netDeviceType"));
+ }