apple / swift-nio

Event-driven network application framework for high performance protocol servers & clients, non-blocking.
https://swiftpackageindex.com/apple/swift-nio/documentation
Apache License 2.0
7.96k stars 648 forks source link

we should query getaddrinfo more precisely #201

Closed weissi closed 6 years ago

weissi commented 6 years ago

Expected behavior

When asking getaddrinfo about an IP address, we should not get two results that contain the same IP address.

Actual behavior

we do get two, example here:

(lldb) p info.pointee
(addrinfo) $R13 = {
  ai_flags = 0
  ai_family = 2
  ai_socktype = 2
  ai_protocol = 17
  ai_addrlen = 16
  ai_canonname = nil
  ai_addr = 0x0000000104904ab0
  ai_next = 0x0000000104904f60
}
(lldb) p info.pointee.ai_next.pointee
(addrinfo) $R14 = {
  ai_flags = 0
  ai_family = 2
  ai_socktype = 1
  ai_protocol = 6
  ai_addrlen = 16
  ai_canonname = nil
  ai_addr = 0x0000000104904f90
  ai_next = nil
}

whereby ai_protocol = 17 is IPPROTO_UDP and ai_protocol = 6 is IPPROTO_TCP. But since we know which one we want we should query correctly.

Steps to reproduce

If possible, minimal yet complete reproducer code (or URL to code)

bootstrap.connect(host: "127.0.0.1", port: 1234)

SwiftNIO version/commit hash

1.2.0

Swift & OS version (output of swift --version && uname -a)

$ uname -a 
Darwin jwmbp.local 17.5.0 Darwin Kernel Version 17.5.0: Mon Jan 22 18:03:58 PST 2018; root:xnu-4570.50.252~1/DEVELOPMENT_X86_64 x86_64
$ swift --version
Apple Swift version 4.0.3 (swiftlang-900.0.71 clang-900.0.38)
Target: x86_64-apple-macosx10.9
normanmaurer commented 6 years ago

Should be fixed by https://github.com/apple/swift-nio/pull/221