- // If there is a hole in the list of connections, use it.
- // Otherwise, add a new connection to the end.
+static struct utcp_connection *find_connection(const struct utcp *utcp, uint16_t src, uint16_t dst) {
+ if(!utcp->nconnections)
+ return NULL;
+ struct utcp_connection key = {
+ .src = src,
+ .dst = dst,
+ }, *keyp = &key;
+ struct utcp_connection **match = bsearch(&keyp, utcp->connections, utcp->nconnections, sizeof *utcp->connections, compare);
+ return match ? *match : NULL;
+}