From 6b264e1c782c8fc529e9a08694d210f5ed8359bd Mon Sep 17 00:00:00 2001 From: Hugo Arregui <969314+hugoArregui@users.noreply.github.com> Date: Thu, 29 Feb 2024 21:07:28 -0300 Subject: [PATCH] initialize source port and destination port if possible --- association.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/association.go b/association.go index cf493ef7..87fdd090 100644 --- a/association.go +++ b/association.go @@ -95,6 +95,16 @@ const ( acceptChSize = 16 ) +func getPort(addr net.Addr) uint16 { + switch addr := addr.(type) { + case *net.UDPAddr: + return uint16(addr.Port) + case *net.TCPAddr: + return uint16(addr.Port) + } + return 0 +} + func getAssociationStateString(a uint32) string { switch a { case closed: @@ -295,6 +305,7 @@ func createAssociation(config Config) *Association { } tsn := globalMathRandomGenerator.Uint32() + a := &Association{ netConn: config.NetConn, maxReceiveBufferSize: maxReceiveBufferSize, @@ -327,6 +338,8 @@ func createAssociation(config Config) *Association { silentError: ErrSilentlyDiscard, stats: &associationStats{}, log: config.LoggerFactory.NewLogger("sctp"), + sourcePort: getPort(config.NetConn.LocalAddr()), + destinationPort: getPort(config.NetConn.RemoteAddr()), } a.name = fmt.Sprintf("%p", a) @@ -391,8 +404,12 @@ func (a *Association) sendInit() error { outbound := &packet{} outbound.verificationTag = a.peerVerificationTag - a.sourcePort = 5000 // Spec?? - a.destinationPort = 5000 // Spec?? + if a.sourcePort == 0 { + a.sourcePort = 5000 + } + if a.destinationPort == 0 { + a.destinationPort = 5000 + } outbound.sourcePort = a.sourcePort outbound.destinationPort = a.destinationPort