From b0756eae4cbd8c629396f7c3dcea2077ddfdb255 Mon Sep 17 00:00:00 2001 From: Sergey Abramchuk Date: Thu, 22 Jun 2017 20:02:52 +0300 Subject: [PATCH] Don't add protocol prefix if a target other than iPhone --- OpenVPN Adapter/OpenVPNAdapter.mm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/OpenVPN Adapter/OpenVPNAdapter.mm b/OpenVPN Adapter/OpenVPNAdapter.mm index c2f77c1..c5d88e4 100644 --- a/OpenVPN Adapter/OpenVPNAdapter.mm +++ b/OpenVPN Adapter/OpenVPNAdapter.mm @@ -560,12 +560,16 @@ static void socketCallback(CFSocketRef socket, CFSocketCallBackType type, CFData - (void)readTUNPackets { [self.packetFlow readPacketsWithCompletionHandler:^(NSArray * _Nonnull packets, NSArray * _Nonnull protocols) { [packets enumerateObjectsUsingBlock:^(NSData * data, NSUInteger idx, BOOL * stop) { - // Prepend data with network protocol. It should be done because OpenVPN uses uint32_t prefixes containing network protocol. + NSMutableData *packet = [NSMutableData new]; + +#if TARGET_OS_IPHONE + // Prepend data with network protocol. It should be done because OpenVPN on iOS uses uint32_t prefixes containing network protocol. NSNumber *protocol = protocols[idx]; uint32_t prefix = CFSwapInt32HostToBig((uint32_t)[protocol unsignedIntegerValue]); - NSMutableData *packet = [NSMutableData new]; [packet appendBytes:&prefix length:sizeof(prefix)]; +#endif + [packet appendData:data]; // Send data to the VPN server