Don't add protocol prefix if a target other than iPhone

This commit is contained in:
Sergey Abramchuk
2017-06-22 20:02:52 +03:00
parent 545098ea0e
commit b0756eae4c

View File

@@ -560,12 +560,16 @@ static void socketCallback(CFSocketRef socket, CFSocketCallBackType type, CFData
- (void)readTUNPackets {
[self.packetFlow readPacketsWithCompletionHandler:^(NSArray<NSData *> * _Nonnull packets, NSArray<NSNumber *> * _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