Skip to content

Commit f9849dc

Browse files
committed
turns out Windows can do packetInfoIPv6
1 parent 61624ba commit f9849dc

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

FlyingSocks/Sources/Socket+WinSock2.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extension Socket {
6262
static let ipproto_ipv6 = Int32(IPPROTO_IPV6.rawValue)
6363
static let ip_pktinfo = Int32(IP_PKTINFO)
6464
static let ipv6_pktinfo = Int32(IPV6_PKTINFO)
65+
static let ipv6_recvpktinfo = Int32(IPV6_PKTINFO)
6566

6667
static func makeAddressINET(port: UInt16) -> WinSDK.sockaddr_in {
6768
WinSDK.sockaddr_in(

FlyingSocks/Sources/Socket.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,8 @@ public struct Socket: Sendable, Hashable {
126126
switch domain {
127127
case AF_INET:
128128
try setValue(true, for: .packetInfoIP)
129-
#if !canImport(WinSDK)
130129
case AF_INET6:
131130
try setValue(true, for: .packetInfoIPv6)
132-
#endif
133131
default:
134132
return
135133
}
@@ -568,18 +566,16 @@ public extension SocketOption where Self == BoolSocketOption {
568566
BoolSocketOption(level: Socket.ipproto_ip, name: Socket.ip_pktinfo)
569567
}
570568

569+
static var packetInfoIPv6: Self {
570+
BoolSocketOption(level: Socket.ipproto_ipv6, name: Socket.ipv6_recvpktinfo)
571+
}
572+
571573
#if canImport(WinSDK)
572574
static var exclusiveLocalAddressReuse: Self {
573575
BoolSocketOption(name: ~SO_REUSEADDR) // SO_EXCLUSIVEADDRUSE macro
574576
}
575577
#endif
576578

577-
#if !canImport(WinSDK)
578-
static var packetInfoIPv6: Self {
579-
BoolSocketOption(level: Socket.ipproto_ipv6, name: Socket.ipv6_recvpktinfo)
580-
}
581-
#endif
582-
583579
#if canImport(Darwin)
584580
// Prevents SIG_TRAP when app is paused / running in background.
585581
static var noSIGPIPE: Self {

FlyingSocks/Tests/SocketTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ struct SocketTests {
331331
)
332332
}
333333

334-
#if !canImport(WinSDK)
335334
@Test
336335
func makes_datagram_ip6() throws {
337336
let socket = try Socket(domain: Int32(sa_family_t(AF_INET6)), type: .datagram)
@@ -340,7 +339,6 @@ struct SocketTests {
340339
try socket.getValue(for: .packetInfoIPv6) == true
341340
)
342341
}
343-
#endif
344342
}
345343

346344
extension Socket.Flags {

0 commit comments

Comments
 (0)