+int
+wxDialUpManagerImpl::CheckProcNet()
+{
+ // assume that the test doesn't work
+ int netDevice = NetDevice_Unknown;
+
+#ifdef __LINUX__
+ if (wxFileExists(wxT("/proc/net/route")))
+ {
+ // cannot use wxFile::Length because file doesn't support seeking, so
+ // use stdio directly
+ FILE *f = fopen("/proc/net/route", "rt");
+ if (f != NULL)
+ {
+ // now we know that we will find all devices we may have
+ netDevice = NetDevice_None;
+
+ char output[256];
+
+ while (fgets(output, 256, f) != NULL)
+ {
+ // Test for the known network interface names
+ if ( strstr(output, "eth")
+ || strstr(output, "wlan")
+ || strstr(output, "ath") )
+ {
+ netDevice |= NetDevice_LAN;
+ }
+ else if (strstr(output,"ppp") // ppp
+ || strstr(output,"sl") // slip
+ || strstr(output,"pl")) // plip
+ {
+ netDevice |= NetDevice_Modem;
+ }
+ }
+
+ fclose(f);
+ }
+ }
+#endif // __LINUX__
+
+ return netDevice;
+}
+
+
+int
+wxDialUpManagerImpl::CheckIfconfig()
+{
+#ifdef __VMS
+ m_CanUseIfconfig = 0;
+ return -1;
+#else
+ // assume that the test doesn't work
+ int netDevice = NetDevice_Unknown;
+
+ // first time check for ifconfig location
+ if ( m_CanUseIfconfig == -1 ) // unknown
+ {
+ static const wxChar *const ifconfigLocations[] =
+ {
+ wxT("/sbin"), // Linux, FreeBSD, Darwin
+ wxT("/usr/sbin"), // SunOS, Solaris, AIX, HP-UX
+ wxT("/usr/etc"), // IRIX
+ wxT("/etc"), // AIX 5
+ };
+
+ for ( size_t n = 0; n < WXSIZEOF(ifconfigLocations); n++ )
+ {
+ wxString path(ifconfigLocations[n]);
+ path << wxT("/ifconfig");
+
+ if ( wxFileExists(path) )
+ {
+ m_IfconfigPath = path;
+ break;
+ }
+ }
+ }
+
+ if ( m_CanUseIfconfig != 0 ) // unknown or yes
+ {
+ wxLogNull ln; // suppress all error messages
+
+ wxASSERT_MSG( !m_IfconfigPath.empty(),
+ wxT("can't use ifconfig if it wasn't found") );
+
+ wxString tmpfile = wxFileName::CreateTempFileName( wxT("_wxdialuptest") );
+ wxString cmd = wxT("/bin/sh -c \'");
+ cmd << m_IfconfigPath;
+#if defined(__AIX__) || \
+ defined(__NETBSD__) || \
+ defined(__OSF__) || \
+ defined(__SOLARIS__) || defined (__SUNOS__)
+ // need to add -a flag
+ cmd << wxT(" -a");
+#elif defined(__LINUX__) || defined(__SGI__) || defined(__OPENBSD__)
+ // nothing to be added to ifconfig
+#elif defined(__FREEBSD__) || defined(__DARWIN__) || defined(__QNX__)
+ // add -l flag
+ cmd << wxT(" -l");
+#elif defined(__HPUX__)
+ // VZ: a wild guess (but without it, ifconfig fails completely)
+ cmd << wxT(" ppp0");
+#else
+ #if defined(__GNUG__)
+ #warning "No ifconfig information for this OS."
+ #else
+ #pragma warning "No ifconfig information for this OS."
+ #endif
+
+ m_CanUseIfconfig = 0;
+ return -1;
+#endif
+ cmd << wxT(" >") << tmpfile << wxT('\'');
+ /* I tried to add an option to wxExecute() to not close stdout,
+ so we could let ifconfig write directly to the tmpfile, but
+ this does not work. That should be faster, as it doesn't call
+ the shell first. I have no idea why. :-( (KB) */
+ if ( wxExecute(cmd,true /* sync */) == 0 )
+ {
+ m_CanUseIfconfig = 1;
+ wxFFile file;
+ if( file.Open(tmpfile) )
+ {
+ wxString output;
+ if ( file.ReadAll(&output) )
+ {
+ // FIXME shouldn't we grep for "^ppp"? (VZ)
+
+ bool hasModem = false,
+ hasLAN = false;
+
+#if defined(__SOLARIS__) || defined (__SUNOS__)
+ // dialup device under SunOS/Solaris
+ hasModem = strstr(output.fn_str(),"ipdptp") != NULL;
+ hasLAN = strstr(output.fn_str(), "hme") != NULL;
+#elif defined(__LINUX__) || defined (__FREEBSD__) || defined (__QNX__) || \
+ defined(__OPENBSD__)
+ hasModem = strstr(output.fn_str(),"ppp") // ppp
+ || strstr(output.fn_str(),"sl") // slip
+ || strstr(output.fn_str(),"pl"); // plip
+ hasLAN = strstr(output.fn_str(), "eth") != NULL;
+#elif defined(__SGI__) // IRIX
+ hasModem = strstr(output.fn_str(), "ppp") != NULL; // PPP
+#elif defined(__HPUX__)
+ // if could run ifconfig on interface, then it exists
+ hasModem = true;
+#endif
+
+ netDevice = NetDevice_None;
+ if ( hasModem )
+ netDevice |= NetDevice_Modem;
+ if ( hasLAN )
+ netDevice |= NetDevice_LAN;
+ }
+ //else: error reading the file
+ }
+ //else: error opening the file
+ }
+ else // could not run ifconfig correctly
+ {
+ m_CanUseIfconfig = 0; // don't try again
+ }
+
+ (void) wxRemoveFile(tmpfile);
+ }
+
+ return netDevice;
+#endif
+}
+
+wxDialUpManagerImpl::NetConnection wxDialUpManagerImpl::CheckPing()
+{
+ // First time check for ping location. We only use the variant
+ // which does not take arguments, a la GNU.
+ if(m_CanUsePing == -1) // unknown
+ {
+#ifdef __VMS
+ if (wxFileExists( wxT("SYS$SYSTEM:TCPIP$PING.EXE") ))
+ m_PingPath = wxT("$SYS$SYSTEM:TCPIP$PING");
+#elif defined(__AIX__)
+ m_PingPath = wxT("/etc/ping");
+#elif defined(__SGI__)
+ m_PingPath = wxT("/usr/etc/ping");
+#else
+ if (wxFileExists( wxT("/bin/ping") ))
+ m_PingPath = wxT("/bin/ping");
+ else if (wxFileExists( wxT("/usr/sbin/ping") ))
+ m_PingPath = wxT("/usr/sbin/ping");
+#endif
+ if (!m_PingPath)
+ {
+ m_CanUsePing = 0;
+ }
+ }
+
+ if(! m_CanUsePing)
+ {
+ // we didn't find ping
+ return Net_Unknown;
+ }
+
+ wxLogNull ln; // suppress all error messages
+ wxASSERT(m_PingPath.length());
+ wxString cmd;
+ cmd << m_PingPath << wxT(' ');
+#if defined(__SOLARIS__) || defined (__SUNOS__)
+ // nothing to add to ping command
+#elif defined(__AIX__) || \
+ defined (__BSD__) || \
+ defined(__LINUX__) || \
+ defined(__OSF__) || \
+ defined(__SGI__) || \
+ defined(__VMS) || \
+ defined(__QNX__)
+ cmd << wxT("-c 1 "); // only ping once
+#elif defined(__HPUX__)
+ cmd << wxT("64 1 "); // only ping once (need also specify the packet size)
+#else
+ #if defined(__GNUG__)
+ #warning "No Ping information for this OS."
+ #else
+ #pragma warning "No Ping information for this OS."
+ #endif
+
+ m_CanUsePing = 0;
+ return Net_Unknown;
+#endif
+ cmd << m_BeaconHost;
+ if(wxExecute(cmd, true /* sync */) == 0)
+ return Net_Connected;
+ else
+ return Net_No;
+}
+