This is an automated email from the ASF dual-hosted git repository.

pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 9b3715050b9ea4428587660e5a1a799c889e7136
Author: Xiang Xiao <xiaoxi...@xiaomi.com>
AuthorDate: Mon Mar 6 12:10:27 2023 +0800

    net: Make si_getsockname callback optional
    
    Signed-off-by: Xiang Xiao <xiaoxi...@xiaomi.com>
---
 net/can/can_sockif.c       | 33 +--------------------------------
 net/icmp/icmp_sockif.c     | 38 +-------------------------------------
 net/icmpv6/icmpv6_sockif.c | 38 +-------------------------------------
 net/pkt/pkt_sockif.c       | 38 +-------------------------------------
 net/socket/getsockname.c   |  7 +++++--
 5 files changed, 9 insertions(+), 145 deletions(-)

diff --git a/net/can/can_sockif.c b/net/can/can_sockif.c
index c8b6521ea5..4fca599633 100644
--- a/net/can/can_sockif.c
+++ b/net/can/can_sockif.c
@@ -53,8 +53,6 @@ static sockcaps_t can_sockcaps(FAR struct socket *psock);
 static void can_addref(FAR struct socket *psock);
 static int  can_bind(FAR struct socket *psock,
               FAR const struct sockaddr *addr, socklen_t addrlen);
-static int  can_getsockname(FAR struct socket *psock,
-              FAR struct sockaddr *addr, FAR socklen_t *addrlen);
 static int  can_getpeername(FAR struct socket *psock,
               FAR struct sockaddr *addr, FAR socklen_t *addrlen);
 static int  can_listen(FAR struct socket *psock, int backlog);
@@ -76,7 +74,7 @@ const struct sock_intf_s g_can_sockif =
   can_sockcaps,     /* si_sockcaps */
   can_addref,       /* si_addref */
   can_bind,         /* si_bind */
-  can_getsockname,  /* si_getsockname */
+  NULL,             /* si_getsockname */
   can_getpeername,  /* si_getpeername */
   can_listen,       /* si_listen */
   can_connect,      /* si_connect */
@@ -342,35 +340,6 @@ static int can_bind(FAR struct socket *psock,
   return OK;
 }
 
-/****************************************************************************
- * Name: can_getsockname
- *
- * Description:
- *   The getsockname() function retrieves the locally-bound name of the
- *   specified socket, stores this address in the sockaddr structure pointed
- *   to by the 'addr' argument, and stores the length of this address in the
- *   object pointed to by the 'addrlen' argument.
- *
- *   If the actual length of the address is greater than the length of the
- *   supplied sockaddr structure, the stored address will be truncated.
- *
- *   If the socket has not been bound to a local name, the value stored in
- *   the object pointed to by address is unspecified.
- *
- * Input Parameters:
- *   conn     CAN socket connection structure
- *   addr     sockaddr structure to receive data [out]
- *   addrlen  Length of sockaddr structure [in/out]
- *
- ****************************************************************************/
-
-static int can_getsockname(FAR struct socket *psock,
-                           FAR struct sockaddr *addr,
-                           FAR socklen_t *addrlen)
-{
-  return -EAFNOSUPPORT;
-}
-
 /****************************************************************************
  * Name: can_getpeername
  *
diff --git a/net/icmp/icmp_sockif.c b/net/icmp/icmp_sockif.c
index 053225dd6d..b9e74aaa48 100644
--- a/net/icmp/icmp_sockif.c
+++ b/net/icmp/icmp_sockif.c
@@ -47,8 +47,6 @@
 static int        icmp_setup(FAR struct socket *psock);
 static sockcaps_t icmp_sockcaps(FAR struct socket *psock);
 static void       icmp_addref(FAR struct socket *psock);
-static int        icmp_getsockname(FAR struct socket *psock,
-                    FAR struct sockaddr *addr, FAR socklen_t *addrlen);
 static int        icmp_getpeername(FAR struct socket *psock,
                     FAR struct sockaddr *addr, FAR socklen_t *addrlen);
 static int        icmp_listen(FAR struct socket *psock, int backlog);
@@ -71,7 +69,7 @@ const struct sock_intf_s g_icmp_sockif =
   icmp_sockcaps,    /* si_sockcaps */
   icmp_addref,      /* si_addref */
   NULL,             /* si_bind */
