- wxASSERT(m_IfconfigPath.length());
-
- wxString tmpfile = wxGetTempFileName("_wxdialuptest");
- wxString cmd = "/bin/sh -c \'";
- cmd << m_IfconfigPath << " >" << tmpfile << '\'';
- /* 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 0
- // temporarily redirect stdout/stderr:
- int
- new_stdout = dup(STDOUT_FILENO),
- new_stderr = dup(STDERR_FILENO);
- close(STDOUT_FILENO);
- close(STDERR_FILENO);
-
- int
- // new stdout:
- output_fd = open(tmpfile, O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR),
- // new stderr:
- null_fd = open("/dev/null", O_CREAT, S_IRUSR|S_IWUSR);
- // verify well behaved unix behaviour:
- wxASSERT(output_fd == STDOUT_FILENO);
- wxASSERT(null_fd == STDERR_FILENO);
- int rc = wxExecute(m_IfconfigPath,TRUE /* sync */,NULL ,wxEXECUTE_DONT_CLOSE_FDS);
- close(null_fd); close(output_fd);
- // restore old stdout, stderr:
- int test;
- test = dup(new_stdout); close(new_stdout); wxASSERT(test == STDOUT_FILENO);
- test = dup(new_stderr); close(new_stderr); wxASSERT(test == STDERR_FILENO);
- if(rc == 0)
+ close(sockfd);
+ return Net_Connected; // we can connect, so we have a network!
+ }
+ else // failed to connect
+ {
+ if(errno == ENETUNREACH)
+ return Net_No; // network is unreachable
+ else
+ return Net_Unknown; // connect failed, but don't know why
+ }
+}
+
+
+int
+wxDialUpManagerImpl::CheckProcNet()
+{
+ // assume that the test doesn't work
+ int netDevice = NetDevice_Unknown;
+
+#ifdef __LINUX__
+ if (wxFileExists(_T("/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)
+ {
+ if ( strstr(output, "eth") ) // network card
+ {
+ 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()
+{
+ // 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 *ifconfigLocations[] =
+ {
+ _T("/sbin"), // Linux, FreeBSD
+ _T("/usr/sbin"), // SunOS, Solaris, AIX, HP-UX
+ _T("/usr/etc"), // IRIX
+ };
+
+ for ( size_t n = 0; n < WXSIZEOF(ifconfigLocations); n++ )
+ {
+ wxString path(ifconfigLocations[n]);
+ path << _T("/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.length(),
+ _T("can't use ifconfig if it wasn't found") );
+
+ wxString tmpfile = wxGetTempFileName("_wxdialuptest");
+ wxString cmd = "/bin/sh -c \'";
+ cmd << m_IfconfigPath;
+#if defined(__SOLARIS__) || defined (__SUNOS__)
+ // need to add -a flag
+ cmd << " -a";
+#elif defined(__LINUX__) || defined(__SGI__)
+ // nothing to be added to ifconfig
+#elif defined(__FREEBSD__)
+ // add -l flag
+ cmd << " -l";
+#elif defined(__HPUX__)
+ // VZ: a wild guess (but without it, ifconfig fails completely)
+ cmd << _T(" ppp0");
+#else
+# pragma warning "No ifconfig information for this OS."
+ m_CanUseIfconfig = 0;
+ return -1;