Skip to content

Commit

Permalink
Merge pull request #5 from compscidr/renovate/kotlinter
Browse files Browse the repository at this point in the history
Update dependency org.jmailen.kotlinter to v4.4.1
  • Loading branch information
compscidr authored Aug 8, 2024
2 parents 3ac0116 + b0ae716 commit 65935d1
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
jupiter = "5.10.3"
kotlin = "2.0.10"
kotlinter = "4.3.0"
kotlinter = "4.4.1"
logback-classic = "1.5.6"
mockk = "1.13.12"
slf4j = "2.0.15"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ package com.jasonernst.packetdumper
* https://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml#ieee-802-numbers-1
* https://en.wikipedia.org/wiki/EtherType
*/
enum class EtherType(val value: UShort) {
enum class EtherType(
val value: UShort,
) {
BUMP(0x0101u),
IPv4(0x0800u),
ARP(0x0806u),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import java.nio.ByteBuffer
*
* https://en.wikipedia.org/wiki/Ethernet_frame
*/
class EthernetHeader(private var destination: MACAddress, private var source: MACAddress, private var type: EtherType) {
class EthernetHeader(
private var destination: MACAddress,
private var source: MACAddress,
private var type: EtherType,
) {
companion object {
const val IP4_VERSION: UByte = 4u
const val IP6_VERSION: UByte = 6u
Expand Down Expand Up @@ -61,20 +65,18 @@ class EthernetHeader(private var destination: MACAddress, private var source: MA
* ethertype, it will just leave the type as 0xFFFF (detect) which maps to RESERVED in the
* actual mapping.
*/
fun getEtherTypeFromIPVersionByte(ipVersion: UByte): EtherType {
return when (ipVersion) {
fun getEtherTypeFromIPVersionByte(ipVersion: UByte): EtherType =
when (ipVersion) {
IP4_VERSION -> EtherType.IPv4
IP6_VERSION -> EtherType.IPv6
else -> {
logger.warn("Couldn't detect etherType, got $ipVersion")
EtherType.DETECT
}
}
}

fun dummyEthernet(etherType: EtherType): EthernetHeader {
return EthernetHeader(MACAddress.DUMMY_MAC_SOURCE, MACAddress.DUMMY_MAC_DEST, etherType)
}
fun dummyEthernet(etherType: EtherType): EthernetHeader =
EthernetHeader(MACAddress.DUMMY_MAC_SOURCE, MACAddress.DUMMY_MAC_DEST, etherType)
}

fun size() = ETHERNET_HEADER_LENGTH
Expand All @@ -87,7 +89,5 @@ class EthernetHeader(private var destination: MACAddress, private var source: MA
return buffer.array()
}

override fun toString(): String {
return "EthernetHeader(destination=$destination, source=$source, type=$type, size=${size()})"
}
override fun toString(): String = "EthernetHeader(destination=$destination, source=$source, type=$type, size=${size()})"
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ class MACAddress {
this.bytes = address.split(":").map { it.toInt(16).toByte() }.toByteArray()
}

override fun toString(): String {
return bytes.joinToString(":") { it.toString(16).padStart(2, '0') }
}
override fun toString(): String = bytes.joinToString(":") { it.toString(16).padStart(2, '0') }

companion object {
fun fromStream(stream: ByteBuffer): MACAddress {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.jasonernst.packetdumper.filedumper
import com.jasonernst.packetdumper.EtherType
import java.nio.ByteBuffer

class PcapNgFilePacketDumper(override var filename: String) : AbstractFilePacketDumper() {
class PcapNgFilePacketDumper(
override var filename: String,
) : AbstractFilePacketDumper() {
override fun open() {
TODO("Not yet implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import java.util.concurrent.atomic.AtomicBoolean
* Each block of offsets is separated by a blank newline, and represents a new packet / dump. When
* the new dump starts, the offset can restart at 0.
*/
class TextFilePacketDumper(private val path: String, private val name: String) : AbstractFilePacketDumper() {
class TextFilePacketDumper(
private val path: String,
private val name: String,
) : AbstractFilePacketDumper() {
private val logger = LoggerFactory.getLogger(javaClass)
private val stringDumper = StringPacketDumper()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.jasonernst.packetdumper.serverdumper
import com.jasonernst.packetdumper.EtherType
import java.nio.ByteBuffer

class PcapNgTcpServerPacketDumper(val listenPort: Int = DEFAULT_PORT) : AbstractServerPacketDumper() {
class PcapNgTcpServerPacketDumper(
val listenPort: Int = DEFAULT_PORT,
) : AbstractServerPacketDumper() {
companion object {
const val DEFAULT_PORT = 19000
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import java.nio.ByteBuffer
* @param packetLogger The slf4j logger to dump the buffers to.
* @param writeToStdOut If true, will write to stdout (if the logger is null)
*/
class StringPacketDumper(private val packetLogger: Logger? = null, private val writeToStdOut: Boolean = false) : AbstractPacketDumper() {
class StringPacketDumper(
private val packetLogger: Logger? = null,
private val writeToStdOut: Boolean = false,
) : AbstractPacketDumper() {
private val logger = LoggerFactory.getLogger(javaClass)

/**
Expand Down

0 comments on commit 65935d1

Please sign in to comment.