PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pstun.h
Go to the documentation of this file.
1 /*
2  * pstun.h
3  *
4  * STUN client
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 2003 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  * Contributor(s): ______________________________________.
25  */
26 
27 #ifndef PTLIB_PSTUN_H
28 #define PTLIB_PSTUN_H
29 
30 #ifdef P_USE_PRAGMA
31 #pragma interface
32 #endif
33 
34 #include <ptlib.h>
35 
36 #if P_STUN
37 
38 #include <ptclib/pnat.h>
39 #include <ptlib/sockets.h>
40 #include <ptclib/cypher.h>
41 
42 
44 
45 class PSTUNMessage;
46 class PSTUNUDPSocket;
47 
48 class PSTUN {
49  public:
50  enum {
51  DefaultPort = 3478
52  };
53 
54  enum {
55  MinChannelNumber = 0x4000,
56  MaxChannelNumber = 0x7ffe,
57  };
58 
59  PSTUN();
60  virtual ~PSTUN() { }
61 
64  void DoRFC3489Discovery(
65  PNatMethod::NatTypes & natType,
66  PSTUNUDPSocket * socket,
67  const PIPSocketAddressAndPort & serverAddress,
68  PIPSocketAddressAndPort & baseAddressAndPort,
69  PIPSocket::Address & externalAddress,
70  bool externalAddressOnly
71  );
72 
74  PNatMethod::NatTypes & natType,
75  PSTUNMessage & responseI,
76  PSTUNUDPSocket * socket,
77  PIPSocket::Address & externalAddress,
78  bool externalAddressOnly
79  );
80 
81  virtual bool GetFromBindingResponse(
82  const PSTUNMessage & response,
83  PIPSocketAddressAndPort & externalAddress
84  );
85 
86 #if P_SSL
87  virtual int MakeAuthenticatedRequest(
88  PSTUNUDPSocket * socket,
89  PSTUNMessage & request,
90  PSTUNMessage & response
91  );
92 
93  virtual void AppendMessageIntegrity(
94  PSTUNMessage & message
95  );
96 
97  virtual bool ValidateMessageIntegrity(
98  const PSTUNMessage & message
99  );
100 #endif // P_SSL
101 
102  virtual void SetCredentials(
103  const PString & username,
104  const PString & password,
105  const PString & realm
106  );
107 
110  virtual const PTimeInterval GetTimeout() const { return m_replyTimeout; }
111 
114  virtual void SetTimeout(
115  const PTimeInterval & timeout
116  ) { m_replyTimeout = timeout; }
117 
120  virtual PINDEX GetRetries() const { return m_pollRetries; }
121 
124  virtual void SetRetries(
125  PINDEX retries
126  ) { m_pollRetries = retries; }
127 
128  enum IceRole {
133  };
134  virtual void SetIceRole(
135  IceRole role
136  );
137 
138  protected:
140  PSASLString m_userName;
141  PSASLString m_realm;
142  PSASLString m_nonce;
143  PBYTEArray m_password; // text for short term, MD5 for long term
148  uint64_t m_iceTieBreak;
149 };
150 
152 
153 #pragma pack(1)
155 
157 {
158  enum Types {
159  MAPPED_ADDRESS = 0x0001, // RFC 3489 & RFC 5389
160  RESPONSE_ADDRESS = 0x0002, // RFC 3489 & RFC 5389
161  CHANGE_REQUEST = 0x0003, // RFC 3489 & RFC 5389 (added in RFC 5780)
162  SOURCE_ADDRESS = 0x0004, // RFC 3489
163  CHANGED_ADDRESS = 0x0005, // RFC 3489
164  USERNAME = 0x0006, // RFC 3489 & RFC 5389
165  PASSWORD = 0x0007, // RFC 3489 (deprecated)
166  MESSAGE_INTEGRITY = 0x0008, // RFC 3489 & RFC 5389
167  ERROR_CODE = 0x0009, // RFC 3489 & RFC 5389
168  UNKNOWN_ATTRIBUTES = 0x000a, // RFC 3489 & RFC 5389
169  REFLECTED_FROM = 0x000b, // RFC 3489
170 
171  CHANNEL_NUMBER = 0x000C, // RFC 5766
172  LIFETIME = 0x000D, // RFC 5766
173  //BANDWIDTH = 0x0010,
174  XOR_PEER_ADDRESS = 0x0012, // RFC 5766
175  DATA = 0x0013, // RFC 5766
176 
177  REALM = 0x0014, // RFC 5389
178  NONCE = 0x0015, // RFC 5389
179 
180  XOR_RELAYED_ADDRESS = 0x0016, // RFC 5766
181  EVEN_PORT = 0x0018, // RFC 5766
182  REQUESTED_TRANSPORT = 0x0019, // RFC 5766
183  DONT_FRAGMENT = 0x001A, // RFC 5766
184  XOR_MAPPED_ADDRESS = 0x0020, // RFC 5389
185 
186  // TIMER-VAL = 0x0021,
187  RESERVATION_TOKEN = 0x0022, // RFC 5766
188 
189  PRIORITY = 0x0024, // RFC 5245 (ICE)
190  USE_CANDIDATE = 0x0025, // RFC 5245 (ICE)
191  ICE_CONTROLLED = 0x8029, // RFC 5245 (ICE)
192  ICE_CONTROLLING = 0x802A, // RFC 5245 (ICE)
193  ICE_NETWORK_COST = 0xC057, // https://tools.ietf.org/html/draft-thatcher-ice-network-cost-01
194 
195  PADDING = 0x0026, // RFC 5389 (added in RFC 5780)
196  RESPONSE_PORT = 0x0027, // RFC 5389 (added in RFC 5780)
197 
198  FINGERPRINT = 0x8028, // RFC 5389
199 
200  ALTERNATE_SERVER = 0x8023, // RFC 5389
201 
202  RESPONSE_ORIGIN = 0x802b, // RFC 5389 (added in RFC 5780)
203  OTHER_ADDRESS = 0x802c // RFC 5389 (added in RFC 5780)
204  };
205 
206  PUInt16b type;
207  PUInt16b length;
208 
209  PSTUNAttribute(Types newType = ERROR_CODE, size_t len = 0)
210  : type((WORD)newType)
211  , length((WORD)len)
212  {
213  }
214 
215  PSTUNAttribute * GetNext() const;
216 };
217 
218 
220 
221 template <PSTUNAttribute::Types ATTR_TYPE, class PARAMS_TYPE>
222 class PSTUNAttributeTemplate : public PSTUNAttribute, public PARAMS_TYPE
223 {
224  public:
226  : PSTUNAttribute(ATTR_TYPE, sizeof(PARAMS_TYPE))
227  {
228  }
229 
230  PSTUNAttributeTemplate(PARAMS_TYPE parameters)
231  : PSTUNAttribute(ATTR_TYPE, sizeof(PARAMS_TYPE))
232  , PARAMS_TYPE(parameters)
233  {
234  }
235 
236  bool IsValid() const { return type == ATTR_TYPE && length == sizeof(PARAMS_TYPE); }
237 
238  static __inline PSTUNAttributeTemplate * Find(const PSTUNMessage & message);
239 };
240 
241 
243 
245 {
246  protected:
247  BYTE pad;
248  BYTE family;
249  PUInt16b port;
250  BYTE ip[4];
251 
252  public:
255  , pad(0)
256  , family(1)
257  {
258  SetIPAndPort(addrAndPort);
259  }
260 
261  WORD GetPort() const;
262  PIPSocket::Address GetIP() const;
263  void SetIPAndPort(const PIPSocketAddressAndPort & addrAndPort);
264  void GetIPAndPort(PIPSocketAddressAndPort & addrAndPort);
265 
266  protected:
267  enum { SizeofAddressAttribute = sizeof(BYTE)+sizeof(BYTE)+sizeof(WORD)+4 };
268  bool IsValidAddrAttr(Types checkType) const { return type == checkType && length == SizeofAddressAttribute; }
269 };
270 
271 
273 {
274  public:
275  char m_string[763]; // not actually 763, but this will do
276 
277  PSTUNStringAttribute(Types newType, const PString & str)
278  : PSTUNAttribute(newType, str.GetLength())
279  {
280  memcpy(m_string, (const char *)str, length);
281  }
282 
284  {
285  return PString(m_string, length);
286  }
287 
288  bool IsValidStringAttr(Types checkType) const
289  {
290  return (type == checkType) && (length == strlen(m_string));
291  }
292 };
293 
294 
296 {
297  public:
298  BYTE flags[4];
299 
300  PSTUNChangeRequest(bool changeIP = false, bool changePort = false)
301  : PSTUNAttribute(CHANGE_REQUEST, sizeof(flags))
302  {
303  memset(flags, 0, sizeof(flags));
304  SetChangeIP(changeIP);
305  SetChangePort(changePort);
306  }
307 
308  bool IsValid() const { return type == CHANGE_REQUEST && length == sizeof(flags); }
309 
310  bool GetChangeIP() const { return (flags[3]&4) != 0; }
311  void SetChangeIP(bool on) { if (on) flags[3] |= 4; else flags[3] &= ~4; }
312 
313  bool GetChangePort() const { return (flags[3]&2) != 0; }
314  void SetChangePort(bool on) { if (on) flags[3] |= 2; else flags[3] &= ~2; }
315 };
316 
317 
318 #if P_SSL
319 class PSTUNMessageIntegrity : public PSTUNAttribute
320 {
321  public:
322  BYTE m_hmac[PMessageDigestSHA1::DigestLength];
323 
324  PSTUNMessageIntegrity(const BYTE * hmac = NULL)
325  : PSTUNAttribute(MESSAGE_INTEGRITY, sizeof(m_hmac))
326  {
327  if (hmac == NULL)
328  memset(m_hmac, 0, sizeof(m_hmac));
329  else
330  memcpy(m_hmac, hmac, sizeof(m_hmac));
331  }
332 
333  bool IsValid() const { return type == MESSAGE_INTEGRITY && length == sizeof(m_hmac); }
334 };
335 #endif // P_SSL
336 
337 
339  PUInt32b m_crc;
340 };
342 
344  PUInt64b m_tieBreak;
345  PSTUNIceTieBreak(uint64_t tieBreak) { m_tieBreak = tieBreak; }
346 };
349 
351  PUInt32b m_priority;
352 };
354 
356  PUInt16b m_networkId;
357  PUInt16b m_networkCost;
358 };
360 
361 
363 {
364  public:
366  {
367  Initialise();
368  }
369 
370  PSTUNErrorCode(int code, const PString & reason = PString::Empty())
371  {
372  Initialise();
373  SetErrorCode(code, reason);
374  }
375 
376  BYTE m_zero1;
377  BYTE m_zero2;
379  BYTE m_units;
380  char m_reason[256]; // not actually 256, but this will do
381 
382  void Initialise();
383  void SetErrorCode(int code, const PString & reason);
384  int GetErrorCode() const { return (m_hundreds * 100) + m_units; }
385  PString GetReason() { return PString(m_reason); }
386  bool IsValid() const { return (type == ERROR_CODE) && (length == 4 + strlen(m_reason) + 1); }
387 };
388 
390 {
392  { Initialise(); }
393 
394  PUInt16b m_channelNumber;
395  PUInt16b m_rffu;
396 
397  void Initialise();
398 };
399 
401 {
402  PUInt16b msgType;
403  PUInt16b msgLength;
404  BYTE transactionId[16];
405 };
406 
408 #pragma pack()
409 
411 
412 
413 class PSTUNClient;
414 
417 class PSTUNUDPSocket : public PNATUDPSocket
418 {
419  PCLASSINFO(PSTUNUDPSocket, PNATUDPSocket);
420  public:
422  PNatMethod::Component component
423  );
424 
425  virtual const char * GetNatName() const;
426 
427  bool OpenSTUN(PSTUNClient & client);
428  virtual void GetCandidateInfo(PNatCandidate & candidate);
429 
430  bool BaseWriteTo(const void * buf, PINDEX len, const PIPSocketAddressAndPort & ap)
431  { Slice slice((void *)buf, len); return PUDPSocket::InternalWriteTo(&slice, 1, ap); }
432 
433  bool BaseReadFrom(void * buf, PINDEX len, PIPSocketAddressAndPort & ap)
434  { Slice slice(buf, len); return PUDPSocket::InternalReadFrom(&slice, 1, ap); }
435 
436  protected:
437  friend class PSTUN;
438  friend class PSTUNClient;
439 
442 
443  bool InternalGetLocalAddress(PIPSocketAddressAndPort & addr);
444 
445  private:
446  PNatMethod::NatTypes m_natType;
447 };
448 
450 
451 class PSTUNMessage : public PBYTEArray
452 {
453  public:
454  enum MsgType {
456 
457  BindingRequestRFC3489 = 0x10001,
458 
459  BindingRequest = 0x0001,
460  BindingResponse = 0x0101,
461  BindingError = 0x0111,
462 
463  SharedSecretRequest = 0x0002,
464  SharedSecretResponse = 0x0102,
465  SharedSecretError = 0x0112,
466 
467  // RFC 5766
468  Allocate = 0x0003,
469  AllocateResponse = 0x0103,
470  AllocateError = 0x0113,
471 
472  Refresh = 0x0004,
473  RefreshResponse = 0x0104,
474  RefreshError = 0x0114,
475 
476  Send = 0x0016,
477  Data = 0x0017,
478 
479  CreatePermission = 0x0008,
480  CreatePermResponse = 0x0108,
481  CreatePermError = 0x0118,
482 
483  ChannelBind = 0x0009,
484  ChannelBindResponse = 0x0109,
485  ChannelBindError = 0x0119,
486 
487  // RFC6062
488  Connect = 0x000a,
489  ConnectResponse = 0x010a,
490  ConnectError = 0x011a,
491 
492  ConnectionBind = 0x000b,
493  ConnectionBindResponse= 0x010b,
494  ConnectionBindError = 0x011b,
495 
496  ConnectionAttempt = 0x001c,
497  };
498 
499  PSTUNMessage();
500  PSTUNMessage(MsgType newType, const BYTE * id = NULL);
501  PSTUNMessage(const BYTE * data, PINDEX size, const PIPSocketAddressAndPort & srcAddr);
502 
503 #if PTRACING
504  void PrintOn(ostream & strm) const;
505 #endif
506 
507  bool IsValid() const;
508  bool IsValidFor(const PSTUNMessage & request) const;
509 
510  PBYTEArray GetTransactionID() const;
511 
512  bool IsRFC5389() const;
513 
514  const PSTUNMessageHeader * operator->() const { return (const PSTUNMessageHeader *)theArray; }
515 
516  MsgType GetType() const;
517  void SetType(MsgType newType, const BYTE * id = NULL);
518  void SetErrorType(int code, const BYTE * id, const char * reason = NULL);
519 
520  bool IsRequest() const { return (GetType() & 0x0110) == 0x0000; }
521  bool IsIndication() const { return (GetType() & 0x0110) == 0x0010; }
522  bool IsSuccessResponse() const { return (GetType() & 0x0110) == 0x0100; }
523  bool IsErrorResponse() const { return (GetType() & 0x0110) == 0x0110; }
524 
525  PSTUNAttribute * AddAttribute(const PSTUNAttribute & attribute);
526  PSTUNAttribute * SetAttribute(const PSTUNAttribute & attribute);
527  PSTUNAttribute * FindAttribute(PSTUNAttribute::Types type) const;
528 
529  template <class Type> Type * FindAttributeAs(PSTUNAttribute::Types type) const
530  { return static_cast<Type *>(FindAttribute(type)); }
531 
532  PString FindAttributeString(PSTUNAttribute::Types type, const char * dflt = NULL) const;
533 
534  bool Read(PUDPSocket & socket);
535  bool Write(PUDPSocket & socket) const;
536  bool Write(PUDPSocket & socket, const PIPSocketAddressAndPort & ap) const;
537  bool Poll(PUDPSocket & socket, const PSTUNMessage & request, PINDEX pollRetries);
538 
539  const PIPSocketAddressAndPort GetSourceAddressAndPort() const { return m_sourceAddressAndPort; }
540 
541 #if P_SSL
542  void AddMessageIntegrity(const PBYTEArray & credentialsHash) { AddMessageIntegrity(credentialsHash, credentialsHash.GetSize()); }
543  void AddMessageIntegrity(const BYTE * credentialsHashPtr, PINDEX credentialsHashLen, PSTUNMessageIntegrity * mi = NULL);
544 
545  unsigned CheckMessageIntegrity(const PBYTEArray & credentialsHash) const { return CheckMessageIntegrity(credentialsHash, credentialsHash.GetSize()); }
546  unsigned CheckMessageIntegrity(const BYTE * credentialsHashPtr, PINDEX credentialsHashLen) const;
547 #endif // P_SSL
548 
549  void AddFingerprint(PSTUNFingerprint * fp = NULL);
550  bool CheckFingerprint(bool required) const;
551 
552  protected:
553  PSTUNAttribute * GetFirstAttribute() const;
554 #if P_SSL
555  void CalculateMessageIntegrity(const BYTE * credentialsHash, PINDEX credentialsHashLen,
556  PSTUNMessageIntegrity * mi, BYTE * hmacPtr, PINDEX hmacSize) const;
557 #endif // P_SSL
558  DWORD CalculateFingerprint(PSTUNFingerprint * fp) const;
559 
561 };
562 
563 
564 template <PSTUNAttribute::Types ATTR_TYPE, typename PARAMS_TYPE>
566 {
567  PSTUNAttributeTemplate * attribute = message.FindAttributeAs<PSTUNAttributeTemplate>(ATTR_TYPE);
568  return attribute != NULL && attribute->IsValid() ? attribute : NULL;
569 }
570 
571 
573 
576 class PSTUNClient : public PNatMethod, public PSTUN
577 {
578  PCLASSINFO(PSTUNClient, PNatMethod);
579  public:
580  enum { DefaultPriority = 40 };
581  PSTUNClient(unsigned priority = DefaultPriority);
582  ~PSTUNClient();
583 
586  static const char * MethodName();
587  virtual PCaselessString GetMethodName() const;
588 
592  virtual void SetCredentials(
593  const PString & username,
594  const PString & password,
595  const PString & realm
596  );
597 
604  bool SetServer(
605  const PString & server
606  );
607 
611  virtual PString GetServer() const;
612 
613  virtual bool GetInterfaceAddress(
614  PIPSocket::Address & internalAddress
615  ) const;
616 
617  virtual bool Open(
618  const PIPSocket::Address & ifaceAddr
619  );
620 
621  virtual bool IsAvailable(
622  const PIPSocket::Address & binding,
623  PObject * userData
624  );
625 
626  virtual void Close();
627 
640  virtual bool CreateSocket(
641  PUDPSocket * & socket,
643  WORD localPort = 0,
644  PObject * context = NULL,
645  Component component = eComponent_Unknown
646  );
647 
661  virtual bool CreateSocketPair(
662  PUDPSocket * & socket1,
663  PUDPSocket * & socket2,
665  PObject * context = NULL
666  );
667 
668  protected:
669  virtual bool InternalGetServerAddress(PIPSocketAddressAndPort & externalAddressAndPort) const;
670  virtual PNATUDPSocket * InternalCreateSocket(Component component, PObject * context);
671  virtual void InternalUpdate(bool externalAddressOnly);
672  bool InternalSetServer(const PString & server, const PIPSocketAddressAndPort & addr PTRACE_PARAM(, const char * source));
673 
675 
676  private:
677  PString m_serverName;
678  PINDEX m_numSocketsForPairing;
679 };
680 
681 
683 
684 #if P_TURN
685 
689 class PTURNRequestedTransport : public PSTUNAttribute
690 {
691  public:
692  enum {
693  ProtocolUDP = IPPROTO_UDP,
694  ProtocolTCP = IPPROTO_TCP
695  };
696  BYTE m_protocol;
697  BYTE m_rffu1;
698  BYTE m_rffu2;
699  BYTE m_rffu3;
700 
701  PTURNRequestedTransport(BYTE protocol = ProtocolUDP)
702  { Initialise(protocol); }
703 
704  void Initialise(BYTE protocol = ProtocolUDP);
705  bool IsValid() const { return (type == REQUESTED_TRANSPORT) && (length == 4); }
706 };
707 
708 
709 class PTURNLifetime : public PSTUNAttribute
710 {
711  public:
712  PUInt32b m_lifetime;
713 
714  PTURNLifetime(DWORD lifetime = 600)
715  : m_lifetime(lifetime)
716  { type = LIFETIME; length = 4; }
717 
718  bool IsValid() const { return (type == LIFETIME) && (length == 8); }
719 
720  DWORD GetLifetime() const { return m_lifetime; }
721 };
722 
723 
724 class PTURNEvenPort : public PSTUNAttribute
725 {
726  public:
727  BYTE m_bits;
728 
729  PTURNEvenPort(bool evenPort = true)
730  { type = EVEN_PORT; m_bits = evenPort ? 1 : 0; length = 1; }
731 
732  bool IsValid() const { return (type == EVEN_PORT) && (length == 1); }
733 
734  bool IsEven() const { return (m_bits & 1) != 0; }
735 };
736 
738 
739 class PTURNClient;
740 
741 #pragma pack(1)
742 
743 struct PTURNChannelHeader {
744  PUInt16b m_channelNumber;
745  PUInt16b m_length;
746 };
747 
748 #pragma pack()
749 
750 class PTURNUDPSocket : public PSTUNUDPSocket, public PSTUN
751 {
752  public:
753 
754  friend class PTURNClient;
755 
756  PTURNUDPSocket(
757  PNatMethod::Component component
758  );
759  ~PTURNUDPSocket();
760 
761  virtual const char * GetNatName() const;
762 
763  virtual bool Close();
764 
765  virtual void GetCandidateInfo(PNatCandidate & candidate);
766 
767  int OpenTURN(PTURNClient & client);
768 
769  protected:
770  bool InternalGetLocalAddress(PIPSocketAddressAndPort & addr);
771  bool InternalWriteTo(const Slice * slices, size_t sliceCount, const PIPSocketAddressAndPort & ipAndPort);
772  bool InternalReadFrom(Slice * slices, size_t sliceCount, PIPSocketAddressAndPort & ipAndPort);
773  bool InternalSetSendAddress(const PIPSocketAddressAndPort & addr, int mtuDiscovery = -1);
774  void InternalGetSendAddress(PIPSocketAddressAndPort & addr);
775 
776  bool m_allocationMade;
777  int m_channelNumber;
778  bool m_usingTURN;
779 
780  BYTE m_protocol;
781  PIPSocketAddressAndPort m_relayedAddress;
782  DWORD m_lifeTime;
783  PIPSocketAddressAndPort m_peerIpAndPort;
784 
785  std::vector<Slice> m_txVect;
786  PTURNChannelHeader m_txHeader;
787  BYTE m_txPadding[4];
788 
789  std::vector<Slice> m_rxVect;
790  PTURNChannelHeader m_rxHeader;
791  BYTE m_rxPadding[4];
792 };
793 
795 
796 class PTURNClient : public PSTUNClient
797 {
798  PCLASSINFO(PTURNClient, PSTUNClient);
799  public:
800 
801  friend class PTURNUDPSocket;
802 
805  static const char * MethodName();
806  virtual PCaselessString GetMethodName() const;
807 
808  enum { DefaultPriority = 30 };
809  PTURNClient(unsigned priority = DefaultPriority);
810 
811  // overrides from PNatMethod
812  bool CreateSocket(
813  PUDPSocket * & socket,
815  WORD localPort = 0,
816  PObject * context = NULL,
817  Component component = eComponent_Unknown
818  );
819 
820  bool CreateSocketPair(
821  PUDPSocket * & socket1,
822  PUDPSocket * & socket2,
824  PObject * context = NULL
825  );
826 
830  virtual RTPSupportTypes GetRTPSupport(
831  bool force = false
832  );
833 
834  protected:
835  virtual PNATUDPSocket * InternalCreateSocket(Component component, PObject * context);
836  // New functions
837  virtual bool RefreshAllocation(DWORD lifetime = 600);
838 };
839 
840 
841 #endif // P_TURN
842 
843 #endif // P_STUN
844 
845 #endif // PTLIB_PSTUN_H
Definition: pstun.h:181
PIPSocket::Address GetIP() const
MXRecord * GetNext()
virtual ~PSTUN()
Definition: pstun.h:60
MsgType
Definition: pstun.h:454
BYTE family
Definition: pstun.h:248
PSTUNAttributeTemplate< PSTUNAttribute::FINGERPRINT, PSTUNFingerprintCRC > PSTUNFingerprint
Definition: pstun.h:341
Definition: pstun.h:338
int GetErrorCode() const
Definition: pstun.h:384
bool GetChangeIP() const
Definition: pstun.h:310
Definition: pstun.h:343
BYTE ip[4]
Definition: pstun.h:250
PUInt16b msgType
Definition: pstun.h:402
PSTUNAttributeTemplate< PSTUNAttribute::ICE_CONTROLLING, PSTUNIceTieBreak > PSTUNIceControlling
Definition: pstun.h:348
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:51
Definition: pstun.h:132
bool IsValid() const
Definition: pstun.h:386
virtual bool InternalWriteTo(const Slice *slices, size_t sliceCount, const PIPSocketAddressAndPort &ipAndPort)
PSTUNAttributeTemplate< PSTUNAttribute::PRIORITY, PSTUNIcePriorityValue > PSTUNIcePriority
Definition: pstun.h:353
bool IsValid() const
Definition: pstun.h:308
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
virtual void SetCredentials(const PString &username, const PString &password, const PString &realm)
Type * FindAttributeAs(PSTUNAttribute::Types type) const
Definition: pstun.h:529
Definition: pstun.h:295
#define PTRACE_PARAM(...)
Definition: object.h:935
Definition: pstun.h:167
PUInt16b port
Definition: pstun.h:249
PSTUNAttributeTemplate< PSTUNAttribute::ICE_NETWORK_COST, PSTUNIceNetworkCostParams > PSTUNIceNetworkCost
Definition: pstun.h:359
PIPSocketAddressAndPort m_baseAddressAndPort
Definition: pstun.h:441
void GetIPAndPort(PIPSocketAddressAndPort &addrAndPort)
A socket channel that uses the UDP transport on the Internet Protocol.
Definition: udpsock.h:42
STUN client.
Definition: pstun.h:576
PSTUNAttribute(Types newType=ERROR_CODE, size_t len=0)
Definition: pstun.h:209
bool IsErrorResponse() const
Definition: pstun.h:523
void SetChangeIP(bool on)
Definition: pstun.h:311
BYTE pad
Definition: pstun.h:247
Definition: pstun.h:48
PIPSocketAddressAndPort m_sourceAddressAndPort
Definition: pstun.h:560
virtual void SetRetries(PINDEX retries)
Set the number of retries for responses from STUN server.
Definition: pstun.h:124
PIPSocketAddressAndPort m_serverReflexiveAddress
Definition: pstun.h:440
Definition: pstun.h:272
Definition: pstun.h:455
This class is a variation of a string that ignores case.
Definition: pstring.h:2012
PSTUNStringAttribute(Types newType, const PString &str)
Definition: pstun.h:277
Definition: pstun.h:355
bool BaseReadFrom(void *buf, PINDEX len, PIPSocketAddressAndPort &ap)
Definition: pstun.h:433
#define P_POP_MSVC_WARNINGS()
Definition: object.h:154
PSASLString m_userName
Definition: pstun.h:140
PString GetReason()
Definition: pstun.h:385
bool IsValidStringAttr(Types checkType) const
Definition: pstun.h:288
WORD GetPort() const
Definition: pstun.h:451
PUInt64b m_tieBreak
Definition: pstun.h:344
A class describing an IP address and port number combination.
Definition: ipsock.h:278
bool GetChangePort() const
Definition: pstun.h:313
PUInt32b m_priority
Definition: pstun.h:351
Definition: pstun.h:400
Definition: pstun.h:55
PINDEX m_pollRetries
Definition: pstun.h:139
Definition: pstun.h:130
void FinishRFC3489Discovery(PNatMethod::NatTypes &natType, PSTUNMessage &responseI, PSTUNUDPSocket *socket, PIPSocket::Address &externalAddress, bool externalAddressOnly)
Definition: pstun.h:350
PUInt32b m_crc
Definition: pstun.h:339
static __inline PSTUNAttributeTemplate * Find(const PSTUNMessage &message)
Definition: pstun.h:565
PUInt16b m_rffu
Definition: pstun.h:395
virtual bool InternalReadFrom(Slice *slices, size_t sliceCount, PIPSocketAddressAndPort &ipAndPort)
bool IsValid() const
Definition: pstun.h:236
Array of unsigned characters.
Definition: array.h:605
PIPSocket::Address m_interface
Definition: pstun.h:144
void SetChangePort(bool on)
Definition: pstun.h:314
PSTUNAddressAttribute(Types newType, const PIPSocketAddressAndPort &addrAndPort)
Definition: pstun.h:253
uint64_t m_iceTieBreak
Definition: pstun.h:148
Types
Definition: pstun.h:158
Definition: pstun.h:244
PSTUNAttributeTemplate()
Definition: pstun.h:225
IceRole
Definition: pstun.h:128
Definition: pstun.h:222
virtual PINDEX GetSize() const
Get the current size of the container.
void DoRFC3489Discovery(PNatMethod::NatTypes &natType, PSTUNUDPSocket *socket, const PIPSocketAddressAndPort &serverAddress, PIPSocketAddressAndPort &baseAddressAndPort, PIPSocket::Address &externalAddress, bool externalAddressOnly)
Determine the NAT type using RFC3489 discovery method.
Definition: pstun.h:129
Definition: pstun.h:56
virtual PINDEX GetRetries() const
Get the number of retries for responses from STUN server.
Definition: pstun.h:120
PString GetString() const
Definition: pstun.h:283
const PIPSocketAddressAndPort GetSourceAddressAndPort() const
Definition: pstun.h:539
PSASLString m_realm
Definition: pstun.h:141
Definition: pstun.h:131
The character string class.
Definition: pstring.h:108
#define P_PUSH_MSVC_WARNINGS(warnings)
Definition: object.h:153
bool IsSuccessResponse() const
Definition: pstun.h:522
PSTUNErrorCode()
Definition: pstun.h:365
PSTUNUDPSocket * m_socket
Definition: pstun.h:674
PBYTEArray m_password
Definition: pstun.h:143
virtual void SetIceRole(IceRole role)
BYTE m_zero2
Definition: pstun.h:377
PSTUNChannelNumber()
Definition: pstun.h:391
PSTUNAttributeTemplate(PARAMS_TYPE parameters)
Definition: pstun.h:230
Definition: pstun.h:362
Definition: pstun.h:156
BYTE m_hundreds
Definition: pstun.h:378
Definition: pstun.h:166
Definition: pstun.h:161
static const PString & Empty()
Return an empty string.
bool IsIndication() const
Definition: pstun.h:521
A class describing an IP address.
Definition: ipsock.h:59
bool IsValidAddrAttr(Types checkType) const
Definition: pstun.h:268
PUInt16b msgLength
Definition: pstun.h:403
void SetIPAndPort(const PIPSocketAddressAndPort &addrAndPort)
PIPSocketAddressAndPort m_serverAddress
Definition: pstun.h:145
static const PIPSocket::Address & GetDefaultIpAny()
PSTUNChangeRequest(bool changeIP=false, bool changePort=false)
Definition: pstun.h:300
virtual void SetTimeout(const PTimeInterval &timeout)
Set the timeout for responses from STUN server.
Definition: pstun.h:114
BYTE m_units
Definition: pstun.h:379
const PSTUNMessageHeader * operator->() const
Definition: pstun.h:514
IceRole m_iceRole
Definition: pstun.h:147
PSTUNIceTieBreak(uint64_t tieBreak)
Definition: pstun.h:345
Definition: pstun.h:389
virtual bool GetFromBindingResponse(const PSTUNMessage &response, PIPSocketAddressAndPort &externalAddress)
Definition: pstun.h:51
PUInt16b m_channelNumber
Definition: pstun.h:394
PUInt16b m_networkCost
Definition: pstun.h:357
PSASLString m_nonce
Definition: pstun.h:142
bool IsRequest() const
Definition: pstun.h:520
PUInt16b m_networkId
Definition: pstun.h:356
PSTUNAttributeTemplate< PSTUNAttribute::ICE_CONTROLLED, PSTUNIceTieBreak > PSTUNIceControlled
Definition: pstun.h:347
Definition: pstun.h:172
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
UDP socket that has been created by the STUN client.
Definition: pstun.h:417
PTimeInterval m_replyTimeout
Definition: pstun.h:146
BYTE m_zero1
Definition: pstun.h:376
bool BaseWriteTo(const void *buf, PINDEX len, const PIPSocketAddressAndPort &ap)
Definition: pstun.h:430
PUInt16b type
Definition: pstun.h:206
PUInt16b length
Definition: pstun.h:207
virtual const PTimeInterval GetTimeout() const
Get the timeout for responses from STUN server.
Definition: pstun.h:110
void PrintOn(ostream &strm) const