]> git.saurik.com Git - wxWidgets.git/blob - src/unix/dialup.cpp
remove wxBase files to get rid of RPM's complains about unpackaged files
[wxWidgets.git] / src / unix / dialup.cpp
1 // -*- c++ -*- ////////////////////////////////////////////////////////////////
2 // Name: unix/dialup.cpp
3 // Purpose: Network related wxWindows classes and functions
4 // Author: Karsten Ballüder
5 // Modified by:
6 // Created: 03.10.99
7 // RCS-ID: $Id$
8 // Copyright: (c) Karsten Ballüder
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 # pragma implementation "dialup.h"
14 #endif
15
16 // for compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #include "wx/setup.h"
20
21 #if wxUSE_DIALUP_MANAGER
22
23 #ifndef WX_PRECOMP
24 # include "wx/defs.h"
25 #endif // !PCH
26
27 #include "wx/string.h"
28 #include "wx/event.h"
29 #include "wx/dialup.h"
30 #include "wx/timer.h"
31 #include "wx/filefn.h"
32 #include "wx/utils.h"
33 #include "wx/log.h"
34 #include "wx/ffile.h"
35 #include "wx/process.h"
36 #include "wx/intl.h"
37 #include "wx/app.h"
38 #include "wx/wxchar.h"
39
40 #include <stdlib.h>
41
42 #include <signal.h>
43 #include <fcntl.h>
44 #include <unistd.h>
45 #define __STRICT_ANSI__
46 #include <sys/socket.h>
47 #include <netdb.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
50 #include <errno.h>
51
52 DEFINE_EVENT_TYPE(wxEVT_DIALUP_CONNECTED)
53 DEFINE_EVENT_TYPE(wxEVT_DIALUP_DISCONNECTED)
54
55 // ----------------------------------------------------------------------------
56 // A class which groups functions dealing with connecting to the network from a
57 // workstation using dial-up access to the net. There is at most one instance
58 // of this class in the program accessed via GetDialUpManager().
59 // ----------------------------------------------------------------------------
60
61 /* TODO
62 *
63 * 1. more configurability for Unix: i.e. how to initiate the connection, how
64 * to check for online status, &c.
65 * 2. add a "long Dial(long connectionId = -1)" function which asks the user
66 * about which connection to dial (this may be done using native dialogs
67 * under NT, need generic dialogs for all others) and returns the identifier
68 * of the selected connection (it's opaque to the application) - it may be
69 * reused later to dial the same connection later (or use strings instead of
70 * longs may be?)
71 * 3. add an async version of dialing functions which notify the caller about
72 * the progress (or may be even start another thread to monitor it)
73 * 4. the static creation/accessor functions are not MT-safe - but is this
74 * really crucial? I think we may suppose they're always called from the
75 * main thread?
76 */
77
78 class WXDLLEXPORT wxDialUpManagerImpl : public wxDialUpManager
79 {
80 public:
81 wxDialUpManagerImpl();
82 ~wxDialUpManagerImpl();
83
84 /** Could the dialup manager be initialized correctly? If this function
85 returns FALSE, no other functions will work neither, so it's a good idea
86 to call this function and check its result before calling any other
87 wxDialUpManager methods.
88 */
89 virtual bool IsOk() const
90 { return TRUE; }
91
92 /** The simplest way to initiate a dial up: this function dials the given
93 ISP (exact meaning of the parameter depends on the platform), returns
94 TRUE on success or FALSE on failure and logs the appropriate error
95 message in the latter case.
96 @param nameOfISP optional paramater for dial program
97 @param username unused
98 @param password unused
99 */
100 virtual bool Dial(const wxString& nameOfISP,
101 const wxString& WXUNUSED(username),
102 const wxString& WXUNUSED(password),
103 bool async);
104
105 // Hang up the currently active dial up connection.
106 virtual bool HangUp();
107
108 // returns TRUE if the computer is connected to the network: under Windows,
109 // this just means that a RAS connection exists, under Unix we check that
110 // the "well-known host" (as specified by SetWellKnownHost) is reachable
111 virtual bool IsOnline() const
112 {
113 CheckStatus();
114 return m_IsOnline == Net_Connected;
115 }
116
117 // do we have a constant net connection?
118 virtual bool IsAlwaysOnline() const;
119
120 // returns TRUE if (async) dialing is in progress
121 virtual bool IsDialing() const
122 { return m_DialProcess != NULL; }
123
124 // cancel dialing the number initiated with Dial(async = TRUE)
125 // NB: this won't result in DISCONNECTED event being sent
126 virtual bool CancelDialing();
127
128 size_t GetISPNames(class wxArrayString &) const
129 { return 0; }
130
131 // sometimes the built-in logic for determining the online status may fail,
132 // so, in general, the user should be allowed to override it. This function
133 // allows to forcefully set the online status - whatever our internal
134 // algorithm may think about it.
135 virtual void SetOnlineStatus(bool isOnline = TRUE)
136 { m_IsOnline = isOnline ? Net_Connected : Net_No; }
137
138 // set misc wxDialUpManager options
139 // --------------------------------
140
141 // enable automatical checks for the connection status and sending of
142 // wxEVT_DIALUP_CONNECTED/wxEVT_DIALUP_DISCONNECTED events. The interval
143 // parameter is only for Unix where we do the check manually: under
144 // Windows, the notification about the change of connection status is
145 // instantenous.
146 //
147 // Returns FALSE if couldn't set up automatic check for online status.
148 virtual bool EnableAutoCheckOnlineStatus(size_t nSeconds);
149
150 // disable automatic check for connection status change - notice that the
151 // wxEVT_DIALUP_XXX events won't be sent any more neither.
152 virtual void DisableAutoCheckOnlineStatus();
153
154 // under Unix, the value of well-known host is used to check whether we're
155 // connected to the internet. It's unused under Windows, but this function
156 // is always safe to call. The default value is www.yahoo.com.
157 virtual void SetWellKnownHost(const wxString& hostname,
158 int portno = 80);
159 /** Sets the commands to start up the network and to hang up
160 again. Used by the Unix implementations only.
161 */
162 virtual void SetConnectCommand(const wxString &command, const wxString &hupcmd)
163 { m_ConnectCommand = command; m_HangUpCommand = hupcmd; }
164
165 //private: -- Sun CC 4.2 objects to using NetConnection enum as the return
166 // type if it is declared private
167
168 // the possible results of testing for Online() status
169 enum NetConnection
170 {
171 Net_Unknown = -1, // we couldn't learn anything
172 Net_No, // no network connection [currently]
173 Net_Connected // currently connected
174 };
175
176 // the possible net connection types
177 enum NetDeviceType
178 {
179 NetDevice_None = 0x0000, // no network devices (authoritative)
180 NetDevice_Unknown = 0x0001, // test doesn't work on this OS
181 NetDevice_Modem = 0x0002, // we have a modem
182 NetDevice_LAN = 0x0004 // a network card
183 };
184
185 private:
186 // the current status
187 NetConnection m_IsOnline;
188
189 // the connection we have with the network card
190 NetConnection m_connCard;
191
192 // Can we use ifconfig to list active devices?
193 int m_CanUseIfconfig;
194
195 // The path to ifconfig
196 wxString m_IfconfigPath;
197
198 // Can we use ping to find hosts?
199 int m_CanUsePing;
200 // The path to ping program
201 wxString m_PingPath;
202
203 // beacon host:
204 wxString m_BeaconHost;
205 // beacon host portnumber for connect:
206 int m_BeaconPort;
207
208 // command to connect to network
209 wxString m_ConnectCommand;
210 // command to hang up
211 wxString m_HangUpCommand;
212 // name of ISP
213 wxString m_ISPname;
214 // a timer for regular testing
215 class AutoCheckTimer *m_timer;
216 friend class AutoCheckTimer;
217
218 // a wxProcess for dialling in background
219 class wxDialProcess *m_DialProcess;
220 // pid of dial process
221 int m_DialPId;
222 friend class wxDialProcess;
223
224 // determine status
225 void CheckStatus(bool fromAsync = FALSE) const;
226
227 // real status check
228 void CheckStatusInternal();
229
230 // check /proc/net (Linux only) for ppp/eth interfaces, returns the bit
231 // mask of NetDeviceType constants
232 int CheckProcNet();
233
234 // check output of ifconfig command for PPP/SLIP/PLIP devices, returns the
235 // bit mask of NetDeviceType constants
236 int CheckIfconfig();
237
238 // combines the 2 possible checks for determining the connection status
239 NetConnection CheckConnectAndPing();
240
241 // pings a host
242 NetConnection CheckPing();
243
244 // check by connecting to host on given port.
245 NetConnection CheckConnect();
246 };
247
248
249 class AutoCheckTimer : public wxTimer
250 {
251 public:
252 AutoCheckTimer(wxDialUpManagerImpl *dupman)
253 {
254 m_dupman = dupman;
255 m_started = FALSE;
256 }
257
258 virtual bool Start( int millisecs = -1, bool WXUNUSED(one_shot) = FALSE )
259 { m_started = TRUE; return wxTimer::Start(millisecs, FALSE); }
260
261 virtual void Notify()
262 { wxLogTrace(wxT("Checking dial up network status.")); m_dupman->CheckStatus(); }
263
264 virtual void Stop()
265 { if ( m_started ) wxTimer::Stop(); }
266 public:
267 bool m_started;
268 wxDialUpManagerImpl *m_dupman;
269 };
270
271 class wxDialProcess : public wxProcess
272 {
273 public:
274 wxDialProcess(wxDialUpManagerImpl *dupman)
275 {
276 m_DupMan = dupman;
277 }
278 void Disconnect() { m_DupMan = NULL; }
279 virtual void OnTerminate(int WXUNUSED(pid), int WXUNUSED(status))
280 {
281 if(m_DupMan)
282 {
283 m_DupMan->m_DialProcess = NULL;
284 m_DupMan->CheckStatus(TRUE);
285 }
286 }
287 private:
288 wxDialUpManagerImpl *m_DupMan;
289 };
290
291
292 wxDialUpManagerImpl::wxDialUpManagerImpl()
293 {
294 m_IsOnline =
295 m_connCard = Net_Unknown;
296 m_DialProcess = NULL;
297 m_timer = NULL;
298 m_CanUseIfconfig = -1; // unknown
299 m_CanUsePing = -1; // unknown
300 m_BeaconHost = WXDIALUP_MANAGER_DEFAULT_BEACONHOST;
301 m_BeaconPort = 80;
302
303 #ifdef __SGI__
304 m_ConnectCommand = _T("/usr/etc/ppp");
305 #elif defined(__LINUX__)
306 // default values for Debian/GNU linux
307 m_ConnectCommand = _T("pon");
308 m_HangUpCommand = _T("poff");
309 #endif
310
311 wxChar * dial = wxGetenv(_T("WXDIALUP_DIALCMD"));
312 wxChar * hup = wxGetenv(_T("WXDIALUP_HUPCMD"));
313 SetConnectCommand(dial ? wxString(dial) : m_ConnectCommand,
314 hup ? wxString(hup) : m_HangUpCommand);
315 }
316
317 wxDialUpManagerImpl::~wxDialUpManagerImpl()
318 {
319 if(m_timer) delete m_timer;
320 if(m_DialProcess)
321 {
322 m_DialProcess->Disconnect();
323 m_DialProcess->Detach();
324 }
325 }
326
327 bool
328 wxDialUpManagerImpl::Dial(const wxString &isp,
329 const wxString & WXUNUSED(username),
330 const wxString & WXUNUSED(password),
331 bool async)
332 {
333 if(m_IsOnline == Net_Connected)
334 return FALSE;
335 m_ISPname = isp;
336 wxString cmd;
337 if(m_ConnectCommand.Find(wxT("%s")))
338 cmd.Printf(m_ConnectCommand,m_ISPname.c_str());
339 else
340 cmd = m_ConnectCommand;
341
342 if ( async )
343 {
344 m_DialProcess = new wxDialProcess(this);
345 m_DialPId = (int)wxExecute(cmd, FALSE, m_DialProcess);
346 if(m_DialPId == 0)
347 {
348 delete m_DialProcess;
349 m_DialProcess = NULL;
350 return FALSE;
351 }
352 else
353 return TRUE;
354 }
355 else
356 return wxExecute(cmd, /* sync */ TRUE) == 0;
357 }
358
359 bool wxDialUpManagerImpl::HangUp()
360 {
361 if(m_IsOnline == Net_No)
362 return FALSE;
363 if(IsDialing())
364 {
365 wxLogError(_("Already dialling ISP."));
366 return FALSE;
367 }
368 wxString cmd;
369 if(m_HangUpCommand.Find(wxT("%s")))
370 cmd.Printf(m_HangUpCommand,m_ISPname.c_str(), m_DialProcess);
371 else
372 cmd = m_HangUpCommand;
373 return wxExecute(cmd, /* sync */ TRUE) == 0;
374 }
375
376
377 bool wxDialUpManagerImpl::CancelDialing()
378 {
379 if(! IsDialing())
380 return FALSE;
381 return kill(m_DialPId, SIGTERM) > 0;
382 }
383
384 bool wxDialUpManagerImpl::EnableAutoCheckOnlineStatus(size_t nSeconds)
385 {
386 DisableAutoCheckOnlineStatus();
387 m_timer = new AutoCheckTimer(this);
388 bool rc = m_timer->Start(nSeconds*1000);
389 if(! rc)
390 {
391 delete m_timer;
392 m_timer = NULL;
393 }
394 return rc;
395 }
396
397 void wxDialUpManagerImpl::DisableAutoCheckOnlineStatus()
398 {
399 if(m_timer != NULL)
400 {
401 m_timer->Stop();
402 delete m_timer;
403 m_timer = NULL;
404 }
405 }
406
407
408 void wxDialUpManagerImpl::SetWellKnownHost(const wxString& hostname, int portno)
409 {
410 if(hostname.Length() == 0)
411 {
412 m_BeaconHost = WXDIALUP_MANAGER_DEFAULT_BEACONHOST;
413 m_BeaconPort = 80;
414 return;
415 }
416
417 // does hostname contain a port number?
418 wxString port = hostname.After(wxT(':'));
419 if(port.Length())
420 {
421 m_BeaconHost = hostname.Before(wxT(':'));
422 m_BeaconPort = wxAtoi(port);
423 }
424 else
425 {
426 m_BeaconHost = hostname;
427 m_BeaconPort = portno;
428 }
429 }
430
431
432 void wxDialUpManagerImpl::CheckStatus(bool fromAsync) const
433 {
434 // This function calls the CheckStatusInternal() helper function
435 // which is OS - specific and then sends the events.
436
437 NetConnection oldIsOnline = m_IsOnline;
438 ( /* non-const */ (wxDialUpManagerImpl *)this)->CheckStatusInternal();
439
440 // now send the events as appropriate: i.e. if the status changed and
441 // if we're in defined state
442 if(m_IsOnline != oldIsOnline
443 && m_IsOnline != Net_Unknown
444 && oldIsOnline != Net_Unknown )
445 {
446 wxDialUpEvent event(m_IsOnline == Net_Connected, ! fromAsync);
447 (void)wxTheApp->ProcessEvent(event);
448 }
449 }
450
451 /*
452 We first try to find out if ppp interface is active. If it is, we assume
453 that we're online but don't have a permanent connection (this is false if a
454 networked machine uses modem to connect to somewhere else, but we can't do
455 anything in this case anyhow).
456
457 If no ppp interface is detected, we check for eth interface. If it is
458 found, we check that we can, indeed, connect to an Internet host. The logic
459 here is that connection check should be fast enough in this case and we
460 don't want to give false positives in a (common) case of a machine on a LAN
461 which is not connected to the outside.
462
463 If we didn't find either ppp or eth interfaces, we stop here and decide
464 that we're connected. However, if couldn't check for this, we try to ping a
465 remote host just in case.
466
467 NB1: Checking for the interface presence can be done in 2 ways
468 a) reading /proc/net/dev under Linux
469 b) spawning ifconfig under any OS
470
471 The first method is faster but only works under Linux.
472
473 NB2: pinging, actually, means that we first try to connect "manually" to
474 a port on remove machine and if it fails, we run ping.
475 */
476
477 void wxDialUpManagerImpl::CheckStatusInternal()
478 {
479 m_IsOnline = Net_Unknown;
480
481 // first do quick checks to determine what kind of network devices do we
482 // have
483 int netDeviceType = CheckProcNet();
484 if ( netDeviceType == NetDevice_Unknown )
485 {
486 // nothing found, try ifconfig too
487 netDeviceType = CheckIfconfig();
488 }
489
490 switch ( netDeviceType )
491 {
492 case NetDevice_None:
493 // no network devices, no connection
494 m_IsOnline = Net_No;
495 break;
496
497 case NetDevice_LAN:
498 // we still do ping to confirm that we're connected but we only do
499 // it once and hope that the purpose of the network card (i.e.
500 // whether it used for connecting to the Internet or just to a
501 // LAN) won't change during the program lifetime
502 if ( m_connCard == Net_Unknown )
503 {
504 m_connCard = CheckConnectAndPing();
505 }
506 m_IsOnline = m_connCard;
507 break;
508
509 case NetDevice_Unknown:
510 // try to ping just in case
511 m_IsOnline = CheckConnectAndPing();
512 break;
513
514 case NetDevice_LAN + NetDevice_Modem:
515 case NetDevice_Modem:
516 // assume we're connected
517 m_IsOnline = Net_Connected;
518 break;
519
520 default:
521 wxFAIL_MSG(_T("Unexpected netDeviceType"));
522 }
523 }
524
525 bool wxDialUpManagerImpl::IsAlwaysOnline() const
526 {
527 wxDialUpManagerImpl *self = wxConstCast(this, wxDialUpManagerImpl);
528
529 int netDeviceType = self->CheckProcNet();
530 if ( netDeviceType == NetDevice_Unknown )
531 {
532 // nothing found, try ifconfig too
533 netDeviceType = self->CheckIfconfig();
534 }
535
536 if ( netDeviceType == NetDevice_Unknown )
537 {
538 // this is the only thing we can do unfortunately...
539 self->HangUp();
540 return IsOnline();
541 }
542 else
543 {
544 // we are only permanently online if we have a network card
545 return (netDeviceType & NetDevice_LAN) != 0;
546 }
547 }
548
549 wxDialUpManagerImpl::NetConnection wxDialUpManagerImpl::CheckConnectAndPing()
550 {
551 NetConnection conn;
552
553 // first try connecting - faster
554 conn = CheckConnect();
555 if ( conn == Net_Unknown )
556 {
557 // try pinging too
558 conn = CheckPing();
559 }
560
561 return conn;
562 }
563
564 wxDialUpManagerImpl::NetConnection wxDialUpManagerImpl::CheckConnect()
565 {
566 // second method: try to connect to a well known host:
567 // This can be used under Win 9x, too!
568 struct hostent *hp;
569 struct sockaddr_in serv_addr;
570
571 if((hp = gethostbyname(m_BeaconHost.mb_str())) == NULL)
572 return Net_No; // no DNS no net
573
574 serv_addr.sin_family = hp->h_addrtype;
575 memcpy(&serv_addr.sin_addr,hp->h_addr, hp->h_length);
576 serv_addr.sin_port = htons(m_BeaconPort);
577
578 int sockfd;
579 if( ( sockfd = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0)
580 {
581 return Net_Unknown; // no info
582 }
583
584 if( connect(sockfd, (struct sockaddr *) &serv_addr,
585 sizeof(serv_addr)) >= 0)
586 {
587 close(sockfd);
588 return Net_Connected; // we can connect, so we have a network!
589 }
590 else // failed to connect
591 {
592 if(errno == ENETUNREACH)
593 return Net_No; // network is unreachable
594 else
595 return Net_Unknown; // connect failed, but don't know why
596 }
597 }
598
599
600 int
601 wxDialUpManagerImpl::CheckProcNet()
602 {
603 // assume that the test doesn't work
604 int netDevice = NetDevice_Unknown;
605
606 #ifdef __LINUX__
607 if (wxFileExists(_T("/proc/net/route")))
608 {
609 // cannot use wxFile::Length because file doesn't support seeking, so
610 // use stdio directly
611 FILE *f = fopen("/proc/net/route", "rt");
612 if (f != NULL)
613 {
614 // now we know that we will find all devices we may have
615 netDevice = NetDevice_None;
616
617 char output[256];
618
619 while (fgets(output, 256, f) != NULL)
620 {
621 if ( strstr(output, "eth") ) // network card
622 {
623 netDevice |= NetDevice_LAN;
624 }
625 else if (strstr(output,"ppp") // ppp
626 || strstr(output,"sl") // slip
627 || strstr(output,"pl")) // plip
628 {
629 netDevice |= NetDevice_Modem;
630 }
631 }
632
633 fclose(f);
634 }
635 }
636 #endif // __LINUX__
637
638 return netDevice;
639 }
640
641
642 int
643 wxDialUpManagerImpl::CheckIfconfig()
644 {
645 #ifdef __VMS
646 m_CanUseIfconfig = 0;
647 return -1;
648 #else
649 // assume that the test doesn't work
650 int netDevice = NetDevice_Unknown;
651
652 // first time check for ifconfig location
653 if ( m_CanUseIfconfig == -1 ) // unknown
654 {
655 static const wxChar *ifconfigLocations[] =
656 {
657 _T("/sbin"), // Linux, FreeBSD, Darwin
658 _T("/usr/sbin"), // SunOS, Solaris, AIX, HP-UX
659 _T("/usr/etc"), // IRIX
660 };
661
662 for ( size_t n = 0; n < WXSIZEOF(ifconfigLocations); n++ )
663 {
664 wxString path(ifconfigLocations[n]);
665 path << _T("/ifconfig");
666
667 if ( wxFileExists(path) )
668 {
669 m_IfconfigPath = path;
670 break;
671 }
672 }
673 }
674
675 if ( m_CanUseIfconfig != 0 ) // unknown or yes
676 {
677 wxLogNull ln; // suppress all error messages
678
679 wxASSERT_MSG( m_IfconfigPath.length(),
680 _T("can't use ifconfig if it wasn't found") );
681
682 wxString tmpfile = wxGetTempFileName( wxT("_wxdialuptest") );
683 wxString cmd = wxT("/bin/sh -c \'");
684 cmd << m_IfconfigPath;
685 #if defined(__SOLARIS__) || defined (__SUNOS__)
686 // need to add -a flag
687 cmd << wxT(" -a");
688 #elif defined(__LINUX__) || defined(__SGI__)
689 // nothing to be added to ifconfig
690 #elif defined(__FREEBSD__) || defined(__DARWIN__)
691 // add -l flag
692 cmd << wxT(" -l");
693 #elif defined(__HPUX__)
694 // VZ: a wild guess (but without it, ifconfig fails completely)
695 cmd << wxT(" ppp0");
696 #else
697 # pragma warning "No ifconfig information for this OS."
698 m_CanUseIfconfig = 0;
699 return -1;
700 #endif
701 cmd << wxT(" >") << tmpfile << wxT('\'');
702 /* I tried to add an option to wxExecute() to not close stdout,
703 so we could let ifconfig write directly to the tmpfile, but
704 this does not work. That should be faster, as it doesn´t call
705 the shell first. I have no idea why. :-( (KB) */
706 if ( wxExecute(cmd,TRUE /* sync */) == 0 )
707 {
708 m_CanUseIfconfig = 1;
709 wxFFile file;
710 if( file.Open(tmpfile) )
711 {
712 wxString output;
713 if ( file.ReadAll(&output) )
714 {
715 // FIXME shouldn't we grep for "^ppp"? (VZ)
716
717 bool hasModem = FALSE,
718 hasLAN = FALSE;
719
720 #if defined(__SOLARIS__) || defined (__SUNOS__)
721 // dialup device under SunOS/Solaris
722 hasModem = strstr(output,"ipdptp") != (char *)NULL;
723 hasLAN = strstr(output, "hme") != (char *)NULL;
724 #elif defined(__LINUX__) || defined (__FREEBSD__)
725 hasModem = strstr(output.fn_str(),"ppp") // ppp
726 || strstr(output.fn_str(),"sl") // slip
727 || strstr(output.fn_str(),"pl"); // plip
728 hasLAN = strstr(output.fn_str(), "eth") != NULL;
729 #elif defined(__SGI__) // IRIX
730 hasModem = strstr(output, "ppp") != NULL; // PPP
731 #elif defined(__HPUX__)
732 // if could run ifconfig on interface, then it exists
733 hasModem = TRUE;
734 #endif
735
736 netDevice = NetDevice_None;
737 if ( hasModem )
738 netDevice |= NetDevice_Modem;
739 if ( hasLAN )
740 netDevice |= NetDevice_LAN;
741 }
742 //else: error reading the file
743 }
744 //else: error opening the file
745 }
746 else // could not run ifconfig correctly
747 {
748 m_CanUseIfconfig = 0; // don´t try again
749 }
750
751 (void) wxRemoveFile(tmpfile);
752 }
753
754 return netDevice;
755 #endif
756 }
757
758 wxDialUpManagerImpl::NetConnection wxDialUpManagerImpl::CheckPing()
759 {
760 // First time check for ping location. We only use the variant
761 // which does not take arguments, a la GNU.
762 if(m_CanUsePing == -1) // unknown
763 {
764 #ifdef __VMS
765 if (wxFileExists( wxT("SYS$SYSTEM:TCPIP$PING.EXE") ))
766 m_PingPath = wxT("$SYS$SYSTEM:TCPIP$PING");
767 #else
768 if (wxFileExists( wxT("/bin/ping") ))
769 m_PingPath = wxT("/bin/ping");
770 else if (wxFileExists( wxT("/usr/sbin/ping") ))
771 m_PingPath = wxT("/usr/sbin/ping");
772 #endif
773 if (!m_PingPath)
774 {
775 m_CanUsePing = 0;
776 }
777 }
778
779 if(! m_CanUsePing)
780 {
781 // we didn't find ping
782 return Net_Unknown;
783 }
784
785 wxLogNull ln; // suppress all error messages
786 wxASSERT(m_PingPath.length());
787 wxString cmd;
788 cmd << m_PingPath << wxT(' ');
789 #if defined(__SOLARIS__) || defined (__SUNOS__)
790 // nothing to add to ping command
791 #elif defined(__LINUX__) || defined (__BSD__) || defined( __VMS )
792 cmd << wxT("-c 1 "); // only ping once
793 #elif defined(__HPUX__)
794 cmd << wxT("64 1 "); // only ping once (need also specify the packet size)
795 #else
796 # pragma warning "No Ping information for this OS."
797 m_CanUsePing = 0;
798 return Net_Unknown;
799 #endif
800 cmd << m_BeaconHost;
801 if(wxExecute(cmd, TRUE /* sync */) == 0)
802 return Net_Connected;
803 else
804 return Net_No;
805 }
806
807 /* static */
808 wxDialUpManager *wxDialUpManager::Create()
809 {
810 return new wxDialUpManagerImpl;
811 }
812
813 #endif // wxUSE_DIALUP_MANAGER