Network extension - C APIs?

Is there a C version of the Network Extensions APIs?

Just asking because some of the Objective-C/Swift objects do not provide useful methods.

e.g. NWEndpoint vs nw_endpoint_t

If you want to get the port using NWEndpoint/NWHostEndpoint, you first need to get a NSString * that is useless and "big" and convert it to an unsigned short.

If you want to get the port using nw_endpoint_t, you just use nw_endpoint_get__port to get the unsigned short.

It's worse of course if you need to get the sockaddr *.

Also with nw_endpoint_t, you can know the type of the endpoint…

I will file an enhancement request about this if needed but the Feedback Assistant website was down, again, when I tried.

Is there a C version of the Network Extensions APIs?

There are three APIs in play here:
  • Network framework’s C API, nw_endpoint_t (X)

  • Network frameworks’s Swift API, NWEndpoint (Y)

  • NetworkExtension framework’s Objective-C API, NWEndpoint and its various subclasses (this can also be used directly from Swift) (Z)

It seems like you prefer X, and that’s fine. If that’s your preference, and your deployment target is high enough, just use it.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
OK but are there entry points for the Network framework’s C "types" for a filter packet provider or a filter data provider?

I see only the Obj-C API in the Network Extension framework and there are no public ways to "convert" a NW Obj-C "type" to a NW "C" type.

I'm looking for the ease of Obj-C and, when needed, the speed of C.


OK but are there entry points for the Network framework’s C "types"
for a filter packet provider or a filter data provider?

What sort of entry points are you talking about? Let’s focus on a filter packet provider for the moment. It works entirely in terms of packets. Where does X, Y or Z come into it?

But, to answer your more general question, there is no way to convert between X, Y, and Z. X and Y are fundamentally equivalent so, while it’s not currently available, a conversion might be feasible. Z is not the same as X and Y, so providing a conversion would be tricky.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
I don't really see "conversion" C issues with packet filter since basically we are just provided with a bytes buffer. I'm more interested by the Filter Packet case.

For instance, in Ob-C, we have NEFilterDataProvider which has those entry points:
  • (NEFilterNewFlowVerdict *)handleNewFlow:(NEFilterFlow *)inFlow;

  • (NEFilterDataVerdict *)handleInboundDataFromFlow:(NEFilterFlow *)inFlow readBytesStartOffset:(NSUInteger)offset readBytes:(NSData *)readBytes;

From the NEFilterFlow, you, AFAIK, can only get a NWEndpoint.

So I'm wondering if there is a "raw" C-equivalent for NEFilterDataProvider.

Network extension - C APIs?
 
 
Q