Could not build module 'NetworkExtension' error

I'm trying to write a sample network filtering code as part of the NetworkExtension,

So far I cannot even use

#include <NetworkExtension/NetworkExtension.h>

without getting an error saying "Could not build module 'NetworkExtensin'"

I have already added the NetworkExtension framework to my project dependencies.

and the project is a command line (C) project


any ideas?

What version of Xcode are you using? On what version of macOS?

Does the problem reproduce if you create a new Objective-C test project using one of the built-in templates? What about a Swift test project? [1]

Does the problem reproduce if you create a new user (in System Preferences > Users & Groups) and try it logged in as that user?

Share and Enjoy

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

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

[1] I’m not proposing you use Swift; this is just a diagnostic.

Hi,

After digging a bit, I understand that it is not possible to create NetworkExtension using native C command line And I'd rather do it in swift.

Is there any good tutorial on how It can be done?

Since it has much differences than writing EnpointSecurity SystemExtension, this one requires IPC Communication.

And from the code sample on Filter Network Traffic there's a little I can understand.


Thanks!

it is not possible to create NetworkExtension using native C command line

I’m not sure how to parse this, so here’s some factoids:

  • It is not possible to create a NetworkExtension provider using vanilla C. This API is exposed as Objective-C, so you must use a language that’s capable of working with Objective-C interfaces (Objective-C, Objective-C++, Swift).

  • It should be possible to build a NetworkExtension from the command line. If all else fails, you can set up an Xcode project and then build it using

    xcodebuild
    . However, I expect that you’d be able to avoid Xcode entirely, and build the project using lower-level command line tools (
    clang
    ,
    swiftc
    ,
    ld
    ,
    codesign
    , and so on).

And from the code sample on Filter Network Traffic there's a little I can understand.

That sample is a good place to start. Why bits are you having problems with?

Share and Enjoy

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

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

I'm trying to use the code sample as a starting point with NetworkExtension

though I'm having some troubles when trying to execute the "register" function in IPCConnection

BTW I'm new to swift (never had any expirience with it before, I'm coming from low level C so I'm not that familiar with this syntax).

I'm getting an error for the lines

        guard let providerProxy = newConnection.remoteObjectProxyWithErrorHandler({ registerError in
            os_log("Failed to register with the provider: %@", registerError.localizedDescription)
            self.currentConnection?.invalidate()
            self.currentConnection = nil
            completionHandler(false)
        }) as? ProviderCommunication else {
            fatalError("Failed to create a remote object proxy for the provider")
        }

the "fatalError" line is the one I'm reaching, and I haven't got an idea regarding the cause of the issue.


--- EDIT:

Okay, so I figured I forgot to actually set the provider using the line

newConnection.remoteObjectInterface = NSXPCInterface(with: ProviderCommunication.self)


and now it's running without any fatal errors, but I'm still getting the next error

Failed to register with the provider: %@ Couldn’t communicate with a helper application.

Not sure what's "helper application" means

I presume you’re working from the Filtering Network Traffic sample code here? If so, the most likely cause of this problem is the IPC setup. Make sure that the extension’s

Info.plist
has a
NEMachServiceName
property whose value is a ‘child’ of the extension’s app group that’s shared between the app and the extension. Out of the box these are:
  • TTT.com.example.apple-samplecode.SimpleFirewall.SimpleFirewallExtension
  • TTT.com.example.apple-samplecode.SimpleFirewall

where

TTT
is your Team ID. Then make sure that the
extensionMachServiceName(from:)
method is correctly returning that name.

Share and Enjoy

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

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

It seems that my extensionMachServiceName(from:) method does return what it should.

This is my Info.plist file's content

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>NetworkExtension</key>
<dict>
<key>NEMachServiceName</key>
<string>com.example.apple-samplecode.SimpleFirewall</string>
<key>NEProviderClasses</key>
<dict>
<key>com.apple.networkextension.filter-data</key>
<string>MyNetworkExtension.FilterDataProvider</string>
</dict>
</dict>
</dict>
</plist>


Just to make sure, I'm not running it as an app bundle, but as a command line project, so the part of the ViewController & AppCommunication I assume is pretty useless for me right?

Just to make sure, I'm not running it as an app bundle, but as a command line project

Huh? NE providers are app (or system) extensions, and these much be contained in an app.

Share and Enjoy

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

let myEmail = "eskimo" + "1" + "@apple.com"
Could not build module 'NetworkExtension' error
 
 
Q