-  icmp_getsockname, /* si_getsockname */
+  NULL,             /* si_getsockname */
   icmp_getpeername, /* si_getpeername */
   icmp_listen,      /* si_listen */
   icmp_connect,     /* si_connect */
@@ -277,40 +275,6 @@ static int icmp_accept(FAR struct socket *psock, FAR 
struct sockaddr *addr,
   return -EAFNOSUPPORT;
 }
 
-/****************************************************************************
- * Name: icmp_getsockname
- *
- * Description:
- *   The icmp_getsockname() function retrieves the locally-bound name of the
- *   specified packet socket, stores this address in the sockaddr structure
- *   pointed to by the 'addr' argument, and stores the length of this
- *   address in the object pointed to by the 'addrlen' argument.
- *
- *   If the actual length of the address is greater than the length of the
- *   supplied sockaddr structure, the stored address will be truncated.
- *
- *   If the socket has not been bound to a local name, the value stored in
- *   the object pointed to by address is unspecified.
- *
- * Input Parameters:
- *   psock    Socket structure of the socket to be queried
- *   addr     sockaddr structure to receive data [out]
- *   addrlen  Length of sockaddr structure [in/out]
- *
- * Returned Value:
- *   On success, 0 is returned, the 'addr' argument points to the address
- *   of the socket, and the 'addrlen' argument points to the length of the
- *   address.  Otherwise, a negated errno value is returned.  See
- *   getsockname() for the list of appropriate error numbers.
- *
- ****************************************************************************/
-
-static int icmp_getsockname(FAR struct socket *psock,
-                           FAR struct sockaddr *addr, FAR socklen_t *addrlen)
-{
-  return -EAFNOSUPPORT;
-}
-
 /****************************************************************************
  * Name: icmp_getpeername
  *
diff --git a/net/icmpv6/icmpv6_sockif.c b/net/icmpv6/icmpv6_sockif.c
index 7a5e5a76dd..aba5c4a9ee 100644
--- a/net/icmpv6/icmpv6_sockif.c
+++ b/net/icmpv6/icmpv6_sockif.c
@@ -47,8 +47,6 @@
 static int        icmpv6_setup(FAR struct socket *psock);
 static sockcaps_t icmpv6_sockcaps(FAR struct socket *psock);
 static void       icmpv6_addref(FAR struct socket *psock);
-static int        icmpv6_getsockname(FAR struct socket *psock,
-                    FAR struct sockaddr *addr, FAR socklen_t *addrlen);
 static int        icmpv6_getpeername(FAR struct socket *psock,
                     FAR struct sockaddr *addr, FAR socklen_t *addrlen);
 static int        icmpv6_listen(FAR struct socket *psock, int backlog);
@@ -71,7 +69,7 @@ const struct sock_intf_s g_icmpv6_sockif =
   icmpv6_sockcaps,    /* si_sockcaps */
   icmpv6_addref,      /* si_addref */
   NULL,               /* si_bind */
-  icmpv6_getsockname, /* si_getsockname */
+  NULL,               /* si_getsockname */
   icmpv6_getpeername, /* si_getpeername */
   icmpv6_listen,      /* si_listen */
   icmpv6_connect,     /* si_connect */
@@ -277,40 +275,6 @@ static int icmpv6_accept(FAR struct socket *psock, FAR 
struct sockaddr *addr,
   return -EAFNOSUPPORT;
 }
 
