diff options
author | Jeroen Leenarts <jeroen.leenarts@gmail.com> | 2018-08-27 13:52:02 +0200 |
---|---|---|
committer | Jeroen Leenarts <jeroen.leenarts@gmail.com> | 2018-08-27 13:52:02 +0200 |
commit | 2c3a36078e2450df9a10baaecfa65eafd9357ebb (patch) | |
tree | 5ba6b08e50cc809e80866b0329f4a8818190b813 /WireGuardNetworkExtension | |
parent | Move, modify and add key generation functions to project. (diff) | |
download | wireguard-apple-2c3a36078e2450df9a10baaecfa65eafd9357ebb.tar.xz wireguard-apple-2c3a36078e2450df9a10baaecfa65eafd9357ebb.zip |
Select correct IP version identifier based on packet contents.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r-- | WireGuardNetworkExtension/WireGuardGoWrapper.m | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/WireGuardNetworkExtension/WireGuardGoWrapper.m b/WireGuardNetworkExtension/WireGuardGoWrapper.m index 7631365..17c549e 100644 --- a/WireGuardNetworkExtension/WireGuardGoWrapper.m +++ b/WireGuardNetworkExtension/WireGuardGoWrapper.m @@ -171,9 +171,19 @@ static ssize_t do_write(const void *ctx, const unsigned char *buf, size_t len) os_log_debug([WireGuardGoWrapper log], "do_write - start"); WireGuardGoWrapper *wrapper = (__bridge WireGuardGoWrapper *)ctx; - //TODO: determine IPv4 or IPv6 status. + + //determine IPv4 or IPv6 status. + NSInteger ipVersionBits = (buf[0] & 0xf0) >> 4; + NSNumber *ipVersion = NSDecimalNumber.zero; + if (ipVersionBits == 4) { + ipVersion = @AF_INET; + } else if (ipVersionBits == 6) { + ipVersion = @AF_INET6; + } else { + return 0; + } NSData *packet = [[NSData alloc] initWithBytes:buf length:len]; - [wrapper.packetFlow writePackets:@[packet] withProtocols:@[@AF_INET]]; + [wrapper.packetFlow writePackets:@[packet] withProtocols:@[ipVersion]]; return len; } } |