mirror of
https://github.com/apple/swift-nio-extras.git
synced 2025-05-14 17:02:43 +08:00
Fix endianess
This commit is contained in:
parent
d8ec99407c
commit
d48d6e15c7
@ -166,12 +166,12 @@ extension ByteBuffer {
|
||||
switch type {
|
||||
case .address(.v4(let address)):
|
||||
return self.writeInteger(UInt8(1))
|
||||
+ self.writeInteger(address.address.sin_addr.s_addr, endianness: .little)
|
||||
+ self.writeInteger(address.address.sin_port, endianness: .little)
|
||||
+ self.writeInteger(address.address.sin_addr.s_addr)
|
||||
+ self.writeInteger(address.address.sin_port)
|
||||
case .address(.v6(let address)):
|
||||
return self.writeInteger(UInt8(4))
|
||||
+ self.writeIPv6Address(address.address)
|
||||
+ self.writeInteger(address.address.sin6_port, endianness: .little)
|
||||
+ self.writeInteger(address.address.sin6_port)
|
||||
case .address(.unixDomainSocket):
|
||||
// enforced in the channel initalisers.
|
||||
fatalError("UNIX domain sockets are not supported")
|
||||
|
@ -29,7 +29,7 @@ extension ClientRequestTests {
|
||||
XCTAssertEqual(buffer.writeClientRequest(req), 10)
|
||||
XCTAssertEqual(buffer.readableBytes, 10)
|
||||
XCTAssertEqual(buffer.readBytes(length: 10)!,
|
||||
[0x05, 0x01, 0x00, 0x01, 0xC0, 0xA8, 0x01, 0x01, 0x00, 0x50])
|
||||
[0x05, 0x01, 0x00, 1, 1, 1, 168, 192, 0x50, 0])
|
||||
}
|
||||
|
||||
}
|
||||
@ -58,13 +58,13 @@ extension ClientRequestTests {
|
||||
func testWriteAddressType(){
|
||||
var ipv4 = ByteBuffer()
|
||||
XCTAssertEqual(ipv4.writeAddressType(.address(try! .init(ipAddress: "192.168.1.1", port: 80))), 7)
|
||||
XCTAssertEqual(ipv4.readBytes(length: 5)!, [1, 192, 168, 1, 1])
|
||||
XCTAssertEqual(ipv4.readInteger(as: UInt16.self)!, 80)
|
||||
XCTAssertEqual(ipv4.readBytes(length: 5)!, [1, 1, 1, 168, 192])
|
||||
XCTAssertEqual(ipv4.readInteger(as: UInt16.self)!, 0x5000)
|
||||
|
||||
var ipv6 = ByteBuffer()
|
||||
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)
|
||||
XCTAssertEqual(ipv6.readInteger(as: UInt16.self)!, 0x5000)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ class SocksClientHandlerTests: XCTestCase {
|
||||
self.writeInbound([0x05, 0x00])
|
||||
|
||||
// client sends the request
|
||||
self.assertOutputBuffer([0x05, 0x01, 0x00, 0x01, 192, 168, 1, 1, 0x00, 0x50])
|
||||
self.assertOutputBuffer([0x05, 0x01, 0x00, 0x01, 1, 1, 168, 192, 0x50, 0x00])
|
||||
|
||||
// server replies yay or nay
|
||||
self.writeInbound([0x05, 0x00, 0x00, 0x01, 192, 168, 1, 1, 0x00, 0x50])
|
||||
@ -80,7 +80,7 @@ class SocksClientHandlerTests: XCTestCase {
|
||||
self.writeInbound([0x05])
|
||||
self.assertOutputBuffer([])
|
||||
self.writeInbound([0x00])
|
||||
self.assertOutputBuffer([0x05, 0x01, 0x00, 0x01, 192, 168, 1, 1, 0x00, 0x50])
|
||||
self.assertOutputBuffer([0x05, 0x01, 0x00, 0x01, 1, 1, 168, 192, 0x50, 0x00])
|
||||
|
||||
// drip feed server response
|
||||
self.writeInbound([0x05, 0x00, 0x00, 0x01])
|
||||
@ -142,7 +142,7 @@ class SocksClientHandlerTests: XCTestCase {
|
||||
// start handshake, send request
|
||||
self.assertOutputBuffer([0x05, 0x01, 0x00])
|
||||
self.writeInbound([0x05, 0x00])
|
||||
self.assertOutputBuffer([0x05, 0x01, 0x00, 0x01, 192, 168, 1, 1, 0x00, 0x50])
|
||||
self.assertOutputBuffer([0x05, 0x01, 0x00, 0x01, 1, 1, 168, 192, 0x50, 0x00])
|
||||
|
||||
// server replies with an error
|
||||
let promise = self.channel.eventLoop.makePromise(of: Void.self)
|
||||
|
Loading…
x
Reference in New Issue
Block a user