<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "NetworkExtension",
  "identifier" : "/documentation/NetworkExtension/NEPacketTunnelFlow/readPackets(completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Network Extension"
    ],
    "preciseIdentifier" : "c:objc(cs)NEPacketTunnelFlow(im)readPacketsWithCompletionHandler:"
  },
  "title" : "readPackets(completionHandler:)"
}
-->

# readPackets(completionHandler:)

Reads IP packets from the TUN interface.

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

## 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 `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`.

## 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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)