30 #ifndef PTLIB_IPSOCKET_H
31 #define PTLIB_IPSOCKET_H
74 Address(PINDEX len,
const BYTE * bytes,
int scope = 0);
77 Address(BYTE b1, BYTE b2, BYTE b3, BYTE b4);
88 Address(
const in6_addr & addr,
int scope);
93 Address(
const int ai_family,
const int ai_addrlen,
struct sockaddr *ai_addr);
95 #ifdef __NUCLEUS_NET__
96 Address(
const struct id_struct & addr);
104 Address & AssignIPV6(
const in6_addr & addr,
int scope);
123 bool EqualIPV6(in6_addr & addr,
int scope)
const;
124 bool NotEqualIPV6(in6_addr & addr,
int scope)
const {
return !EqualIPV6(addr, scope); }
159 bool bracketIPv6 =
false,
160 bool excludeScope =
false
172 operator in_addr()
const;
175 operator in6_addr()
const;
178 int GetIPV6Scope()
const {
return m_scope6; }
182 operator DWORD()
const;
239 bool IsV4Mapped()
const;
243 bool IsLinkLocal()
const;
246 bool IsSiteLocal()
const;
290 WORD defaultPort = 0,
291 char separator =
':',
292 const char * proto = NULL
296 WORD defaultPort = 0,
300 struct sockaddr *ai_addr,
306 WORD defaultPort = 0,
307 char separator =
':',
308 const char * proto = NULL
379 static void SetDefaultIpAddressFamilyV6();
380 static PBoolean IsIpAddressFamilyV6Supported();
404 int ipAdressFamily=PF_INET
414 PortRange(WORD basePort = 0, WORD maxPort = 0);
420 unsigned dfltRange = 0,
421 unsigned dfltBase = 0
438 unsigned queueSize = 5,
443 PINDEX numSockets = 1,
445 unsigned queueSize = 5,
508 unsigned queueSize = 5,
515 unsigned queueSize = 5,
603 AddressAndPort & addr
621 AddressAndPort & addr
667 void PrintOn(ostream & strm)
const;
698 virtual void Cancel() = 0;
770 InterfaceTable & table,
790 const char * ifName = NULL
881 QoS(QoSType type = BestEffortQoS);
890 Flow() { memset(
this, 0,
sizeof(*
this)); }
916 #include "msos/ptlib/ipsock.h"
918 #include "unix/ptlib/ipsock.h"
932 operator sockaddr*()
const {
return addr; }
939 void Construct(
const Address & ip, WORD port);
941 sockaddr_storage storage;
947 sockaddr_in6 * addr6;
960 #endif // PTLIB_IPSOCKET_H
virtual bool SetQoS(const QoS &qos)
Set the current Quality of Service.
Class for detector of Route Table changes.
Definition: ipsock.h:691
PString AsString(bool bracketIPv6=false, bool excludeScope=false) const
Format an address as a string.
PString interfaceName
Definition: ipsock.h:673
BYTE Byte3() const
Return third byte of IPv4 address.
PortRange(WORD basePort=0, WORD maxPort=0)
in_addr m_four
Definition: ipsock.h:256
BYTE operator[](PINDEX idx) const
Return specified byte of IPv4 or IPv6 address.
static PString GetInterface(const Address &addr)
Get the interface name for the specified local IP address.
AddressAndPort(char separator= ':')
virtual PBoolean Listen(unsigned queueSize=5, WORD port=0, Reusability reuse=AddressIsExclusive)
Listen on a socket for a remote host on the specified port number.
Definition: ipsock.h:507
Address net_mask
Definition: ipsock.h:671
Address GetNetwork() const
Get the network address associated with the route table entry.
Definition: ipsock.h:652
Definition: object.h:2253
bool operator!=(in_addr &addr) const
Definition: ipsock.h:127
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:51
bool operator==(const Address &addr) const
Definition: ipsock.h:117
bool operator!=(DWORD dw) const
Definition: ipsock.h:129
bool Connect(PIPSocket &socket, const Address &addr, const Address &binding=GetDefaultIpAny())
Connect to remote.
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
QoS(QoSType type=BestEffortQoS)
static int GetDefaultIpAddressFamily()
Set the default IP address familly.
PBoolean FromString(const PString &str)
Convert string to IP address. Returns true if was a valid address.
static PBoolean IsLocalHost(const PString &hostname)
Determine if the specified host is actually the local machine.
struct PIPSocket::QoS::Flow m_transmit
PString GetLocalAddress() const
Get the Internet Protocol address and port for the local host.
friend ostream & operator<<(ostream &s, const Address &a)
Output IPv6 & IPv4 address as a string to the specified string.
WORD GetBase() const
Get base port for range.
Definition: ipsock.h:450
bool IsValid() const
Definition: ipsock.h:424
static Address GetInterfaceAddress(const PString &ifName, unsigned version=4)
Get the interface name for the specified local IP address.
bool operator!=(const Address &addr) const
Definition: ipsock.h:118
static RouteTableDetector * CreateRouteTableDetector()
Create an object that can wait for a change in the route table or active network interfaces.
unsigned m_maxBandwidth
Definition: ipsock.h:891
sockaddr_in * addr4
Definition: ipsock.h:945
Describe an interface table entry.
Definition: ipsock.h:713
void Set(unsigned newBase, unsigned newMax, unsigned dfltRange=0, unsigned dfltBase=0)
Set the port range parameters.
static PString GetGatewayInterface(unsigned version=4)
Get the name for the interface that is being used as the gateway, that is, the interface that packets...
static PBoolean GetHostAddress(Address &addr)
Get the Internet Protocol address for the specified host, or if none specified, for the host this pro...
socklen_t GetSize() const
This class describes a type of socket that will communicate using the Internet Protocol.
Definition: ipsock.h:47
static Address GetGatewayInterfaceAddress(unsigned version=4)
Get the IP address for the interface that is being used as the gateway, that is, the interface that p...
virtual Comparison Compare(const PObject &obj) const
Compare the two objects and return their relative rank.
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:2251
Address m_netMask
Definition: ipsock.h:757
friend istream & operator>>(istream &s, Address &a)
Input IPv4 (not IPv6 yet!) address as a string from the specified string.
static Address GetNetworkInterface(unsigned version=4)
Get the address of the first interface to the "Internet".
unsigned m_version
Definition: ipsock.h:261
friend ostream & operator<<(ostream &strm, const PIPSocket::QoS &qos)
int m_scope6
Definition: ipsock.h:262
P_DEPRECATED bool IsRFC1918() const
Definition: ipsock.h:236
Address m_ipAddress
Definition: ipsock.h:756
friend istream & operator>>(istream &strm, PIPSocket::QoS &qos)
unsigned m_maxJitter
Definition: ipsock.h:894
PIPSocket::Address PIPAddress
Definition: ipsock.h:953
const PString & GetInterface() const
Get the network address name associated with the route table entry.
Definition: ipsock.h:661
static void SetSuppressCanonicalName(bool suppress)
Set flag for suppress getting canonical name when doing lookup via hostname.
PIPSocket::Address m_address
Definition: ipsock.h:343
bool MatchWildcard(const AddressAndPort &wild) const
virtual void PrintOn(ostream &strm) const
Print to specified stream.
sockaddr_storage * ptr
Definition: ipsock.h:943
This is an array collection class of PString objects.
Definition: pstring.h:2365
PINDEX GetSize() const
Get the address length (will be either 4 or 16).
PString GetPeerHostName()
Get the host name for the peer host the socket is connected to.
unsigned GetVersion() const
Get the version of the IP address being used.
Definition: ipsock.h:206
virtual PString GetName() const
Get the platform and I/O channel type name of the channel.
static bool GetSuppressCanonicalName()
Get flag for suppress getting canonical name when doing lookup via hostname.
PString GetPeerAddress() const
Get the Internet Protocol address for the peer host and port the socket is connected to...
A class describing an IP address and port number combination.
Definition: ipsock.h:278
virtual void PrintOn(ostream &strm) const
Output the contents of the URL to the stream as a string.
WORD m_port
Definition: ipsock.h:344
QoSType m_type
Definition: ipsock.h:884
union PIPSocket::Address::@2 m_v
Runtime test of IP addresse type.
void SetAddress(const PIPSocket::Address &addr, WORD port=0)
BYTE Byte1() const
Return first byte of IPv4 address.
virtual bool InternalGetPeerAddress(AddressAndPort &addrAndPort)
PString m_macAddress
Definition: ipsock.h:758
BYTE Byte4() const
Return fourth byte of IPv4 address.
bool IsMulticast() const
Check if address is multicast group.
static PBoolean GetRouteTable(RouteTable &table)
Get the systems route table.
RouteEntry(const Address &addr)
Create a route table entry from an IP address.
Definition: ipsock.h:649
Address GetAddress() const
Get the address associated with the interface.
Definition: ipsock.h:743
bool Parse(const PString &str, WORD defaultPort=0, char separator= ':', const char *proto=NULL)
struct PIPSocket::QoS::Flow m_receive
PString GetLocalHostName()
Get the host name for the local host.
virtual bool InternalListen(const Address &bind, unsigned queueSize, WORD port, Reusability reuse)
PIPSocket()
Create a new Internet Protocol socket based on the port number specified.
Describe a route table entry.
Definition: ipsock.h:644
PString AsString(char separator=0) const
WORD m_max
Definition: ipsock.h:458
PIPSocket::AddressAndPort PIPSocketAddressAndPort
Definition: ipsock.h:955
BYTE Byte2() const
Return second byte of IPv4 address.
bool IsLoopback() const
Check address 127.0.0.1 or ::1.
bool IsValid() const
Check for illegal address.
Definition: ipsock.h:209
PString m_name
Definition: ipsock.h:755
Address GetDestination() const
Get the default gateway address associated with the route table entry.
Definition: ipsock.h:658
unsigned m_maxLatency
Definition: ipsock.h:893
static PStringArray GetHostAliases(const PString &hostname)
Get the alias host names for the specified host.
char m_separator
Definition: ipsock.h:345
virtual PBoolean OpenSocket()=0
virtual PBoolean Connect(const PString &address)
Connect a socket to a remote host on the specified port number.
virtual ~RouteTableDetector()
Definition: ipsock.h:694
const char * GetPointer() const
Get the pointer to IP address data.
Definition: ipsock.h:203
unsigned m_maxPacketSize
Definition: ipsock.h:892
bool PBoolean
Definition: object.h:174
bool operator*=(const Address &addr) const
Compare two addresses for equivalence.
Definition: ipsock.h:154
WORD GetMax() const
Get maximum port for range.
Definition: ipsock.h:453
static void SetDefaultIpAddressFamilyV4()
P_DECLARE_ENUM(QoSType, BackgroundQoS, BestEffortQoS, ExcellentEffortQoS, CriticalQoS, VideoQoS, VoiceQoS, ControlQoS)
The types of QoS supported, based on IEEE P802.1p TrafficClass parameter.
Address destination
Definition: ipsock.h:672
PARRAY(RouteTable, RouteEntry)
WORD GetPort() const
Definition: ipsock.h:320
long GetMetric() const
Get the network metric associated with the route table entry.
Definition: ipsock.h:664
long metric
Definition: ipsock.h:674
static void ClearNameCache()
Clear the name (DNS) cache.
WORD m_base
Definition: ipsock.h:457
The character string class.
Definition: pstring.h:108
virtual void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
Definition: ipsock.h:331
AddressAndPort m_remote
Definition: ipsock.h:887
bool operator!=(int i) const
Definition: ipsock.h:147
bool IsAny() const
Check address 0.0.0.0 or ::.
InterfaceEntry()
Create an interface entry from a name, IP addr and MAC addr.
QoS m_qos
Definition: ipsock.h:922
static const Address GetBroadcast(unsigned version=4)
bool Listen(PIPSocket &socket, const Address &binding=GetDefaultIpAny(), unsigned queueSize=5, Reusability reuse=AddressIsExclusive)
Listen on the socket(s) with local port in the range.
void SetPort(WORD port)
Definition: ipsock.h:322
virtual bool InternalGetLocalAddress(AddressAndPort &addrAndPort)
Comparison Compare(const PObject &obj) const
Compare two adresses for absolute (in)equality.
static const Address & GetAny(unsigned version=4)
static const Address & GetLoopback(unsigned version=4)
static Address GetGatewayAddress(unsigned version=4)
Get the IP address that is being used as the gateway, that is, the computer that packets on the defau...
Address & operator=(const in_addr &addr)
Copy an address from another IP v4 address.
static Address GetRouteInterfaceAddress(const Address &remoteAddress)
Get the interface address that will be used to reach the specified remote address.
std::vector< PIPSocket::AddressAndPort > PIPSocketAddressAndPortVector
Definition: ipsock.h:957
A class describing an IP address.
Definition: ipsock.h:59
static const PIPSocket::Address & GetInvalidAddress()
void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
Address GetNetMask() const
Get the network address mask associated with the route table entry.
Definition: ipsock.h:655
Class for handling a range of ports for local binding.
Definition: ipsock.h:412
Address GetNetMask() const
Get the net mask associated with the interface.
Definition: ipsock.h:746
bool operator==(int i) const
Definition: ipsock.h:146
bool IsBroadcast() const
Check for Broadcast address 255.255.255.255.
virtual bool Wait(const PTimeInterval &timeout)=0
static const PIPSocket::Address & GetDefaultIpAny()
Address network
Definition: ipsock.h:670
const QoS & GetQoS() const
Get the current Quality of Service.
Definition: ipsock.h:907
virtual PBoolean Listen(const Address &bind, unsigned queueSize=5, WORD port=0, Reusability reuse=AddressIsExclusive)
Definition: ipsock.h:513
const PIPSocket::Address & GetAddress() const
Definition: ipsock.h:313
#define P_DEPRECATED
Definition: object.h:141
static PBoolean GetInterfaceTable(InterfaceTable &table, PBoolean includeDown=false)
Get a list of all interfaces.
const PString & GetName() const
Get the name of the interface.
Definition: ipsock.h:740
static PString GetHostName()
Get the "official" host name for the host specified or if none, the host this process is running on...
bool IsSubNet(const Address &network, const Address &mask) const
Check if this address is within the sub-net.
friend ostream & operator<<(ostream &strm, const PortRange &pr)
Definition: ipsock.h:425
int m_dscp
Definition: ipsock.h:885
A network communications channel.
Definition: socket.h:59
sockaddr * operator->() const
Definition: ipsock.h:931
const PString & GetMACAddress() const
Get the MAC address associate with the interface.
Definition: ipsock.h:749
Flow()
Definition: ipsock.h:890
PIPSocket::AddressAndPort PIPAddressAndPort
Definition: ipsock.h:954
Reusability
Flags to reuse of port numbers in Listen() function.
Definition: socket.h:85
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
static void SanitiseName(PString &name)
Sanitise a device name for use in PTLib.
static PString GetInterfaceMACAddress(const char *ifName=NULL)
Get MAC address of interface.
PIPSocket::Address GetIP() const
static void SetDefaultIpAddressFamily(int ipAdressFamily)
sockaddr * addr
Definition: ipsock.h:944
bool IsValid() const
Definition: ipsock.h:326
bool IsPrivate() const
Check if the remote address is a private address.
Address()
Create an IPv4 address with the default address: 127.0.0.1 (loopback).