Skip to content

Commit

Permalink
Fix non Darwin/Linux builds
Browse files Browse the repository at this point in the history
  • Loading branch information
dnadoba committed Dec 2, 2022
1 parent ec72e0a commit e088edd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Tests/NIOPosixTests/IPv4Header.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ extension ByteBuffer {
}

mutating func readIPv4HeaderFromOSRawSocket() -> IPv4Header? {
#if canImport(Darwin)
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(FreeBSD)
return self.readIPv4HeaderFromBSDRawSocket()
#else
return self.readIPv4Header()
Expand Down Expand Up @@ -267,7 +267,7 @@ extension ByteBuffer {

@discardableResult
mutating func writeIPv4HeaderToOSRawSocket(_ header: IPv4Header) -> Int {
#if canImport(Darwin)
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(FreeBSD)
self.writeIPv4HeaderToBSDRawSocket(header)
#else
self.writeIPv4Header(header)
Expand Down Expand Up @@ -324,21 +324,21 @@ private func onesComplementAdd<Integer: FixedWidthInteger>(lhs: Integer, rhs: In

extension IPv4Header {
var platformIndependentTotalLengthForReceivedPacketFromRawSocket: UInt16 {
#if canImport(Darwin)
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
// On BSD the IP header will only contain the size of the ip packet body, not the header.
// This is known bug which can't be fixed without breaking old apps which already workaround the issue
// like e.g. we do now too.
return totalLength + 20
#elseif os(Linux)
#else
return totalLength
#endif
}
var platformIndependentChecksumForReceivedPacketFromRawSocket: UInt16 {
#if canImport(Darwin)
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
// On BSD the checksum is always zero and we need to compute it
precondition(headerChecksum == 0)
return computeChecksum()
#elseif os(Linux)
#else
return headerChecksum
#endif
}
Expand Down

0 comments on commit e088edd

Please sign in to comment.