Documentation ¶
Overview ¶
Package stunlib provides an api for parsing and genrating stun packets
Index ¶
- Constants
- func CreateMaskedAddress(tid TransactionID, ua *net.UDPAddr) []byte
- func CreateStunFingerPrint(sp []byte) uint32
- func IsStunPacket(ba []byte) bool
- func SAOptional(sa StunAttribute) bool
- func UnMaskAddress(tid TransactionID, mba []byte) *net.UDPAddr
- func UnmaskIP(tid TransactionID, address []byte) net.IP
- func VerifyFingerPrint(sp StunPacket) bool
- type StunAttribute
- type StunMessage
- type StunPacket
- func (sp *StunPacket) GetAddress() (*net.UDPAddr, error)
- func (sp *StunPacket) GetAllAttributes() []StunAttribute
- func (sp *StunPacket) GetAttribute(sa StunAttribute) []byte
- func (sp *StunPacket) GetBytes() []byte
- func (sp *StunPacket) GetStunMessageType() StunMessage
- func (sp *StunPacket) GetTxID() *TransactionID
- func (sp *StunPacket) HasAddress() bool
- func (sp *StunPacket) HasFingerPrint() bool
- func (sp *StunPacket) ToBuilder() *StunPacketBuilder
- type StunPacketBuilder
- func (spb *StunPacketBuilder) AddFingerprint(fp bool) *StunPacketBuilder
- func (spb *StunPacketBuilder) Build() *StunPacket
- func (spb *StunPacketBuilder) ClearAttributes() *StunPacketBuilder
- func (spb *StunPacketBuilder) SetAddress(ua *net.UDPAddr) *StunPacketBuilder
- func (spb *StunPacketBuilder) SetAttribue(sa StunAttribute, ba []byte) *StunPacketBuilder
- func (spb *StunPacketBuilder) SetPaddingByte(b byte) *StunPacketBuilder
- func (spb *StunPacketBuilder) SetStunMessage(sm StunMessage) *StunPacketBuilder
- func (spb *StunPacketBuilder) SetTXID(txid *TransactionID) *StunPacketBuilder
- func (spb *StunPacketBuilder) SetXORAddress(ua *net.UDPAddr) *StunPacketBuilder
- type TransactionID
Constants ¶
const ( SMRequest StunMessage = 0x0001 SMSuccess StunMessage = 0x0101 SMFailure StunMessage = 0x0111 SMIndication StunMessage = 0x0011 SAMappedAddress StunAttribute = 0x0001 SAResponseAddress StunAttribute = 0x0002 SAChangeRequest StunAttribute = 0x0003 SASourceAddress StunAttribute = 0x0004 SAChangedRequest StunAttribute = 0x0005 SAUsername StunAttribute = 0x0006 SAPassword StunAttribute = 0x0007 SAMessageIntegrity StunAttribute = 0x0008 SAErrorCode StunAttribute = 0x0009 SAUnknownAttribute StunAttribute = 0x000a SAReflectedFrom StunAttribute = 0x000b SARealm StunAttribute = 0x0014 SANonce StunAttribute = 0x0015 SAXORMappedAddress StunAttribute = 0x0020 SAPriority StunAttribute = 0x0024 SAUseCandidate StunAttribute = 0x0025 SASoftware StunAttribute = 0x8022 SAAlternateServer StunAttribute = 0x8023 SAFingerPrint StunAttribute = 0x8028 SAIceControlled StunAttribute = 0x8029 SAIceControlling StunAttribute = 0x802a )
Variables ¶
This section is empty.
Functions ¶
func CreateMaskedAddress ¶ added in v0.0.3
func CreateMaskedAddress(tid TransactionID, ua *net.UDPAddr) []byte
func CreateStunFingerPrint ¶ added in v0.0.3
CreateStunFingerPrint adds s fingerprint to a StunPacket Be very carful with this method the size stun attr need to include the The 8 bytes that will be added as the fingerprint, but the []byte Can not have those bytes
func IsStunPacket ¶
func SAOptional ¶
func SAOptional(sa StunAttribute) bool
func UnMaskAddress ¶ added in v0.0.3
func UnMaskAddress(tid TransactionID, mba []byte) *net.UDPAddr
func VerifyFingerPrint ¶ added in v0.0.3
func VerifyFingerPrint(sp StunPacket) bool
VerifyFingerPrint verifies there is a fingerprint and it is correct.
Types ¶
type StunAttribute ¶
type StunAttribute uint16
type StunMessage ¶
type StunMessage uint16
type StunPacket ¶
type StunPacket struct {
// contains filtered or unexported fields
}
func NewStunPacket ¶
func NewStunPacket(b []byte) (*StunPacket, error)
NewStunPacket create a new StunPacket from the provided []byte
func (*StunPacket) GetAddress ¶
func (sp *StunPacket) GetAddress() (*net.UDPAddr, error)
GetAddress returns the MappedAddress or XORMappedAddress in this StunPacket if its exits
func (*StunPacket) GetAllAttributes ¶
func (sp *StunPacket) GetAllAttributes() []StunAttribute
GetAllAttributes will return all the StunAttributes in this StunPacket as an Array
func (*StunPacket) GetAttribute ¶
func (sp *StunPacket) GetAttribute(sa StunAttribute) []byte
GetAttribute returns the []byte for a given StunAttribute
func (*StunPacket) GetBytes ¶
func (sp *StunPacket) GetBytes() []byte
GetBytes gets the underliying []byte for this StunPacket
func (*StunPacket) GetStunMessageType ¶
func (sp *StunPacket) GetStunMessageType() StunMessage
GetStunMessageType will return the current StunMessage for this StunPacket
func (*StunPacket) GetTxID ¶
func (sp *StunPacket) GetTxID() *TransactionID
GetTxID returns the TransactionID for this StunPacket
func (*StunPacket) HasAddress ¶
func (sp *StunPacket) HasAddress() bool
HasAddress returns true if this StunPacket has a MappedAddress of any kind.
func (*StunPacket) HasFingerPrint ¶ added in v0.0.3
func (sp *StunPacket) HasFingerPrint() bool
func (*StunPacket) ToBuilder ¶
func (sp *StunPacket) ToBuilder() *StunPacketBuilder
ToBuilder creates a StunPacketBuilder with this StunPackets Data as the base
type StunPacketBuilder ¶
type StunPacketBuilder struct {
// contains filtered or unexported fields
}
func NewStunPacketBuilder ¶
func NewStunPacketBuilder() *StunPacketBuilder
func (*StunPacketBuilder) AddFingerprint ¶ added in v0.0.3
func (spb *StunPacketBuilder) AddFingerprint(fp bool) *StunPacketBuilder
func (*StunPacketBuilder) Build ¶
func (spb *StunPacketBuilder) Build() *StunPacket
func (*StunPacketBuilder) ClearAttributes ¶
func (spb *StunPacketBuilder) ClearAttributes() *StunPacketBuilder
func (*StunPacketBuilder) SetAddress ¶
func (spb *StunPacketBuilder) SetAddress(ua *net.UDPAddr) *StunPacketBuilder
func (*StunPacketBuilder) SetAttribue ¶
func (spb *StunPacketBuilder) SetAttribue(sa StunAttribute, ba []byte) *StunPacketBuilder
func (*StunPacketBuilder) SetPaddingByte ¶
func (spb *StunPacketBuilder) SetPaddingByte(b byte) *StunPacketBuilder
func (*StunPacketBuilder) SetStunMessage ¶
func (spb *StunPacketBuilder) SetStunMessage(sm StunMessage) *StunPacketBuilder
func (*StunPacketBuilder) SetTXID ¶
func (spb *StunPacketBuilder) SetTXID(txid *TransactionID) *StunPacketBuilder
func (*StunPacketBuilder) SetXORAddress ¶
func (spb *StunPacketBuilder) SetXORAddress(ua *net.UDPAddr) *StunPacketBuilder
type TransactionID ¶
type TransactionID struct {
// contains filtered or unexported fields
}
func NewTID ¶
func NewTID(ba []byte) (*TransactionID, error)
NewTID will create a new TransactionID from the provided []byte The []byte must be only 12 bytes
func (*TransactionID) GetTID ¶
func (tid *TransactionID) GetTID() []byte
GetTID provides this TransactionIDs []byte
func (*TransactionID) MaskAddress ¶
func (tid *TransactionID) MaskAddress(addr *net.UDPAddr) []byte
MaskAddress takes an net.UDPAddr and turns it into a SAXORMappedAddress []byte
func (*TransactionID) String ¶
func (tid *TransactionID) String() string
This prints the TransactionID as a HexString
func (*TransactionID) UnMaskAddress ¶
func (tid *TransactionID) UnMaskAddress(addr []byte) *net.UDPAddr
UnMaskAddress uses this TransactionID to unmask an SAXORMappedAddress