-/****************************************************************************
- * Name: icmpv6_getsockname
- *
- * Description:
- *   The icmpv6_getsockname() function retrieves the locally-bound name of
- *   the specified packet socket, stores this address in the sockaddr
- *   structure pointed to by the 'addr' argument, and stores the length of
- *   this address in the object pointed to by the 'addrlen' argument.
- *
- *   If the actual length of the address is greater than the length of the
- *   supplied sockaddr structure, the stored address will be truncated.
- *
- *   If the socket has not been bound to a local name, the value stored in
- *   the object pointed to by address is unspecified.
- *
- * Input Parameters:
- *   psock    Socket structure of the socket to be queried
- *   addr     sockaddr structure to receive data [out]
- *   addrlen  Length of sockaddr structure [in/out]
- *
- * Returned Value:
- *   On success, 0 is returned, the 'addr' argument points to the address
- *   of the socket, and the 'addrlen' argument points to the length of the
- *   address.  Otherwise, a negated errno value is returned.  See
- *   getsockname() for the list of appropriate error numbers.
- *
- ****************************************************************************/
-
-static int icmpv6_getsockname(FAR struct socket *psock,
-                           FAR struct sockaddr *addr, FAR socklen_t *addrlen)
-{
-  return -EAFNOSUPPORT;
-}
-
 /****************************************************************************
  * Name: icmpv6_getpeername
  *
diff --git a/net/pkt/pkt_sockif.c b/net/pkt/pkt_sockif.c
index 47a902b6f4..7af123891e 100644
--- a/net/pkt/pkt_sockif.c
+++ b/net/pkt/pkt_sockif.c
@@ -52,8 +52,6 @@ static sockcaps_t pkt_sockcaps(FAR struct socket *psock);
 static void       pkt_addref(FAR struct socket *psock);
 static int        pkt_bind(FAR struct socket *psock,
                     FAR const struct sockaddr *addr, socklen_t addrlen);
-static int        pkt_getsockname(FAR struct socket *psock,
-                    FAR struct sockaddr *addr, FAR socklen_t *addrlen);
 static int        pkt_getpeername(FAR struct socket *psock,
                     FAR struct sockaddr *addr, FAR socklen_t *addrlen);
 static int        pkt_listen(FAR struct socket *psock, int backlog);
@@ -76,7 +74,7 @@ const struct sock_intf_s g_pkt_sockif =
   pkt_sockcaps,    /* si_sockcaps */
   pkt_addref,      /* si_addref */
   pkt_bind,        /* si_bind */
-  pkt_getsockname, /* si_getsockname */
+  NULL,            /* si_getsockname */
   pkt_getpeername, /* si_getpeername */
   pkt_listen,      /* si_listen */
   pkt_connect,     /* si_connect */
@@ -372,40 +370,6 @@ static int pkt_bind(FAR struct socket *psock,
     }
 }
 
-/****************************************************************************
- * Name: pkt_getsockname
- *
- * Description:
- *   The pkt_getsockname() function retrieves the locally-bound name of the
- *   specified packet socket, stores this address in the sockaddr structure
- *   pointed to by the 'addr' argument, and stores the length of this
- *   address in the object pointed to by the 'addrlen' argument.
- *
- *   If the actual length of the address is greater than the length of the
- *   supplied sockaddr structure, the stored address will be truncated.
- *
- *   If the socket has not been bound to a local name, the value stored in
- *   the object pointed to by address is unspecified.
- *
- * Input Parameters:
- *   psock    Socket structure of the socket to be queried
- *   addr     sockaddr structure to receive data [out]
- *   addrlen  Length of sockaddr structure [in/out]
- *
- * Returned Value:
- *   On success, 0 is returned, the 'addr' argument points to the address
- *   of the socket, and the 'addrlen' argument points to the length of the
- *   address.  Otherwise, a negated errno value is returned.  See
- *   getsockname() for the list of appropriate error numbers.
- *
- ****************************************************************************/
-
-static int pkt_getsockname(FAR struct socket *psock,
-                           FAR struct sockaddr *addr, FAR socklen_t *addrlen)
-{
-  return -EAFNOSUPPORT;
-}
-
 /****************************************************************************
  * Name: pkt_getpeername
  *
diff --git a/net/socket/getsockname.c b/net/socket/getsockname.c
index a2ce0152ad..c70a1d71ef 100644
--- a/net/socket/getsockname.c
+++ b/net/socket/getsockname.c
@@ -95,8 +95,11 @@ int psock_getsockname(FAR struct socket *psock, FAR struct 
sockaddr *addr,
 
   /* Let the address family's send() method handle the operation */
 
-  DEBUGASSERT(psock->s_sockif != NULL &&
-              psock->s_sockif->si_getsockname != NULL);
+  DEBUGASSERT(psock->s_sockif != NULL);
+  if (psock->s_sockif->si_getsockname == NULL)
+    {
+      return -EOPNOTSUPP;
+    }
 
   return psock->s_sockif->si_getsockname(psock, addr, addrlen);
 }

Reply via email to