macOS packet tunnel provider

Mac PacketTunnelProvider not work , who can help me?

Replies

Please explain:

- what you do, and show the code

- what you get

- what you expect

1. Code for Connecting Accelerator


[self.manager loadFromPreferencesWithCompletionHandler:^(NSError *error){

if(error != nil){

NSLog(@"%@", error);

}else{

NSError *startError = nil;

[self.manager.connection startVPNTunnelWithOptions:nil andReturnError:&startError];

if(startError != nil)

{

NSLog(@"%@", startError);

}else{

NSLog(@"Complete");

}

}



}];


2.My current problem

I used the code link accelerator in the Mac development environment, but found that the -(void) startTunnelWithOptions: (NSDictionary *) options completionHandler: (void (^) (NSError *)) completionHandler in the Packet Tunnel Provider file; the method didn't go, but certainly it't work in the iOS development environment.


3.What I expect

My current Mac development environment, like the iOS environment, can execute the link accelerator method in the PacketTunnelProvider file

1.Code inside PacketTunnelProvider file


@implementation PacketTunnelProvider

{

OpenAdapter *vpnAdapter;

NWTCPConnection *_TCPConnection;

}


- (void)startTunnelWithOptions:(NSDictionary *)options completionHandler:(void (^)(NSError *))completionHandler {

NSLog(@"===>");

vpnAdapter = [[OpenAdapter alloc] init];

vpnAdapter.delegate = self;


NSUserDefaults *shared = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.cdjcsh1.baima"];


NSString *asav_node = [shared valueForKey:@"asav_node"];

NSString *asav_password = [shared valueForKey:@"asav_password"];

NSString *asav_username = [shared valueForKey:@"asav_username"];

NSString *asav_group = [shared valueForKey:@"asav_group"];

[vpnAdapter connect:asav_node user:asav_username pass:asav_password group:asav_group];


return;


}


2.The problems I encounter


I executed the [self.manager.connection startVPNTunnelWithOptions:nil andReturnError:&startError] method, not go the method in the PacketTunnelProvider file.

I hope you can understand what I mean and get your help. Thank you very much.

When you say:

not go the method in the PacketTunnelProvider file

Do you mean you do not execute the func ?

Or that it does not execute as expected ?


Could you add NSLog in secevral places of startTunnelWithOptions to see what happens ?

1.The following code saves @"result"


- (void)startTunnelWithOptions:(NSDictionary *)options completionHandler:(void (^)(NSError *))completionHandler

{

vpnAdapter = [[OpenAdapter alloc] init];

vpnAdapter.delegate = self;


NSUserDefaults *shared = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.mac.mac3"];

NSString *asav_node = [shared valueForKey:@"asav_node"];

NSString *asav_password = [shared valueForKey:@"asav_password"];

NSString *asav_username = [shared valueForKey:@"asav_username"];

NSString *asav_group = [shared valueForKey:@"asav_group"];

[shared setObject:@"1" forKey:@"result"];

[shared synchronize];

[vpnAdapter connect:asav_node user:asav_username pass:asav_password group:asav_group];

return;

}


2.This is the data that I print in the "result" field (null)


2019-08-21 16:30:42.650959+0800 mac2[1682:1021899] (null)

2019-08-21 16:30:42.653757+0800 mac2[1682:1021899] NEVPNStatusInvalid

2019-08-21 16:30:42.660091+0800 mac2[1682:1021899] Save successfully

2019-08-21 16:30:42.661454+0800 mac2[1682:1021899] Complete

2019-08-21 16:30:42.663759+0800 mac2[1682:1021899] NEVPNStatusConnecting

2019-08-21 16:30:42.666691+0800 mac2[1682:1021899] NEVPNStatusDisconnected

Since there is no interruption point in the PacketTunnelProvider file, I can only print the value of the @ "result" field using the method above.

Your should add comprehensive logging to your packet tunnel provider. You’ll want this when you release the app — it’s the only way to debug those obscure problems that only show up in the field — so you might as well get a start on it now.

I recommend that you use

os_log
for your logging. This has a couple of benefits:
  • You can monitor the log in real time using the Console app on macOS.

  • Your log entries will be captured in a sysdiagnose log, which is super helpful when debugging problems reported by users.

Note For more info about sysdiagnose logs, see our Bug Reporting > Profiles and Logs page.

Critically, your should add a log point to your packet tunnel provider’s initialiser. This will let you know whether your code is running at all. If it isn’t, you have some sort of packaging problem that’s preventing your provider from running. OTOH, if your provider at least starts, you can use that as a starting point for your debugging.

Since there is no interruption point in the PacketTunnelProvider file

You can debug a packet tunnel provider in the debugger, but it won’t attached automatically. You’ll need to attach using Debug > Attach to Process. However, that won’t help if your provider isn’t even starting, which is why I recommend that you start with the above.

ps I’ve edited this thread’s title to more accurately reflect its content.

Share and Enjoy

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

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

In the MacOs development environment, I can understand that only after the successful release of Mac app, the packettunnelprovider can work. Right?

In the MacOs development environment, I can understand that only after the successful release of Mac app, the packettunnelprovider can work.

I’m sorry, but I don’t understand what you’re asking here.

Share and Enjoy

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

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

I wonder if the packettunnellprovider will execute the method only after the Macapp has been released and downloaded. Otherwise, the packettunnellprovider file will not work in the development environment, right?

For those reading along at home, I’m going to be helping chak sum via a different channel.

Share and Enjoy

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

let myEmail = "eskimo" + "1" + "@apple.com"
(s. 718743204)