Skip to content

Commit

Permalink
initialize source port and destination port if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoArregui committed Mar 1, 2024
1 parent 5359da5 commit 6b264e1
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions association.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -295,6 +305,7 @@ func createAssociation(config Config) *Association {
}

tsn := globalMathRandomGenerator.Uint32()

a := &Association{
netConn: config.NetConn,
maxReceiveBufferSize: maxReceiveBufferSize,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 6b264e1

Please sign in to comment.