<!--
{
  "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/writePackets(_:withProtocols:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Network Extension"
    ],
    "preciseIdentifier" : "c:objc(cs)NEPacketTunnelFlow(im)writePackets:withProtocols:"
  },
  "title" : "writePackets(_:withProtocols:)"
}
-->

# writePackets(_:withProtocols:)

Writes IP packets to the TUN interface.

```
func writePackets(_ packets: [Data], withProtocols protocols: [NSNumber]) -> Bool
```

## Parameters

`packets`

An array of NSData objects containing the IP packets to the written.

`protocols`

An array of NSNumber objects containing the protocol numbers (e.g. AF_INET or AF_INET6) of the IP packets in `packets` in host byte order.

## Discussion

The number of NSData objects in `packets` must be exactly equal to the number of NSNumber objects in `protocols`.

---

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)