Instance Method


Read IP packets from the TUN interface.


func readPackets(completionHandler: @escaping ([Data], [NSNumber]) -> Void)



A block that is executed when some packets are read from the TUN interface. The packets that were read are passed to this block in the packets array. The protocol numbers of the packets that were read are passed to this block in the protocols array. Each packet has a protocol number in the corresponding index in the protocols array. The protocol numbers are given in host byte order. Valid protocol numbers include AF_INET and AF_INET6. See /usr/include/sys/socket.h.


Each call to this method results in a single execution of the completion handler. The caller should call this method after each completionHandler execution in order to continue to receive packets from the TUN interface.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software