Fix writing domains

This commit is contained in:
David Evans 2021-06-18 11:40:42 +01:00
parent b03d835bca
commit 2f50bb22f2
2 changed files with 6 additions and 1 deletions

View File

@ -202,7 +202,7 @@ extension ByteBuffer {
return self.writeInteger(SOCKSAddress.domainIdentifierByte)
+ self.writeInteger(UInt8(domain.utf8.count))
+ self.writeString(domain)
+ self.writeInteger(port)
+ self.writeInteger(UInt16(port))
}
}

View File

@ -65,6 +65,11 @@ extension ClientRequestTests {
XCTAssertEqual(ipv6.writeAddressType(.address(try! .init(ipAddress: "0001:0002:0003:0004:0005:0006:0007:0008", port: 80))), 19)
XCTAssertEqual(ipv6.readBytes(length: 17)!, [4, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8])
XCTAssertEqual(ipv6.readInteger(as: UInt16.self)!, 80)
var domain = ByteBuffer()
XCTAssertEqual(domain.writeAddressType(.domain("127.0.0.1", port: 80)), 13)
XCTAssertEqual(domain.readBytes(length: 11)!, [3, 9, 49, 50, 55, 46, 48, 46, 48, 46, 49])
XCTAssertEqual(domain.readInteger(as: UInt16.self)!, 80)
}
}