ios IP Layer Proxy Beta (#215)

This commit is contained in:
wanghongenpin
2024-10-09 02:30:02 +08:00
parent aded2b7f37
commit 86d342cb07
38 changed files with 2458 additions and 84 deletions

View File

@@ -102,8 +102,7 @@ object IPPacketFactory {
val versionAndHeaderLength: Byte = buffer.get()
val ipVersion = (versionAndHeaderLength.toInt() shr 4).toByte()
if (ipVersion.toInt() != IP4_VERSION) {
// throw IllegalArgumentException("Invalid IP version $ipVersion")
return null
throw IllegalArgumentException("Invalid IP version $ipVersion")
}
val internetHeaderLength = (versionAndHeaderLength.toInt() and 0x0F).toByte()

View File

@@ -73,6 +73,7 @@ object TCPPacketFactory {
tcp.isNS = false
tcp.setIsRST(true)
tcp.dataOffset = 5
tcp.options = null
tcp.windowSize = 0
@@ -109,6 +110,8 @@ object TCPPacketFactory {
tcp.setIsFIN(false)
tcp.timeStampSender = timeSender
tcp.timeStampReplyTo = timeReplyTo
tcp.dataOffset = 5
tcp.options = null
var totalLength = ip.getIPHeaderLength() + tcp.getTCPHeaderLength()
if (packetData != null) {
@@ -142,6 +145,8 @@ object TCPPacketFactory {
tcp.setIsSYN(false)
tcp.setIsPSH(false)
tcp.setIsFIN(false)
tcp.dataOffset = 5
tcp.options = null
ip.totalLength = ip.getIPHeaderLength() + tcp.getTCPHeaderLength()
return createPacketData(ip, tcp, null)
@@ -184,6 +189,9 @@ object TCPPacketFactory {
tcp.timeStampReplyTo = tcp.timeStampSender
tcp.timeStampSender = PacketUtil.currentTime
tcp.dataOffset = 5
tcp.options = null
return Packet(ip, tcp, createPacketData(ip, tcp, null))
}
@@ -209,6 +217,9 @@ object TCPPacketFactory {
tcp.setIsPSH(false)
tcp.setIsFIN(isFin)
tcp.dataOffset = 5
tcp.options = null
ip.totalLength = ip.getIPHeaderLength() + tcp.getTCPHeaderLength()
return createPacketData(ip, tcp, null)
}
@@ -233,6 +244,7 @@ object TCPPacketFactory {
tcp.setIsACK(true)
tcp.setIsFIN(true)
tcp.dataOffset = 5
tcp.options = null
//窗口大小应为零
tcp.windowSize = 0

View File

@@ -39,7 +39,6 @@ object UDPPacketFactory {
}
val srcPort = udp.destinationPort
val destPort = udp.sourcePort
val checksum: Short = 0
val ipHeader = ip.copy()
val srcIp = ip.destinationIP
val destIp = ip.sourceIP
@@ -68,15 +67,19 @@ object UDPPacketFactory {
var start = ipData.size
val intContainer = ByteArray(4)
PacketUtil.writeIntToBytes(srcPort, intContainer, 0)
//extract the last two bytes of int value
System.arraycopy(intContainer, 2, buffer, start, 2)
start += 2
PacketUtil.writeIntToBytes(destPort, intContainer, 0)
System.arraycopy(intContainer, 2, buffer, start, 2)
start += 2
PacketUtil.writeIntToBytes(udpLen, intContainer, 0)
System.arraycopy(intContainer, 2, buffer, start, 2)
start += 2
val checksum: Short = 0
PacketUtil.writeIntToBytes(checksum.toInt(), intContainer, 0)
System.arraycopy(intContainer, 2, buffer, start, 2)
start += 2