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