-
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.
- Loading branch information
Showing
5 changed files
with
456 additions
and
45 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
38 changes: 38 additions & 0 deletions
38
packetdumper/src/test/kotlin/com/jasonernst/packetdumper/PcapNgTestHelper.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,38 @@ | ||
package com.jasonernst.packetdumper | ||
|
||
import com.jasonernst.packetdumper.filedumper.AbstractFilePacketDumper | ||
import com.jasonernst.packetdumper.pcapng.PcapNgBlock | ||
import com.jasonernst.packetdumper.pcapng.PcapNgInterfaceDescriptionBlock | ||
import com.jasonernst.packetdumper.pcapng.PcapNgSectionHeaderBlockLive | ||
import com.jasonernst.packetdumper.stringdumper.StringPacketDumper | ||
import org.slf4j.LoggerFactory | ||
import java.io.BufferedInputStream | ||
import java.io.FileInputStream | ||
import java.nio.ByteBuffer | ||
|
||
object PcapNgTestHelper { | ||
private val logger = LoggerFactory.getLogger(javaClass) | ||
|
||
/** | ||
* Verify that the file has the correct headers, advances the readBuffer beyond these headers | ||
* and returns a list of the blocks. | ||
*/ | ||
fun verifyHeaders(readBuffer: ByteBuffer): List<PcapNgBlock> { | ||
val pcapBlocks = mutableListOf<PcapNgBlock>() | ||
|
||
// we expect the file to start with a section header block | ||
pcapBlocks.add(PcapNgSectionHeaderBlockLive.fromStream(readBuffer)) | ||
|
||
// we expect the file to have an interface description block | ||
pcapBlocks.add(PcapNgInterfaceDescriptionBlock.fromStream(readBuffer)) | ||
|
||
return pcapBlocks | ||
} | ||
|
||
fun readFile(dumper: AbstractFilePacketDumper): ByteBuffer { | ||
val readBuffer = ByteBuffer.wrap(BufferedInputStream(FileInputStream(dumper.filename)).readAllBytes()) | ||
val stringPacketDumper = StringPacketDumper(logger) | ||
stringPacketDumper.dumpBuffer(readBuffer, 0, readBuffer.limit(), false, null) | ||
return readBuffer | ||
} | ||
} |
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
Oops, something went wrong.