How to send the data back after get the data through 'readPacketsWithCompletionHandler'

After through this method

[self.packetFlow readPacketsWithCompletionHandler:^(NSArray<NSData *> * _Nonnull packets, NSArray<NSNumber *> * _Nonnull protocols) {
  
}];

to get the data,I want to block some ip address,And then,how to send the data back to my iphone?I just block some thing,so i don't have to send them to a VPN server.

After read the data,if I do nothing,The iphone will not be able to access the network.

[self.packetFlow readPacketsWithCompletionHandler:^(NSArray<NSData *> * _Nonnull packets, NSArray<NSNumber *> * _Nonnull protocols) {
         //do some block
        [self.packetFlow writePackets:packets withProtocols:protocols];

}];

And this is not work.

Replies

I want to block some ip address,And then,how to send the data back to my iphone?

You’ve got the wrong end of the stick here. Network Extension’s tunnel provider architecture was designed for folks doing VPN. In a VPN app you would take those packets and push them down a tunnel that you’ve opened to your VPN server (often using NWTCPConnection, but possibly using some other API), and your VPN server would then forward them out on to the Internet (or your private network, or whatever). There’s no way to push those packets back into the client networking stack, because a VPN would never need to do that.

If you want to block access to certain IP addresses, that’s what a content filter provider is for.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

>There’s no way to push those packets back into the client networking stack, because a VPN would never need to do that.

Then how the global VPN distinguishing different applications?

One more question,

'content filter provider',is this a global filter?You mean Filter Data Provider?tks and Merry Christmas.

'content filter provider' … You mean Filter Data Provider?

Yes. I’m using content filter provider as a shortcut for both the filter control and data providers, which always come as a pair.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"