readPackets(completionHandler:)
Reads IP packets from the TUN interface.
Declaration
func readPackets(completionHandler: @escaping @Sendable ([Data], [NSNumber]) -> Void)func readPackets() async -> ([Data], [NSNumber])Parameters
- completionHandler:
A Swift closure or an ObjectiveC block that runs when some packets are read from the TUN interface. The packets that were read are passed to this block in the
packetsarray. The protocol numbers of the packets that were read are passed to this block in theprotocolsarray. Each packet has a protocol number in the corresponding index in theprotocolsarray. The protocol numbers are given in host byte order. Valid protocol numbers includeAF_INETandAF_INET6. See/usr/include/sys/socket.h.
Discussion
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.