---
title: "writePackets(_:withProtocols:)"
framework: networkextension
role: symbol
role_heading: Instance Method
path: "networkextension/nepackettunnelflow/writepackets(_:withprotocols:)"
---

# writePackets(_:withProtocols:)

Writes IP packets to the TUN interface.

## Declaration

```swift
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

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

## See Also

### Handling IP packets

- [readPacketObjects(completionHandler:)](networkextension/nepackettunnelflow/readpacketobjects(completionhandler:).md)
- [writePacketObjects(_:)](networkextension/nepackettunnelflow/writepacketobjects(_:).md)
- [readPackets(completionHandler:)](networkextension/nepackettunnelflow/readpackets(completionhandler:).md)
