27 #ifndef PTLIB_PSOCKBUN_H
28 #define PTLIB_PSOCKBUN_H
43 #define PINTERFACE_MONITOR_FACTORY_NAME "InterfaceMonitor"
53 PIPSocket::InterfaceTable & interfaces)
const = 0;
77 bool runMonitorThread =
true
107 bool includeLoopBack =
false,
156 #define PDECLARE_InterfaceNotifier(cls, fn) PDECLARE_NOTIFIER2(PInterfaceMonitor, cls, fn, PInterfaceMonitor::InterfaceChange)
159 #define PCREATE_InterfaceNotifier(fn) PCREATE_NOTIFIER2(fn, PInterfaceMonitor::InterfaceChange)
187 virtual void OnInterfacesChanged(
const PIPSocket::InterfaceTable & addedInterfaces,
const PIPSocket::InterfaceTable & removedInterfaces);
307 bool includeLoopBack =
false,
339 bool reuseAddr =
false
378 PNatMethods * m_natMethods;
402 const PMonitoredSocketsPtr & sockets,
525 const PString & fixedInterface,
539 bool includeLoopBack =
false,
596 void CloseSocket(SocketInfoMap_T::iterator iterSocket);
626 bool includeLoopBack =
false,
689 #endif // PTLIB_PSOCKBUN_H
Class for detector of Route Table changes.
Definition: ipsock.h:691
WORD GetPort() const
Return the local port number being used by the socket(s)
Definition: psockbun.h:244
void SetInterface(const PString &iface)
Set the interface descriptor to be used for all reads/writes to this channel.
static PMonitoredSockets * Create(const PString &iface, bool reuseAddr=falseP_NAT_PARAM(PNatMethods *natMethods=NULL))
Create a new monitored socket instance based on the interface descriptor.
bool IsInterface(const PString &iface) const
bool GetInterfaceInfo(const PString &iface, InterfaceEntry &info) const
Return information about an active interface given the descriptor string.
Notifiers m_notifiers
Definition: psockbun.h:190
PIPSocket::Address m_addr
Remote IP address data came from, or is written to.
Definition: psockbun.h:272
virtual PBoolean GetAddress(const PString &iface, PIPSocket::Address &address, WORD &port, PBoolean usingNAT) const
Get the local address for the given interface.
virtual PBoolean Read(void *buffer, PINDEX length)
Override of PChannel functions to allow connectionless reads.
friend class PInterfaceMonitorClient
Definition: psockbun.h:204
PDECLARE_InterfaceNotifier(PMonitoredSocketBundle, OnInterfaceChange)
~PMonitoredSocketBundle()
void * m_buffer
Data to read/write.
Definition: psockbun.h:270
PUDPSocket * m_socket
Definition: psockbun.h:352
PIPSocket::InterfaceEntry InterfaceEntry
Definition: psockbun.h:225
void CloseSocket(SocketInfoMap_T::iterator iterSocket)
virtual PStringArray GetInterfaces(bool includeLoopBack=false, const PIPSocket::Address &destination=PIPSocket::GetDefaultIpAny())
Get an array of all current interface descriptors, possibly including the loopback (127...
PIPSocketAddressAndPort m_lastReceivedAP
Definition: psockbun.h:509
virtual PBoolean Open(WORD port)
Open the socket(s) using the specified port.
virtual PBoolean GetAddress(const PString &iface, PIPSocket::Address &address, WORD &port, PBoolean usingNAT) const =0
Get the local address for the given interface.
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:51
PInterfaceMonitor(unsigned refreshInterval=DefaultRefreshInterval, bool runMonitorThread=true)
PString m_interface
Definition: psockbun.h:683
virtual PBoolean Close()
Close all socket(s)
#define P_NAT_PARAM(...)
Definition: pnat.h:637
static bool IsMatchingInterface(const PString &iface, const InterfaceEntry &entry)
Returns whether the descriptor string equals the interface entry.
PNotifierTemplate< InterfaceChange > Notifier
Type for disposition notifiers.
Definition: psockbun.h:153
PChannel::Errors m_errorCode
Error code for read/write.
Definition: psockbun.h:277
PINDEX m_length
Maximum length of data.
Definition: psockbun.h:271
PBoolean IsOpen() const
Indicate if the socket(s) are open and ready for reads/writes.
Definition: psockbun.h:238
virtual PString GetName() const
Get the platform and I/O channel type name of the channel.
virtual bool SetQoS(const PIPSocket::QoS &qos)
Set the quality of service for sockets.
virtual PBoolean Close()=0
Close all socket(s)
This is a base class for UDP socket(s) that are monitored for interface changes.
Definition: psockbun.h:215
A socket channel that uses the UDP transport on the Internet Protocol.
Definition: udpsock.h:42
Describe an interface table entry.
Definition: ipsock.h:713
virtual ~PInterfaceMonitor()
virtual void RefreshInterfaceList()
PDECLARE_MUTEX(m_notifiersMutex)
virtual void OnInterfacesChanged(const PIPSocket::InterfaceTable &addedInterfaces, const PIPSocket::InterfaceTable &removedInterfaces)
virtual PBoolean Close()
Close the channel, shutting down the link to the data source.
SocketInfoMap_T m_socketInfoMap
Definition: psockbun.h:598
bool m_closing
Definition: psockbun.h:507
Definition: psockbun.h:72
void SetRemote(const PIPSocket::Address &address, WORD port)
Set the remote address/port for all Write() functions.
Definition: psockbun.h:453
WORD m_port
Remote port data came from, or is written to.
Definition: psockbun.h:273
Definition: psockbun.h:344
List of sockets used for Select() function.
Definition: socket.h:312
PSingleMonitoredSocket(const PString &theInterface, bool reuseAddrP_NAT_PARAM(PNatMethods *natMethods=NULL))
This class is a variation of a string that ignores case.
Definition: pstring.h:2012
bool IsValidBindingForDestination(const PIPSocket::Address &binding, const PIPSocket::Address &destination)
Returns whether destination is reachable through binding or not.
PIPSocketAddressAndPort m_remoteAP
Definition: psockbun.h:508
bool CreateSocket(SocketInfo &info, const PIPSocket::Address &binding)
PTimeInterval m_timeout
Time to wait for data.
Definition: psockbun.h:276
virtual PBoolean Open(WORD port)
Open the socket(s) using the specified port.
bool m_inUse
Definition: psockbun.h:353
PIPSocket::InterfaceEntry InterfaceEntry
Definition: psockbun.h:100
This is an array collection class of PString objects.
Definition: pstring.h:2365
Definition: psockbun.h:48
PString m_lastReceivedInterface
Definition: psockbun.h:510
A class describing an IP address and port number combination.
Definition: ipsock.h:278
PInterfaceMonitor::Notifier m_onInterfaceChange
Definition: psockbun.h:591
PSafePtr< PMonitoredSockets > PMonitoredSocketsPtr
Definition: psockbun.h:386
virtual PBoolean Write(const void *buffer, PINDEX length)
Override of PChannel functions to allow connectionless writes.
virtual void WriteToBundle(BundleParams ¶m)=0
Write to the remote address/port using the socket(s) available.
Errors
Normalised error codes.
Definition: channel.h:227
void SetAddress(const PIPSocket::Address &addr, WORD port=0)
bool m_sharedBundle
Definition: psockbun.h:504
bool GetLocal(PIPSocket::Address &address, WORD &port, bool usingNAT)
Get the local IP address and port for the currently selected interface.
PString GetLastReceivedInterface() const
Get the interface the last received UDP data was recieved on.
Definition: psockbun.h:496
PINDEX m_lastCount
Actual length of data read/written.
Definition: psockbun.h:275
void SetRunMonitorThread(bool runMonitorThread)
Change whether the monitor thread should run.
virtual PStringArray GetInterfaces(bool includeLoopBack=false, const PIPSocket::Address &destination=PIPSocket::GetDefaultIpAny())
Get an array of all current interface descriptors, possibly including the loopback (127...
unsigned m_ipVersion
Definition: psockbun.h:600
This class can be used to access the bundled/monitored UDP sockets using the PChannel API...
Definition: psockbun.h:394
PMonitoredSockets(bool reuseAddrP_NAT_PARAM(PNatMethods *natMethods))
virtual PBoolean GetAddress(const PString &iface, PIPSocket::Address &address, WORD &port, PBoolean usingNAT) const
Get the local address for the given interface.
virtual void ReadFromBundle(BundleParams ¶m)
Read fram a remote address/port using the socket(s) available.
Definition: psockbun.h:259
virtual void OnShutdown()
bool m_promiscuousReads
Definition: psockbun.h:506
void RemoveNotifier(const Notifier ¬ifier)
void Write(BundleParams ¶m)
This concrete class bundles a set of UDP sockets which are dynamically adjusted as interfaces are add...
Definition: psockbun.h:520
Abstract class defining I/O channel semantics.
Definition: channel.h:103
This class defines a thread-safe object in a collection.
Definition: safecoll.h:123
bool m_opened
Definition: psockbun.h:381
virtual bool SetQoS(const PIPSocket::QoS &qos)
Set the quality of service for sockets.
PString m_currentInterface
Definition: psockbun.h:505
virtual void ReadFromBundle(BundleParams ¶m)
Read fram a remote address/port using the socket(s) available.
bool PBoolean
Definition: object.h:174
virtual PIPSocket::InterfaceTable FilterInterfaces(const PIPSocket::Address &destination, PIPSocket::InterfaceTable &interfaces) const =0
void Read(PMonitoredSockets &bundle, BundleParams ¶m)
WORD GetPort() const
Definition: ipsock.h:320
virtual void WriteToBundle(BundleParams ¶m)
Write to the remote address/port using the socket(s) available.
PIPSocket::QoS m_qos
Definition: psockbun.h:383
void AddNotifier(const Notifier ¬ifier, unsigned priority=DefaultPriority)
Add a notifier for interface changes.
std::multimap< unsigned, Notifier > Notifiers
Definition: psockbun.h:189
BundleParams()
Definition: psockbun.h:260
The character string class.
Definition: pstring.h:108
void GetRemote(PIPSocketAddressAndPort &ap) const
Definition: psockbun.h:471
virtual PBoolean IsOpen() const
Determine if the channel is currently open.
PCaselessString m_fixedInterface
Definition: psockbun.h:599
This concrete class monitors a single scoket bound to a specific interface or address.
Definition: psockbun.h:610
This class is a singleton that will monitor the network interfaces on a machine and update a list aof...
Definition: psockbun.h:67
PThread * m_updateThread
Definition: psockbun.h:199
const PMonitoredSocketsPtr & GetMonitoredSockets() const
Get the monitored socket bundle being used by this channel.
Definition: psockbun.h:499
bool DestroySocket(SocketInfo &info)
InterfaceEntry m_entry
Definition: psockbun.h:684
PMonitoredSocketChannel(const PMonitoredSocketsPtr &sockets, bool shared)
Construct a monitored socket bundle channel.
virtual void WriteToBundle(BundleParams ¶m)
Write to the remote address/port using the socket(s) available.
void GetLastReceived(PIPSocketAddressAndPort &ap) const
Definition: psockbun.h:491
This class defines a thread of execution in the system.
Definition: thread.h:66
void ReadFromSocketList(PSocket::SelectList &readers, PUDPSocket *&socket, BundleParams ¶m)
PString m_iface
Interface to use for read or write, also then one data was read on.
Definition: psockbun.h:274
virtual PStringArray GetInterfaces(bool includeLoopBack=false, const PIPSocket::Address &destination=PIPSocket::GetDefaultIpAny())
Get an array of all current interface descriptors, possibly including the loopback (127...
PIPSocket::RouteTableDetector * m_changedDetector
Definition: psockbun.h:202
Information on the interface change.
Definition: psockbun.h:142
PInterfaceMonitor::Notifier m_onInterfaceChange
Definition: psockbun.h:679
void GetRemote(PIPSocket::Address &addr, WORD &port) const
Get the current remote address/port for all Write() functions.
Definition: psockbun.h:467
PTimeInterval m_refreshInterval
Definition: psockbun.h:197
void SetRefreshInterval(unsigned refresh)
Change the refresh interval.
Class for a factory to create concrete class instances without parameters during construction.
Definition: pfactory.h:396
A class describing an IP address.
Definition: ipsock.h:59
Definition: psockbun.h:162
virtual void ReadFromBundle(BundleParams ¶m)=0
Read fram a remote address/port using the socket(s) available.
PStringArray GetInterfaces(bool includeLoopBack=false, const PIPSocket::Address &destination=PIPSocket::GetDefaultIpAny())
Get an array of all current interface descriptors, possibly including the loopback (127...
PIPSocket::InterfaceTable m_interfaces
Definition: psockbun.h:193
static const PIPSocket::Address & GetDefaultIpAny()
Definition: pprocess.h:786
void Stop()
Stop monitoring network interfaces.
PFACTORY_GET_SINGLETON(PProcessStartupFactory, PInterfaceMonitor)
Return the singleton interface for the network monitor.
void SetPromiscuous(bool flag)
Set flag for receiving UDP data from any remote address.
Definition: psockbun.h:479
virtual PBoolean Open(WORD port)=0
Open the socket(s) using the specified port.
const PIPSocket::Address & GetAddress() const
Definition: ipsock.h:313
void Start()
Start monitoring network interfaces.
bool GetSocketAddress(const SocketInfo &info, PIPSocket::Address &address, WORD &port, bool usingNAT) const
PUDPSocket m_interfaceAddedSignal
Definition: psockbun.h:382
PMonitoredSocketsPtr m_socketBundle
Definition: psockbun.h:503
PString GetInterface()
Get the current interface descriptor being used/.
void GetLastReceived(PIPSocket::Address &addr, WORD &port) const
Get the IP address and port of the last received UDP data.
Definition: psockbun.h:487
SocketInfo m_info
Definition: psockbun.h:685
PDECLARE_InterfaceNotifier(PSingleMonitoredSocket, OnInterfaceChange)
void SetInterfaceFilter(PInterfaceFilter *filter)
Sets the monitor's interface filter.
virtual bool GetInterfaceInfo(const PString &iface, InterfaceEntry &info) const
Return information about an active interface given the descriptor string.
std::map< std::string, SocketInfo > SocketInfoMap_T
Definition: psockbun.h:593
~PSingleMonitoredSocket()
InterfaceChange(const InterfaceEntry &entry, bool added)
Definition: psockbun.h:144
virtual bool SetQoS(const PIPSocket::QoS &qos)=0
Set the quality of service for sockets.
bool m_reuseAddress
Definition: psockbun.h:376
const bool m_added
Definition: psockbun.h:149
virtual PBoolean Close()
Close all socket(s)
int m_errorNumber
Error number (OS specific) for read/write.
Definition: psockbun.h:278
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
bool GetPromiscuous()
Get flag for receiving UDP data from any remote address.
Definition: psockbun.h:484
SocketInfo()
Definition: psockbun.h:345
PMonitoredSocketBundle(const PString &fixedInterface, unsigned ipVersion, bool reuseAddrP_NAT_PARAM(PNatMethods *natMethods=NULL))
PInterfaceFilter * m_interfaceFilter
Definition: psockbun.h:201
void OpenSocket(const PString &iface)
WORD m_localPort
Definition: psockbun.h:375
bool m_runMonitorThread
Definition: psockbun.h:196
bool HasInterfaceFilter() const
Definition: psockbun.h:179
void SetRemote(const PIPSocket::AddressAndPort &ap)
Definition: psockbun.h:457