diff --git a/net/local/local.h b/net/local/local.h index e65078b46c..c746b51fc0 100644 --- a/net/local/local.h +++ b/net/local/local.h @@ -254,6 +254,19 @@ void local_free(FAR struct local_conn_s *conn); FAR struct local_conn_s *local_nextconn(FAR struct local_conn_s *conn); +/**************************************************************************** + * Name: local_peerconn + * + * Description: + * Traverse the connections list to find the peer + * + * Assumptions: + * This function must be called with the network locked. + * + ****************************************************************************/ + +FAR struct local_conn_s *local_peerconn(FAR struct local_conn_s *conn); + /**************************************************************************** * Name: psock_local_bind * diff --git a/net/local/local_conn.c b/net/local/local_conn.c index bf4faf32d0..3b27400d78 100644 --- a/net/local/local_conn.c +++ b/net/local/local_conn.c @@ -82,6 +82,33 @@ FAR struct local_conn_s *local_nextconn(FAR struct local_conn_s *conn) return (FAR struct local_conn_s *)conn->lc_node.flink; } +/**************************************************************************** + * Name: local_peerconn + * + * Description: + * Traverse the connections list to find the peer + * + * Assumptions: + * This function must be called with the network locked. + * + ****************************************************************************/ + +FAR struct local_conn_s *local_peerconn(FAR struct local_conn_s *conn) +{ + FAR struct local_conn_s *peer = NULL; + + while ((peer = local_nextconn(peer)) != NULL) + { + if (conn->lc_proto == peer->lc_proto && conn != peer && + !strncmp(conn->lc_path, peer->lc_path, UNIX_PATH_MAX - 1)) + { + return peer; + } + } + + return NULL; +} + /**************************************************************************** * Name: local_alloc() *