net: Make si_getsockname callback optional

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2023-03-06 12:10:27 +08:00 committed by Petro Karashchenko
parent b3c1c55805
commit 9b3715050b
5 changed files with 9 additions and 145 deletions

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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);
}