Network Extension Framework and bindToRequest

I am currently upgrading our app from Captive Network Framework to Network Extenstions Framework(i.e. NEHotspotHelper).

So, I come to the following in our code:

     [myReq bindToCommand:cmdRef];

Where myReq is an NSMutableURLRequest and cmdRef is a CNPluginCommandRef. The bindToCommand is documented in the CaptiveNetowrkPlugin Handbook (page 12) as:

Making Network Connections
Any network connection that the CNPlugin opens to authenticate to the network
MUST be bound to the supplied command. This ensures that the network traffic
goes over the authenticating interface and not the default interface that the system
might choose automatically.
When using NSMutableURLRequest, use the following objective C method:
@interface NSMutableURLRequest (CaptiveNetworkPlugin)
- (void)bindToCommand:(CNPluginCommandRef)cmd;

In other words, we bind the CNP command to the NSMutableURLRequest then perform our usual setup and (my guess is) that NSMutableURLRequest handles the rest under the covers. (If I misunderstand, please clarify:)

As far as I can tell, the closest method to bindToCommand translates to NEHotspotHelperCommand createTCPConnection:

Create a new TCP connection over the network associated with the command.

- (NWTCPConnection * _Nonnull)createTCPConnection:(NWEndpoint * _Nonnull)endpoint


But, I’m not quite sure how to use it. The SimpleTunnel sample code doesn’t use the NEHotspotHelper version of the call.

Anyone have any sample code or suggestions on how to use createTCPConnection in NEHotspotHelper?


~Gene

I’m not sure I understand what the actual problem is here. In most cases hotspot helper apps talk to the hotspot via HTTP[S], and thus they create a request, bind it to the command (so it goes out over the right interface), and then send the request via NSURLSession.

Is the issue that you want to talk to your hotspot using low-level TCP (and hence

-bindToCommand:
, which is only available for NSURLRequest, which implies HTTP[S], won’t work for you)?

Share and Enjoy

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

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

.eskimo,


Thanks for your response.


I don't see equivalent method bindToCommand in NSMutableURLRequest for NEHotspotHelperCommand. How do we bind a NEHotspotHelperCommand to a NSMutableURLRequest?


- Gene

What you’re looking for is

-[NSMutableURLRequest bindToHotspotHelperCommand:
.

Also, please get in touch with me via email (my address is in my signature, below).

Share and Enjoy

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

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

Thanks, eskimo!


Firing off an email now.


- Gene

What if I want to send UDP packet and listen the response...

How can I bind it to the command?

That would be

-createUDPSession:
in
<NetworkExtension/NEHotspotHelper.h>
(also, for TCP,
-createTCPConnection:
).

Share and Enjoy

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

let myEmail = "eskimo" + "1" + "@apple.com"
Network Extension Framework and bindToRequest
 
 
Q