PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ipsock.h
Go to the documentation of this file.
1 /*
2  * ipsock.h
3  *
4  * Internet Protocol socket I/O channel class.
5  *
6  * Portable Tools Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  */
29 
30 #ifndef PTLIB_IPSOCKET_H
31 #define PTLIB_IPSOCKET_H
32 
33 #ifdef P_USE_PRAGMA
34 #pragma interface
35 #endif
36 
37 #include <ptlib/socket.h>
38 
39 
47 class PIPSocket : public PSocket
48 {
49  PCLASSINFO(PIPSocket, PSocket);
50  protected:
54  PIPSocket();
55 
56  public:
59  class Address : public PObject {
60  PCLASSINFO_WITH_CLONE(Address, PObject);
61  public:
62 
65  Address();
67 
71  explicit Address(const PString & dotNotation);
72 
74  Address(PINDEX len, const BYTE * bytes, int scope = 0);
75 
77  Address(BYTE b1, BYTE b2, BYTE b3, BYTE b4);
78 
80  Address(DWORD dw);
81 
83  Address(const in_addr & addr);
84 
85 #if P_HAS_IPV6
86  Address(const in6_addr & addr);
88  Address(const in6_addr & addr, int scope);
89 #endif
90 
93  Address(const int ai_family, const int ai_addrlen,struct sockaddr *ai_addr);
94 
95 #ifdef __NUCLEUS_NET__
96  Address(const struct id_struct & addr);
97  Address & operator=(const struct id_struct & addr);
98 #endif
99 
101  Address & operator=(const in_addr & addr);
102 
103 #if P_HAS_IPV6
104  Address & AssignIPV6(const in6_addr & addr, int scope);
106 #endif
107 
109  Address & operator=(const PString & dotNotation);
110 
112  Address & operator=(DWORD dw);
114 
116  Comparison Compare(const PObject & obj) const;
117  bool operator==(const Address & addr) const { return Compare(addr) == EqualTo; }
118  bool operator!=(const Address & addr) const { return Compare(addr) != EqualTo; }
119 #if P_HAS_IPV6
120  bool operator ==(in6_addr & addr) const;
121  bool operator !=(in6_addr & addr) const { return !operator==(addr); }
122 
123  bool EqualIPV6(in6_addr & addr, int scope) const;
124  bool NotEqualIPV6(in6_addr & addr, int scope) const { return !EqualIPV6(addr, scope); }
125 #endif
126  bool operator==(in_addr & addr) const;
127  bool operator!=(in_addr & addr) const { return !operator==(addr); }
128  bool operator==(DWORD dw) const;
129  bool operator!=(DWORD dw) const { return !operator==(dw); }
130 #ifdef P_VXWORKS
131  bool operator==(long unsigned int u) const { return operator==((DWORD)u); }
132  bool operator!=(long unsigned int u) const { return !operator==((DWORD)u); }
133 #endif
134 #ifdef _WIN32
135  bool operator==(unsigned u) const { return operator==((DWORD)u); }
136  bool operator!=(unsigned u) const { return !operator==((DWORD)u); }
137 #endif
138 #ifdef P_RTEMS
139  bool operator==(u_long u) const { return operator==((DWORD)u); }
140  bool operator!=(u_long u) const { return !operator==((DWORD)u); }
141 #endif
142 #ifdef P_BEOS
143  bool operator==(in_addr_t a) const { return operator==((DWORD)a); }
144  bool operator!=(in_addr_t a) const { return !operator==((DWORD)a); }
145 #endif
146  bool operator==(int i) const { return operator==((DWORD)i); }
147  bool operator!=(int i) const { return !operator==((DWORD)i); }
148 
151 #if P_HAS_IPV6
152  bool operator*=(const Address & addr) const;
153 #else
154  bool operator*=(const Address & addr) const { return operator==(addr); }
155 #endif
156 
159  bool bracketIPv6 = false,
160  bool excludeScope = false
161  ) const;
162 
165  const PString & str
166  );
167 
169  operator PString() const;
170 
172  operator in_addr() const;
173 
174 #if P_HAS_IPV6
175  operator in6_addr() const;
177 
178  int GetIPV6Scope() const { return m_scope6; }
179 #endif
180 
182  operator DWORD() const;
183 
185  BYTE Byte1() const;
186 
188  BYTE Byte2() const;
189 
191  BYTE Byte3() const;
192 
194  BYTE Byte4() const;
195 
197  BYTE operator[](PINDEX idx) const;
198 
200  PINDEX GetSize() const;
201 
203  const char * GetPointer() const { return (const char *)&m_v; }
204 
206  unsigned GetVersion() const { return m_version; }
207 
209  bool IsValid() const { return m_version == 4 || m_version == 6; }
211  bool IsAny() const;
212 
214  bool IsLoopback() const;
215 
217  bool IsBroadcast() const;
218 
220  bool IsMulticast() const;
221 
223  bool IsSubNet(const Address & network, const Address & mask) const;
224 
235  bool IsPrivate() const;
236  P_DEPRECATED bool IsRFC1918() const { return IsPrivate(); }
237 
238 #if P_HAS_IPV6
239  bool IsV4Mapped() const;
241 
243  bool IsLinkLocal() const;
244 
246  bool IsSiteLocal() const;
247 #endif
248 
249  static const Address & GetLoopback(unsigned version = 4);
250  static const Address & GetAny(unsigned version = 4);
251  static const Address GetBroadcast(unsigned version = 4);
252 
253  protected:
255  union {
256  in_addr m_four;
257 #if P_HAS_IPV6
258  in6_addr m_six;
259 #endif
260  } m_v;
261  unsigned m_version;
262  int m_scope6;
263 
270  friend ostream & operator<<(ostream & s, const Address & a);
271 
273  friend istream & operator>>(istream & s, Address & a);
274  };
275 
278  class AddressAndPort : public PObject
279  {
280  public:
282  char separator = ':'
283  );
285  WORD defaultPort,
286  char separator = ':'
287  );
289  const PString & str,
290  WORD defaultPort = 0,
291  char separator = ':',
292  const char * proto = NULL
293  );
295  const PIPSocket::Address & addr,
296  WORD defaultPort = 0,
297  char separator = ':'
298  );
300  struct sockaddr *ai_addr,
301  const int ai_addrlen
302  );
303 
304  bool Parse(
305  const PString & str,
306  WORD defaultPort = 0,
307  char separator = ':',
308  const char * proto = NULL
309  );
310 
311  PString AsString(char separator = 0) const;
312 
313  const PIPSocket::Address & GetAddress() const { return m_address; }
314 
315  void SetAddress(
316  const PIPSocket::Address & addr,
317  WORD port = 0
318  );
319 
320  WORD GetPort() const { return m_port; }
321 
322  void SetPort(
323  WORD port
324  ) { m_port = port; }
325 
326  bool IsValid() const
327  {
328  return m_address.IsValid() && m_port != 0;
329  }
330 
331  virtual void PrintOn(ostream & strm) const
332  {
333  strm << AsString();
334  }
335 
336  virtual Comparison Compare(const PObject & obj) const;
337 
338  bool MatchWildcard(
339  const AddressAndPort & wild
340  ) const;
341 
342  protected:
344  WORD m_port;
346  };
347 
348 
349  //**@name Overrides from class PObject */
351 
353  virtual void PrintOn(
354  ostream &strm
355  ) const;
357 
358  //**@name Overrides from class PChannel */
360 
367  virtual PString GetName() const;
368 
375  static int GetDefaultIpAddressFamily();
376  static void SetDefaultIpAddressFamily(int ipAdressFamily); // PF_INET, PF_INET6
377  static void SetDefaultIpAddressFamilyV4(); // PF_INET
378 #if P_HAS_IPV6
379  static void SetDefaultIpAddressFamilyV6(); // PF_INET6
380  static PBoolean IsIpAddressFamilyV6Supported();
381 #endif
382  static const PIPSocket::Address & GetDefaultIpAny();
383  static const PIPSocket::Address & GetInvalidAddress();
384 
391  static void SetSuppressCanonicalName(bool suppress);
392 
399  static bool GetSuppressCanonicalName();
400 
403  virtual PBoolean OpenSocket(
404  int ipAdressFamily=PF_INET
405  ) = 0;
407 
412  class PortRange {
413  public:
414  PortRange(WORD basePort = 0, WORD maxPort = 0);
415 
417  void Set(
418  unsigned newBase,
419  unsigned newMax,
420  unsigned dfltRange = 0,
421  unsigned dfltBase = 0
422  );
423 
424  bool IsValid() const { return m_base != 0 && m_base <= m_max; }
425  friend ostream & operator<<(ostream & strm, const PortRange & pr) { return strm << pr.m_base << '-' << pr.m_max; }
426 
428  bool Connect(
429  PIPSocket & socket,
430  const Address & addr,
431  const Address & binding = GetDefaultIpAny()
432  );
433 
435  bool Listen(
436  PIPSocket & socket,
437  const Address & binding = GetDefaultIpAny(),
438  unsigned queueSize = 5,
440  );
441  bool Listen(
442  PIPSocket ** sockets,
443  PINDEX numSockets = 1,
444  const Address & binding = GetDefaultIpAny(),
445  unsigned queueSize = 5,
447  );
448 
450  WORD GetBase() const { return m_base; }
451 
453  WORD GetMax() const { return m_max; }
454 
455  protected:
456  PDECLARE_MUTEX(m_mutex);
457  WORD m_base;
458  WORD m_max;
459  };
460 
472  virtual PBoolean Connect(
473  const PString & address
474  );
475  virtual PBoolean Connect(
476  const Address & addr
477  );
478  virtual PBoolean Connect(
479  WORD localPort,
480  const Address & addr
481  );
482  virtual PBoolean Connect(
483  const Address & iface,
484  const Address & addr
485  );
486  virtual PBoolean Connect(
487  const Address & iface,
488  WORD localPort,
489  const Address & addr
490  );
491 
507  virtual PBoolean Listen(
508  unsigned queueSize = 5,
509  WORD port = 0,
511  ) { return InternalListen(GetDefaultIpAny(), queueSize, port, reuse); }
512 
513  virtual PBoolean Listen(
514  const Address & bind,
515  unsigned queueSize = 5,
516  WORD port = 0,
518  ) { return InternalListen(bind, queueSize, port, reuse); }
520 
530  static PString GetHostName();
531  static PString GetHostName(
532  const PString & hostname
533  );
534  static PString GetHostName(
535  const Address & addr
536  );
537 
544  static PBoolean GetHostAddress(
545  Address & addr
546  );
547  static PBoolean GetHostAddress(
548  const PString & hostname,
552  Address & addr
553  );
554 
566  const PString & hostname
567  );
569  const Address & addr
570  /* Name of host to get address for. This may be either a domain name or
571  an IP number in "dot" format.
572  */
573  );
574 
582  static PBoolean IsLocalHost(
586  const PString & hostname
587  );
588 
594  PString GetLocalAddress() const;
595  bool GetLocalAddress(
596  Address & addr
597  ) const;
598  bool GetLocalAddress(
599  Address & addr,
600  WORD & port
601  ) const;
602  bool GetLocalAddress(
603  AddressAndPort & addr
604  ) const;
605 
612  PString GetPeerAddress() const;
613  bool GetPeerAddress(
614  Address & addr
615  ) const;
616  bool GetPeerAddress(
617  Address & addr,
618  WORD & port
619  ) const;
620  bool GetPeerAddress(
621  AddressAndPort & addr
622  ) const;
623 
630 
637 
640  static void ClearNameCache();
641 
644  class RouteEntry : public PObject
645  {
646  PCLASSINFO(RouteEntry, PObject);
647  public:
649  RouteEntry(const Address & addr) : network(addr), metric(0) { }
650 
652  Address GetNetwork() const { return network; }
653 
655  Address GetNetMask() const { return net_mask; }
656 
658  Address GetDestination() const { return destination; }
659 
661  const PString & GetInterface() const { return interfaceName; }
662 
664  long GetMetric() const { return metric; }
665 
667  void PrintOn(ostream & strm) const;
668 
669  protected:
674  long metric;
675 
676  friend class PIPSocket;
677  };
678 
679  PARRAY(RouteTable, RouteEntry);
680 
686  static PBoolean GetRouteTable(
687  RouteTable & table
688  );
689 
692  {
693  public:
694  virtual ~RouteTableDetector() { }
695  virtual bool Wait(
696  const PTimeInterval & timeout
697  ) = 0;
698  virtual void Cancel() = 0;
699  };
700 
709  static RouteTableDetector * CreateRouteTableDetector();
710 
713  class InterfaceEntry : public PObject
714  {
716 
717  public:
719  InterfaceEntry();
721  const PString & name,
722  const Address & addr,
723  const Address & mask,
724  const PString & macAddr
725  );
726 
728  virtual void PrintOn(
729  ostream &strm // Stream to print the object into.
730  ) const;
731 
740  const PString & GetName() const { return m_name; }
741 
743  Address GetAddress() const { return m_ipAddress; }
744 
746  Address GetNetMask() const { return m_netMask; }
747 
749  const PString & GetMACAddress() const { return m_macAddress; }
750 
752  static void SanitiseName(PString & name);
753 
754  protected:
759 
760  friend class PIPSocket;
761  };
762 
763  PARRAY(InterfaceTable, InterfaceEntry);
764 
770  InterfaceTable & table,
771  PBoolean includeDown = false
772  );
773 
776  static PString GetInterface(
777  const Address & addr
778  );
779 
783  const PString & ifName,
784  unsigned version = 4
785  );
786 
790  const char * ifName = NULL
791  );
792 
800  unsigned version = 4
801  );
802 
814  static Address GetGatewayAddress(
815  unsigned version = 4
816  );
817 
830  unsigned version = 4
831  );
832 
845  unsigned version = 4
846  );
847 
856  const Address & remoteAddress
857  );
858 
860  P_DECLARE_ENUM(QoSType,
861  BackgroundQoS,
862  BestEffortQoS,
863  ExcellentEffortQoS,
864  CriticalQoS,
865  VideoQoS,
866  VoiceQoS,
867  ControlQoS
868  );
879  struct QoS
880  {
881  QoS(QoSType type = BestEffortQoS);
882  QoS(const PString & str);
883 
884  QoSType m_type;
885  int m_dscp; // If between 0 and 63, is used instead of default for QoSType.
886 
888 
889  struct Flow {
890  Flow() { memset(this, 0, sizeof(*this)); }
891  unsigned m_maxBandwidth; // bits/second, includes IP overhead
892  unsigned m_maxPacketSize; // Bytes, includes IP overhead
893  unsigned m_maxLatency; // Microseconds
894  unsigned m_maxJitter; // Microseconds
896 
897  friend ostream & operator<<(ostream & strm, const PIPSocket::QoS & qos);
898  friend istream & operator>>(istream & strm, PIPSocket::QoS & qos);
899  };
900 
902  virtual bool SetQoS(
903  const QoS & qos
904  );
905 
907  const QoS & GetQoS() const { return m_qos; }
909 
910  virtual bool InternalGetLocalAddress(AddressAndPort & addrAndPort);
911  virtual bool InternalGetPeerAddress(AddressAndPort & addrAndPort);
912  virtual bool InternalListen(const Address & bind, unsigned queueSize, WORD port, Reusability reuse);
913 
914 // Include platform dependent part of class
915 #ifdef _WIN32
916 #include "msos/ptlib/ipsock.h"
917 #else
918 #include "unix/ptlib/ipsock.h"
919 #endif
920 
921  protected:
923 
925  {
926  public:
928  sockaddr_wrapper(const AddressAndPort & ipPort);
929  sockaddr_wrapper(const Address & ip, WORD port);
930 
931  sockaddr* operator->() const { return addr; }
932  operator sockaddr*() const { return addr; }
933  socklen_t GetSize() const;
934 
935  PIPSocket::Address GetIP() const;
936  WORD GetPort() const;
937 
938  private:
939  void Construct(const Address & ip, WORD port);
940 
941  sockaddr_storage storage;
942  union {
943  sockaddr_storage * ptr;
944  sockaddr * addr;
945  sockaddr_in * addr4;
946  #if P_HAS_IPV6
947  sockaddr_in6 * addr6;
948  #endif
949  };
950  };
951 };
952 
956 
957 typedef std::vector<PIPSocket::AddressAndPort> PIPSocketAddressAndPortVector;
958 
959 
960 #endif // PTLIB_IPSOCKET_H
961 
962 
963 // End Of File ///////////////////////////////////////////////////////////////
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
Definition: socket.h:87
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
Definition: ipsock.h:889
PString GetLocalAddress() const
Get the Internet Protocol address and port for the local host.
friend ostream & operator<<(ostream &s, const Address &a)
Output IPv6 &amp; 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 &quot;Internet&quot;.
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
Definition: ipsock.h:879
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()
Definition: ipsock.h:924
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 &quot;official&quot; 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).