31 #ifndef PTLIB_PSOCKBUN_H
32 #define PTLIB_PSOCKBUN_H
51 #define PINTERFACE_MONITOR_FACTORY_NAME "InterfaceMonitor"
74 bool runMonitorThread =
true
104 bool includeLoopBack =
false,
125 InterfaceEntry & info
134 const InterfaceEntry & entry
155 virtual void OnInterfacesChanged(
const PIPSocket::InterfaceTable & addedInterfaces,
const PIPSocket::InterfaceTable & removedInterfaces);
204 bool includeLoopBack =
false,
215 InterfaceEntry & info
247 PIPSocket::InterfaceTable & interfaces)
const = 0;
306 PINDEX & lastWriteCount
321 PINDEX & lastReadCount,
328 ) { natMethod = method; }
340 bool reuseAddr =
false,
376 PINDEX & lastWriteCount
384 PINDEX & lastReadCount,
394 PINDEX & lastReadCount,
422 const PMonitoredSocketsPtr & sockets,
533 bool reuseAddr =
false,
545 bool includeLoopBack =
false,
582 PINDEX & lastWriteCount
597 PINDEX & lastReadCount,
611 void CloseSocket(SocketInfoMap_T::iterator iterSocket);
629 bool reuseAddr =
false,
639 bool includeLoopBack =
false,
676 PINDEX & lastWriteCount
691 PINDEX & lastReadCount,
711 #endif // PTLIB_PSOCKBUN_H
Class for detector of Route Table changes.
Definition: ipsock.h:620
WORD GetPort() const
Return the local port number being used by the socket(s)
Definition: psockbun.h:285
void SetInterface(const PString &iface)
Set the interface descriptor to be used for all reads/writes to this channel.
bool inUse
Definition: psockbun.h:355
virtual PChannel::Errors WriteToBundle(const void *buf, PINDEX len, const PIPSocket::Address &addr, WORD port, const PString &iface, PINDEX &lastWriteCount)
Write to the remote address/port using the socket(s) available.
bool IsInterface(const PString &iface) const
bool GetInterfaceInfo(const PString &iface, InterfaceEntry &info) const
Return information about an active interface given the descriptor string.
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.
~PMonitoredSocketBundle()
virtual void OnRemoveInterface(const InterfaceEntry &entry)
Call back function for when an interface has been removed from the system.
PIPSocket::Address lastReceivedAddress
Definition: psockbun.h:516
void CloseSocket(SocketInfoMap_T::iterator iterSocket)
virtual PChannel::Errors ReadFromBundle(void *buffer, PINDEX length, PIPSocket::Address &addr, WORD &port, PString &iface, PINDEX &lastReadCount, const PTimeInterval &timeout)=0
Read fram a remote address/port using the socket(s) available.
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...
SocketInfoMap_T socketInfoMap
Definition: psockbun.h:613
bool reuseAddress
Definition: psockbun.h:399
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.
PINDEX priority
Definition: psockbun.h:234
std::list< PInterfaceMonitorClient * > ClientList_T
Definition: psockbun.h:159
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:55
PInterfaceMonitor(unsigned refreshInterval=DefaultRefreshInterval, bool runMonitorThread=true)
bool promiscuousReads
Definition: psockbun.h:512
virtual PChannel::Errors ReadFromBundle(void *buf, PINDEX len, PIPSocket::Address &addr, WORD &port, PString &iface, PINDEX &lastReadCount, const PTimeInterval &timeout)
Read fram a remote address/port using the socket(s) available.
virtual PBoolean Close()
Close all socket(s)
static bool IsMatchingInterface(const PString &iface, const InterfaceEntry &entry)
Returns whether the descriptor string equals the interface entry.
bool closing
Definition: psockbun.h:514
PBoolean IsOpen() const
Indicate if the socket(s) are open and ready for reads/writes.
Definition: psockbun.h:279
virtual void OnRemoveNatMethod(const PNatMethod *natMethod)
Called when a NAT method is about to be destroyed.
PIPSocket::InterfaceEntry InterfaceEntry
Definition: psockbun.h:195
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:258
A socket channel that uses the UDP transport on the Internet Protocol.
Definition: udpsock.h:47
Describe an interface table entry.
Definition: ipsock.h:642
virtual ~PInterfaceMonitor()
virtual void RefreshInterfaceList()
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.
PMutex m_threadMutex
Definition: psockbun.h:168
void SetRemote(const PIPSocket::Address &address, WORD port)
Set the remote address/port for all Write() functions.
virtual void OnRemoveNatMethod(const PNatMethod *)
Called when a NAT method is about to be destroyed.
Definition: psockbun.h:232
Definition: psockbun.h:349
List of sockets used for Select() function.
Definition: socket.h:311
virtual void OnAddInterface(const InterfaceEntry &entry)
Call back function for when an interface has been added to the system.
bool IsValidBindingForDestination(const PIPSocket::Address &binding, const PIPSocket::Address &destination)
Returns whether destination is reachable through binding or not.
virtual PChannel::Errors ReadFromBundle(void *buf, PINDEX len, PIPSocket::Address &addr, WORD &port, PString &iface, PINDEX &lastReadCount, const PTimeInterval &timeout)
Read fram a remote address/port using the socket(s) available.
bool CreateSocket(SocketInfo &info, const PIPSocket::Address &binding)
virtual PBoolean Open(WORD port)
Open the socket(s) using the specified port.
WORD remotePort
Definition: psockbun.h:515
PIPSocket::InterfaceEntry InterfaceEntry
Definition: psockbun.h:97
This is an array collection class of PString objects.
Definition: pstring.h:2024
Definition: psockbun.h:242
PString lastReceivedInterface
Definition: psockbun.h:518
ClientList_T m_clients
Definition: psockbun.h:160
PSafePtr< PMonitoredSockets > PMonitoredSocketsPtr
Definition: psockbun.h:406
virtual PBoolean Write(const void *buffer, PINDEX length)
Override of PChannel functions to allow connectionless writes.
PSmartPtr< PInterfaceMonitorClient > ClientPtr
Definition: psockbun.h:157
static PMonitoredSockets * Create(const PString &iface, bool reuseAddr=false, PNatMethod *natMethod=NULL)
Create a new monitored socket instance based on the interface descriptor.
Errors
Normalised error codes.
Definition: channel.h:529
bool GetLocal(PIPSocket::Address &address, WORD &port, bool usingNAT)
Get the local IP address and port for the currently selected interface.
BOOL PBoolean
Definition: object.h:102
PString GetLastReceivedInterface() const
Get the interface the last received UDP data was recieved on.
Definition: psockbun.h:502
void SetRunMonitorThread(bool runMonitorThread)
Change whether the monitor thread should run.
void SetNatMethod(PNatMethod *method)
Set the NAT method, eg STUN client pointer.
Definition: psockbun.h:326
PInterfaceMonitorClient(PINDEX priority=DefaultPriority)
This class can be used to access the bundled/monitored UDP sockets using the PChannel API...
Definition: psockbun.h:414
PIPSocket::Address remoteAddress
Definition: psockbun.h:513
virtual PBoolean GetAddress(const PString &iface, PIPSocket::Address &address, WORD &port, PBoolean usingNAT) const
Get the local address for the given interface.
Definition: psockbun.h:190
virtual PChannel::Errors WriteToBundle(const void *buf, PINDEX len, const PIPSocket::Address &addr, WORD port, const PString &iface, PINDEX &lastWriteCount)
Write to the remote address/port using the socket(s) available.
PUDPSocket interfaceAddedSignal
Definition: psockbun.h:403
PNatMethod Base Network Address Traversal Method class All NAT Traversal Methods are derived off this...
Definition: pnat.h:49
virtual void OnShutdown()
PString theInterface
Definition: psockbun.h:705
~PInterfaceMonitorClient()
PMutex mutex
Definition: psockbun.h:519
This concrete class bundles a set of UDP sockets which are dynamically adjusted as interfaces are add...
Definition: psockbun.h:528
Abstract class defining I/O channel semantics.
Definition: channel.h:107
Definition: psockbun.h:69
This class defines a thread-safe object in a collection.
Definition: safecoll.h:119
virtual PIPSocket::InterfaceTable FilterInterfaces(const PIPSocket::Address &destination, PIPSocket::InterfaceTable &interfaces) const =0
virtual void OnAddInterface(const InterfaceEntry &entry)=0
Call back function for when an interface has been added to the system.
The character string class.
Definition: pstring.h:108
void OnRemoveNatMethod(const PNatMethod *natMethod)
virtual void OnAddInterface(const InterfaceEntry &entry)
Call back function for when an interface has been added to the system.
PINDEX GetPriority() const
Returns the priority of this client.
Definition: psockbun.h:222
This is a base class for clients of the PInterfaceMonitor singleton object.
Definition: psockbun.h:185
virtual PBoolean IsOpen() const
Determine if the channel is currently open.
PMutex m_interfacesMutex
Definition: psockbun.h:164
PSingleMonitoredSocket(const PString &theInterface, bool reuseAddr=false, PNatMethod *natMethod=NULL)
This concrete class monitors a single scoket bound to a specific interface or address.
Definition: psockbun.h:623
This class is a singleton that will monitor the network interfaces on a machine and update a list aof...
Definition: psockbun.h:64
PString currentInterface
Definition: psockbun.h:511
PThread * m_updateThread
Definition: psockbun.h:169
const PMonitoredSocketsPtr & GetMonitoredSockets() const
Get the monitored socket bundle being used by this channel.
Definition: psockbun.h:505
virtual PBoolean GetInterfaceInfo(const PString &iface, InterfaceEntry &info) const
Return information about an active interface given the descriptor string.
PChannel::Errors ReadFromSocket(SocketInfo &info, void *buf, PINDEX len, PIPSocket::Address &addr, WORD &port, PINDEX &lastReadCount, const PTimeInterval &timeout)
PMonitoredSocketBundle(bool reuseAddr=false, PNatMethod *natMethod=NULL)
bool DestroySocket(SocketInfo &info)
PMonitoredSockets(bool reuseAddr, PNatMethod *natMethod)
PMonitoredSocketChannel(const PMonitoredSocketsPtr &sockets, bool shared)
Construct a monitored socket bundle channel.
This template class creates a type safe version of PSmartPointer.
Definition: smartptr.h:174
This class defines a thread of execution in the system.
Definition: thread.h:66
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:172
static PIPSocket::Address GetDefaultIpAny()
PMutex m_clientsMutex
Definition: psockbun.h:161
void GetRemote(PIPSocket::Address &addr, WORD &port) const
Get the current remote address/port for all Write() functions.
Definition: psockbun.h:479
PChannel::Errors WriteToSocket(const void *buf, PINDEX len, const PIPSocket::Address &addr, WORD port, const SocketInfo &info, PINDEX &lastWriteCount)
PTimeInterval m_refreshInterval
Definition: psockbun.h:167
void SetRefreshInterval(unsigned refresh)
Change the refresh interval.
Template class for generic factories of an abstract class.
Definition: pfactory.h:144
A class describing an IP address.
Definition: ipsock.h:75
bool sharedBundle
Definition: psockbun.h:510
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:163
Definition: pprocess.h:779
InterfaceEntry theEntry
Definition: psockbun.h:706
void Stop()
Stop monitoring network interfaces.
PFACTORY_GET_SINGLETON(PProcessStartupFactory, PInterfaceMonitor)
Return the singleton interface for the network monitor.
PNatMethod * GetNatMethod() const
Definition: psockbun.h:332
WORD lastReceivedPort
Definition: psockbun.h:517
void SetPromiscuous(bool flag)
Set flag for receiving UDP data from any remote address.
Definition: psockbun.h:488
virtual PBoolean Open(WORD port)=0
Open the socket(s) using the specified port.
virtual void OnRemoveInterface(const InterfaceEntry &entry)
Call back function for when an interface has been removed from the system.
void Start()
Start monitoring network interfaces.
bool GetSocketAddress(const SocketInfo &info, PIPSocket::Address &address, WORD &port, bool usingNAT) const
bool opened
Definition: psockbun.h:402
void AddClient(PInterfaceMonitorClient *)
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:496
void RemoveClient(PInterfaceMonitorClient *)
void SetInterfaceFilter(PInterfaceFilter *filter)
Sets the monitor's interface filter.
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...
std::map< std::string, SocketInfo > SocketInfoMap_T
Definition: psockbun.h:608
~PSingleMonitoredSocket()
PNatMethod * natMethod
Definition: psockbun.h:400
virtual PBoolean Close()
Close all socket(s)
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
bool GetPromiscuous()
Get flag for receiving UDP data from any remote address.
Definition: psockbun.h:493
virtual PChannel::Errors WriteToBundle(const void *buffer, PINDEX length, const PIPSocket::Address &addr, WORD port, const PString &iface, PINDEX &lastWriteCount)=0
Write to the remote address/port using the socket(s) available.
SocketInfo theInfo
Definition: psockbun.h:707
SocketInfo()
Definition: psockbun.h:350
PInterfaceFilter * m_interfaceFilter
Definition: psockbun.h:171
PMonitoredSocketsPtr socketBundle
Definition: psockbun.h:509
void OpenSocket(const PString &iface)
virtual void OnRemoveInterface(const InterfaceEntry &entry)=0
Call back function for when an interface has been removed from the system.
WORD localPort
Definition: psockbun.h:398
bool m_runMonitorThread
Definition: psockbun.h:166
PUDPSocket * socket
Definition: psockbun.h:354
bool HasInterfaceFilter() const
Definition: psockbun.h:141