mirror of
https://github.com/pion/stun.git
synced 2025-10-31 02:56:27 +08:00
18 lines
459 B
Go
18 lines
459 B
Go
package stun
|
|
|
|
// STUN aligns attributes on 32-bit boundaries, attributes whose content
|
|
// is not a multiple of 4 bytes are padded with 1, 2, or 3 bytes of
|
|
// padding so that its value contains a multiple of 4 bytes. The
|
|
// padding bits are ignored, and may be any value.
|
|
//
|
|
// https://tools.ietf.org/html/rfc5389#section-15
|
|
const padding = 4
|
|
|
|
func nearestPaddedValueLength(l int) int {
|
|
n := padding * (l / padding)
|
|
if n < l {
|
|
n += padding
|
|
}
|
|
return n
|
|
}
|