Odd network error and app crashed

We have implemented Network Extension with the capability of PacketTunnel. After setting the TunnelNetworkSettings it create a virtual interface. We have added additional link-local address to the virtual interface by including a IPv6 address in the addresses property of the NEIPv6Settings and all working as expected.

For Example -: Virtual interface is utun3 and link-local address is fe80::2 An entry has added in routing table like -> fe80::%utun3 fe80::2%utun3 UcI utun3 [output of netstat -rn]

now we are trying to create a Web-Socket connection with the link-local address

var connection: NWConnection?
var parameters: NWParameters?

let wsOptions = NWProtocolWebSocket.Options()
 wsOptions.autoReplyPing = true

 let tcpOptions = NWProtocolTCP.Options()
 tcpOptions.enableKeepalive = true

 parameters = NWParameters(tls: nil, tcp: tcpOptions)
 parameters?.defaultProtocolStack.applicationProtocols.insert(wsOptions, at: 0)

connection = NWConnection(host: "fe80::1%utun3", port: ***, using: parameters!)

connection?.stateUpdateHandler = { [weak self] state in
            print(" Link local received new state: \(state)")
        }
connection?.start(queue: .main)

On Start connection has sent SYN and received SYN ACK [Packets captured image]

at this point app is crashed this flowing error

`nw_endpoint_get_url called with null endpoint

2023-04-26 19:06:28.181408+0530 TunnelApp[3200:74170] [] nw_endpoint_get_url called with null endpoint, dumping backtrace:   [arm64] libnetcore-3013.80.5

    0   Network             0x00000001b4e91c80 __nw_create_backtrace_string + 192

    1   Network               0x00000001b4f38a70 nw_endpoint_get_url + 1216

    2   Network               0x00000001b4e942c4 nw_ws_create_client_request + 100

    3   Network             0x00000001b48fce58 __nw_ws_create_state_block_invoke + 428

    4   Network          0x00000001b4a9f384 nw_protocol_options_access_handle + 108

    5   Network         0x00000001b48f0a74 nw_ws_create_state + 248

    6   Network      0x00000001b48f05c8 _nw_protocol_copy_ws_definition_block_invoke_2 + 192

    7   Network       0x00000001b492ce5c nw_framer_protocol_connected + 368

    8   libusrtcp.dylib     0x00000001bc0ca290 nw_protocol_tcp_wake_connected + 432

    9   libusrtcp.dylib             0x00000001bc1011c0 tcp_input_available + 828

    10  libusrtcp.dylib     0x00000001bc0cbd4c nw_protocol_tcp_input_available + 288

    11  Network               0x00000001b539d4cc _ZL27nw_channel_add_input_framesP10nw_channelP11nw_protocol + 9188

    12  Network               0x00000001b539aff8 _ZL30nw_channel_update_input_sourceP10nw_channelP11nw_protocolb + 328

    13  Network                             0x00000001b539a204 ___ZL17nw_channel_createP10nw_contextPhjPvjbbPb_block_invoke.29 + 72

    14  libdispatch.dylib         0x00000001030029d4 _dispatch_client_callout + 20

    15  libdispatch.dylib         0x00000001030062b4 _dispatch_continuation_pop + 816

    16  libdispatch.dylib       0x00000001030215f0 _dispatch_source_invoke + 1732

    17  libdispatch.dylib       0x000000010300e8c8 _dispatch_workloop_invoke + 2876

    18  libdispatch.dylib     0x000000010301c990 _dispatch_workloop_worker_thread + 1064

    19  libsystem_pthread.dylib           0x0000000102c0fd28 _pthread_wqthread + 288

    20  libsystem_pthread.dylib             0x0000000102c17a7c start_wqthread + 8`

Any suggestions on it

Thanks

I believe this crash is caused by you setting up the destination address incorrectly. For a WebSocket it’s meant to be a URL. See this post for an example.

ps I don’t think that this has anything to do with the Network Extension context. If you ran the same code in a standard app, it’d crash in the same way. See the But Should You? section of my Debugging a Network Extension Provider post.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Odd network error and app crashed
 
 
Q