Fix non Darwin/Linux builds (#2328)

This commit is contained in:
David Nadoba 2022-12-02 17:48:54 +01:00 committed by GitHub
parent ec72e0acc3
commit 21c22f3535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 6 deletions

View File

@ -208,7 +208,7 @@ extension ByteBuffer {
}
mutating func readIPv4HeaderFromOSRawSocket() -> IPv4Header? {
#if canImport(Darwin)
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
return self.readIPv4HeaderFromBSDRawSocket()
#else
return self.readIPv4Header()
@ -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)
self.writeIPv4HeaderToBSDRawSocket(header)
#else
self.writeIPv4Header(header)
@ -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
}