diff --git a/net/local/local.h b/net/local/local.h index bc604872eef..902c900f3d9 100644 --- a/net/local/local.h +++ b/net/local/local.h @@ -259,6 +259,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 e6e421e31e5..86654fa9db0 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) #endif } +/**************************************************************************** + * 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() *