1 ////////////////////////////////////////////////// 2 3 #include <ptlib.h> 4 #include <ptlib/pprocess.h> 5 #include <ptclib/psockbun.h> 6 7 8 class SockBundleProcess : public PProcess 9 { 10 PCLASSINFO(SockBundleProcess, PProcess) 11 12 public: 13 SockBundleProcess(); 14 void Main(); 15 }; 16 17 PCREATE_PROCESS(SockBundleProcess); 18 19 SockBundleProcess()20SockBundleProcess::SockBundleProcess() 21 { 22 } 23 24 Main()25void SockBundleProcess::Main() 26 { 27 PArgList & args = GetArguments(); 28 29 args.Parse( 30 #if PTRACING 31 "o-output:" "-no-output." 32 "t-trace." "-no-trace." 33 #endif 34 ); 35 36 #if PTRACING 37 PTrace::Initialise(args.GetOptionCount('t'), 38 args.HasOption('o') ? (const char *)args.GetOptionString('o') : NULL, 39 PTrace::Blocks | PTrace::Timestamp | PTrace::Thread | PTrace::FileAndLine); 40 #endif 41 42 PMonitoredSocketBundle bundle; 43 if (!bundle.Open(5080)) { 44 cout << "Cannot open monitored socket bundle" << endl; 45 return; 46 } 47 48 PSingleMonitoredSocket single(bundle.GetInterfaces()[0]); 49 if (!single.Open(1719)) { 50 cout << "Cannot open single monitored socket" << endl; 51 return; 52 } 53 54 cout << "Initial interfaces:" << endl; 55 for (;;) { 56 PStringArray interfaces = bundle.GetInterfaces(); 57 PINDEX i; 58 for (i = 0; i < interfaces.GetSize(); ++i) { 59 cout << " #" << i+1 << ' '; 60 61 PIPSocket::InterfaceEntry entry; 62 if (!bundle.GetInterfaceInfo(interfaces[i], entry)) 63 cout << interfaces[i] << " is no longer active" << endl; 64 else 65 cout << entry << endl; 66 } 67 68 cout << endl << "\nWaiting for interface changes" << endl; 69 70 Sleep(10000); 71 72 cout << "\nCurrent interfaces:" << endl; 73 } 74 } 75