Move UDP header assembly to build()
Test: TH Flag: EXEMPT mainline Bug: 1000001 Change-Id: I5e070a57bfa40f95b72549cb02662f6557f78d45
This commit is contained in:
parent
6064435502
commit
c1cf40d38e
1 changed files with 4 additions and 7 deletions
|
|
@ -456,20 +456,17 @@ class UdpPkt(
|
|||
) : Packet {
|
||||
constructor(srcPort: Int, dstPort: Int) : this(srcPort.toShort(), dstPort.toShort())
|
||||
|
||||
val outputStream = ByteArrayOutputStream()
|
||||
init {
|
||||
override fun build(payload: FinalizedPacket?, pseudo: PseudoHeaderPacket?): FinalizedPacket {
|
||||
require(pseudo != null)
|
||||
|
||||
val udpHeader = ByteBuffer.allocate(8)
|
||||
.putShort(srcPort)
|
||||
.putShort(dstPort)
|
||||
.putShort(0) // length; to be filled in later.
|
||||
.putShort(0) // checksum; to be filled in later.
|
||||
udpHeader.flip()
|
||||
val outputStream = ByteArrayOutputStream()
|
||||
outputStream.write(udpHeader.array())
|
||||
}
|
||||
|
||||
override fun build(payload: FinalizedPacket?, pseudo: PseudoHeaderPacket?): FinalizedPacket {
|
||||
require(pseudo != null)
|
||||
|
||||
if (payload != null) {
|
||||
outputStream.write(payload.bytes)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue