Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
compscidr committed Aug 7, 2024
1 parent 772a2dc commit ac641a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.jasonernst.packetdumper

import org.slf4j.LoggerFactory
import java.nio.ByteBuffer
import java.security.InvalidParameterException

/**
* Bare minimal Ethernet frame.
Expand All @@ -28,21 +27,22 @@ class EthernetHeader(private var destination: MACAddress, private var source: MA
buffer: ByteBuffer,
offset: Int = 0,
length: Int = 0,
etherType: EtherType
etherType: EtherType,
): ByteBuffer {
val startingPosition = buffer.position()
val totalLength = minOf(length, buffer.limit() - offset)
if (totalLength < length) {
logger.warn("Trying to dump more bytes than are in the buffer. Dumping up to buffer limit.")
}
val newBuffer = ByteBuffer.allocate(totalLength + ETHERNET_HEADER_LENGTH.toInt())
val detectedEtherType = if (etherType == EtherType.DETECT) {
val ipVersion = buffer.get(offset).toUByte()
buffer.position(startingPosition)
getEtherTypeFromIPVersionByte(ipVersion)
} else {
etherType
}
val detectedEtherType =
if (etherType == EtherType.DETECT) {
val ipVersion = buffer.get(offset).toUByte()
buffer.position(startingPosition)
getEtherTypeFromIPVersionByte(ipVersion)
} else {
etherType
}
newBuffer.put(dummyEthernet(detectedEtherType).toBytes())
newBuffer.put(buffer.array(), offset, totalLength)
newBuffer.rewind()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.jasonernst.packetdumper.stringdumper

import com.jasonernst.packetdumper.AbstractPacketDumper
import com.jasonernst.packetdumper.EtherType
import com.jasonernst.packetdumper.EthernetHeader
import com.jasonernst.packetdumper.EthernetHeader.Companion
import com.jasonernst.packetdumper.EthernetHeader.Companion.prependDummyHeader
import org.slf4j.Logger
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -71,18 +69,19 @@ class StringPacketDumper(private val packetLogger: Logger? = null, private val w
): String {
val startingPosition = buffer.position()
// optionally prepend the ethernet dummy header
val conversionBuffer = if (etherType != null) {
prependDummyHeader(buffer, offset, length, etherType)
} else {
val totalLength = minOf(length, buffer.limit() - offset)
if (totalLength < length) {
logger.warn("Trying to dump more bytes than are in the buffer. Dumping up to buffer limit.")
val conversionBuffer =
if (etherType != null) {
prependDummyHeader(buffer, offset, length, etherType)
} else {
val totalLength = minOf(length, buffer.limit() - offset)
if (totalLength < length) {
logger.warn("Trying to dump more bytes than are in the buffer. Dumping up to buffer limit.")
}
val newBuffer = ByteBuffer.allocate(totalLength)
newBuffer.put(buffer.array(), offset, totalLength)
newBuffer.rewind()
newBuffer
}
val newBuffer = ByteBuffer.allocate(totalLength)
newBuffer.put(buffer.array(), offset, totalLength)
newBuffer.rewind()
newBuffer
}
val output = StringBuilder()
var i = 0
while (i < conversionBuffer.limit()) {
Expand Down

0 comments on commit ac641a2

Please sign in to comment.