-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:compscidr/icmp
- Loading branch information
Showing
10 changed files
with
162 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
icmp-common/src/main/java/com/jasonernst/icmp_common/v4/ICMPv4TimeExceededCodes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.jasonernst.icmp_common.v4 | ||
|
||
import com.jasonernst.icmp_common.ICMPType | ||
|
||
enum class ICMPv4TimeExceededCodes(override val value: UByte) : ICMPType { | ||
TTL_EXCEEDED(0U), | ||
FRAGMENT_REASSEMBLY_TIME_EXCEEDED(1U) | ||
; | ||
|
||
companion object { | ||
fun fromValue(value: UByte) = ICMPv4DestinationUnreachableCodes.entries.first { it.value == value } | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
icmp-common/src/main/java/com/jasonernst/icmp_common/v4/ICMPv4TimeExceededPacket.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.jasonernst.icmp_common.v4 | ||
|
||
import java.nio.ByteBuffer | ||
import java.nio.ByteOrder | ||
|
||
class ICMPv4TimeExceededPacket(code: ICMPv4DestinationUnreachableCodes, checksum: UShort = 0u, val data: ByteArray = ByteArray(0)): ICMPv4Header(ICMPv4Type.TIME_EXCEEDED, code.value, checksum) { | ||
companion object { | ||
fun fromStream(buffer: ByteBuffer, code: UByte, checksum: UShort, order: ByteOrder = ByteOrder.BIG_ENDIAN): ICMPv4TimeExceededPacket { | ||
buffer.order(order) | ||
val remainingBuffer = ByteArray(buffer.remaining()) | ||
buffer.get(remainingBuffer) | ||
return ICMPv4TimeExceededPacket(ICMPv4TimeExceededCodes.fromValue(code), checksum, data = remainingBuffer) | ||
} | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
|
||
other as ICMPv4TimeExceededPacket | ||
|
||
return data.contentEquals(other.data) | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = super.hashCode() | ||
result = 31 * result + data.contentHashCode() | ||
return result | ||
} | ||
|
||
override fun toByteArray(order: ByteOrder): ByteArray { | ||
ByteBuffer.allocate(ICMP_HEADER_MIN_LENGTH.toInt() + data.size).apply { | ||
order(order) | ||
put(super.toByteArray(order)) | ||
put(data) | ||
return array() | ||
} | ||
} | ||
|
||
override fun toString(): String { | ||
return "ICMPv4TimeExceededPacket(code=$code, checksum=$checksum, data=${data.contentToString()})" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
icmp-common/src/main/java/com/jasonernst/icmp_common/v6/ICMPv6TimeExceededCodes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.jasonernst.icmp_common.v6 | ||
|
||
import com.jasonernst.icmp_common.ICMPType | ||
|
||
enum class ICMPv6TimeExceededCodes(override val value: UByte) : ICMPType { | ||
HOP_LIMIT_EXCEEDED(0U), | ||
FRAGMENT_REASSEMBLY_TIME_EXCEEDED(1U) | ||
; | ||
|
||
companion object { | ||
fun fromValue(value: UByte) = ICMPv6TimeExceededCodes.entries.first { it.value == value } | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
icmp-common/src/main/java/com/jasonernst/icmp_common/v6/ICMPv6TimeExceededPacket.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.jasonernst.icmp_common.v6 | ||
|
||
import java.nio.ByteBuffer | ||
import java.nio.ByteOrder | ||
|
||
class ICMPv6TimeExceededPacket(code: ICMPv6TimeExceededCodes, checksum: UShort = 0u, val data: ByteArray = ByteArray(0)): ICMPv6Header( | ||
ICMPv6Type.TIME_EXCEEDED, code.value, checksum) { | ||
companion object { | ||
fun fromStream(buffer: ByteBuffer, code: UByte, checksum: UShort, order: ByteOrder = ByteOrder.BIG_ENDIAN): ICMPv6TimeExceededPacket { | ||
buffer.order(order) | ||
val remainingBuffer = ByteArray(buffer.remaining()) | ||
buffer.get(remainingBuffer) | ||
return ICMPv6TimeExceededPacket(ICMPv6TimeExceededCodes.fromValue(code), checksum, data = remainingBuffer) | ||
} | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
|
||
other as ICMPv6TimeExceededPacket | ||
|
||
return data.contentEquals(other.data) | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = super.hashCode() | ||
result = 31 * result + data.contentHashCode() | ||
return result | ||
} | ||
|
||
override fun toByteArray(order: ByteOrder): ByteArray { | ||
ByteBuffer.allocate(ICMP_HEADER_MIN_LENGTH.toInt() + data.size).apply { | ||
order(order) | ||
put(super.toByteArray(order)) | ||
put(data) | ||
return array() | ||
} | ||
} | ||
|
||
override fun toString(): String { | ||
return "ICMPv6TimeExceededPacket(code=$code, checksum=$checksum, data=${data.contentToString()})" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters