65 PNatMethod::NatTypes & natType,
70 bool externalAddressOnly
74 PNatMethod::NatTypes & natType,
78 bool externalAddressOnly
87 virtual int MakeAuthenticatedRequest(
93 virtual void AppendMessageIntegrity(
97 virtual bool ValidateMessageIntegrity(
159 MAPPED_ADDRESS = 0x0001,
160 RESPONSE_ADDRESS = 0x0002,
161 CHANGE_REQUEST = 0x0003,
162 SOURCE_ADDRESS = 0x0004,
163 CHANGED_ADDRESS = 0x0005,
166 MESSAGE_INTEGRITY = 0x0008,
168 UNKNOWN_ATTRIBUTES = 0x000a,
169 REFLECTED_FROM = 0x000b,
171 CHANNEL_NUMBER = 0x000C,
174 XOR_PEER_ADDRESS = 0x0012,
180 XOR_RELAYED_ADDRESS = 0x0016,
182 REQUESTED_TRANSPORT = 0x0019,
183 DONT_FRAGMENT = 0x001A,
184 XOR_MAPPED_ADDRESS = 0x0020,
187 RESERVATION_TOKEN = 0x0022,
190 USE_CANDIDATE = 0x0025,
191 ICE_CONTROLLED = 0x8029,
192 ICE_CONTROLLING = 0x802A,
193 ICE_NETWORK_COST = 0xC057,
196 RESPONSE_PORT = 0x0027,
198 FINGERPRINT = 0x8028,
200 ALTERNATE_SERVER = 0x8023,
202 RESPONSE_ORIGIN = 0x802b,
203 OTHER_ADDRESS = 0x802c
210 : type((WORD)newType)
215 PSTUNAttribute *
GetNext()
const;
221 template <PSTUNAttribute::Types ATTR_TYPE,
class PARAMS_TYPE>
232 , PARAMS_TYPE(parameters)
280 memcpy(m_string, (
const char *)str,
length);
290 return (
type == checkType) && (
length == strlen(m_string));
303 memset(flags, 0,
sizeof(flags));
304 SetChangeIP(changeIP);
305 SetChangePort(changePort);
311 void SetChangeIP(
bool on) {
if (on) flags[3] |= 4;
else flags[3] &= ~4; }
322 BYTE m_hmac[PMessageDigestSHA1::DigestLength];
324 PSTUNMessageIntegrity(
const BYTE * hmac = NULL)
328 memset(m_hmac, 0,
sizeof(m_hmac));
330 memcpy(m_hmac, hmac,
sizeof(m_hmac));
373 SetErrorCode(code, reason);
383 void SetErrorCode(
int code,
const PString & reason);
404 BYTE transactionId[16];
422 PNatMethod::Component component
425 virtual const char * GetNatName()
const;
428 virtual void GetCandidateInfo(PNatCandidate & candidate);
446 PNatMethod::NatTypes m_natType;
457 BindingRequestRFC3489 = 0x10001,
459 BindingRequest = 0x0001,
460 BindingResponse = 0x0101,
461 BindingError = 0x0111,
463 SharedSecretRequest = 0x0002,
464 SharedSecretResponse = 0x0102,
465 SharedSecretError = 0x0112,
469 AllocateResponse = 0x0103,
470 AllocateError = 0x0113,
473 RefreshResponse = 0x0104,
474 RefreshError = 0x0114,
479 CreatePermission = 0x0008,
480 CreatePermResponse = 0x0108,
481 CreatePermError = 0x0118,
483 ChannelBind = 0x0009,
484 ChannelBindResponse = 0x0109,
485 ChannelBindError = 0x0119,
489 ConnectResponse = 0x010a,
490 ConnectError = 0x011a,
492 ConnectionBind = 0x000b,
493 ConnectionBindResponse= 0x010b,
494 ConnectionBindError = 0x011b,
496 ConnectionAttempt = 0x001c,
504 void PrintOn(ostream & strm)
const;
507 bool IsValid()
const;
512 bool IsRFC5389()
const;
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);
520 bool IsRequest()
const {
return (GetType() & 0x0110) == 0x0000; }
530 {
return static_cast<Type *
>(FindAttribute(type)); }
542 void AddMessageIntegrity(
const PBYTEArray & credentialsHash) { AddMessageIntegrity(credentialsHash, credentialsHash.
GetSize()); }
543 void AddMessageIntegrity(
const BYTE * credentialsHashPtr, PINDEX credentialsHashLen, PSTUNMessageIntegrity * mi = NULL);
545 unsigned CheckMessageIntegrity(
const PBYTEArray & credentialsHash)
const {
return CheckMessageIntegrity(credentialsHash, credentialsHash.
GetSize()); }
546 unsigned CheckMessageIntegrity(
const BYTE * credentialsHashPtr, PINDEX credentialsHashLen)
const;
550 bool CheckFingerprint(
bool required)
const;
555 void CalculateMessageIntegrity(
const BYTE * credentialsHash, PINDEX credentialsHashLen,
556 PSTUNMessageIntegrity * mi, BYTE * hmacPtr, PINDEX hmacSize)
const;
564 template <PSTUNAttribute::Types ATTR_TYPE,
typename PARAMS_TYPE>
568 return attribute != NULL && attribute->
IsValid() ? attribute : NULL;
580 enum { DefaultPriority = 40 };
586 static const char * MethodName();
592 virtual void SetCredentials(
611 virtual PString GetServer()
const;
613 virtual bool GetInterfaceAddress(
621 virtual bool IsAvailable(
626 virtual void Close();
640 virtual bool CreateSocket(
645 Component component = eComponent_Unknown
661 virtual bool CreateSocketPair(
670 virtual PNATUDPSocket * InternalCreateSocket(Component component,
PObject * context);
671 virtual void InternalUpdate(
bool externalAddressOnly);
678 PINDEX m_numSocketsForPairing;
693 ProtocolUDP = IPPROTO_UDP,
694 ProtocolTCP = IPPROTO_TCP
701 PTURNRequestedTransport(BYTE protocol = ProtocolUDP)
702 { Initialise(protocol); }
704 void Initialise(BYTE protocol = ProtocolUDP);
714 PTURNLifetime(DWORD lifetime = 600)
715 : m_lifetime(lifetime)
720 DWORD GetLifetime()
const {
return m_lifetime; }
729 PTURNEvenPort(
bool evenPort =
true)
734 bool IsEven()
const {
return (m_bits & 1) != 0; }
743 struct PTURNChannelHeader {
744 PUInt16b m_channelNumber;
754 friend class PTURNClient;
757 PNatMethod::Component component
761 virtual const char * GetNatName()
const;
763 virtual bool Close();
765 virtual void GetCandidateInfo(PNatCandidate & candidate);
767 int OpenTURN(PTURNClient & client);
776 bool m_allocationMade;
785 std::vector<Slice> m_txVect;
786 PTURNChannelHeader m_txHeader;
789 std::vector<Slice> m_rxVect;
790 PTURNChannelHeader m_rxHeader;
801 friend class PTURNUDPSocket;
805 static const char * MethodName();
808 enum { DefaultPriority = 30 };
809 PTURNClient(
unsigned priority = DefaultPriority);
817 Component component = eComponent_Unknown
820 bool CreateSocketPair(
830 virtual RTPSupportTypes GetRTPSupport(
835 virtual PNATUDPSocket * InternalCreateSocket(Component component,
PObject * context);
837 virtual bool RefreshAllocation(DWORD lifetime = 600);
845 #endif // PTLIB_PSTUN_H
PIPSocket::Address GetIP() const
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
int GetErrorCode() const
Definition: pstun.h:384
bool GetChangeIP() const
Definition: pstun.h:310
BYTE ip[4]
Definition: pstun.h:250
PSTUNAttributeTemplate< PSTUNAttribute::ICE_CONTROLLING, PSTUNIceTieBreak > PSTUNIceControlling
Definition: pstun.h:348
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:51
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
#define PTRACE_PARAM(...)
Definition: object.h:935
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
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
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
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
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
PINDEX m_pollRetries
Definition: pstun.h:139
void FinishRFC3489Discovery(PNatMethod::NatTypes &natType, PSTUNMessage &responseI, PSTUNUDPSocket *socket, PIPSocket::Address &externalAddress, bool externalAddressOnly)
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
PSTUNAttributeTemplate()
Definition: pstun.h:225
IceRole
Definition: pstun.h:128
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.
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
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
BYTE m_hundreds
Definition: pstun.h:378
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
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
virtual bool GetFromBindingResponse(const PSTUNMessage &response, PIPSocketAddressAndPort &externalAddress)
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
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