net/socket: move si_send/recv into sendmsg/recvmsg
Implement si_send/sendto/recvfrom with si_sendmsg/recvmsg, instead of the other way round. Change-Id: I7b858556996e0862df22807a6edf6d7cfe6518fc Signed-off-by: Peter Bee <bijunda1@xiaomi.com>
This commit is contained in:
parent
90be95bb89
commit
e223f60c09
59 changed files with 1303 additions and 2181 deletions
|
|
@ -54,9 +54,7 @@
|
|||
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_IMXRT_FLEXCAN
|
||||
|
||||
|
|
@ -93,11 +91,7 @@
|
|||
|
||||
#define POOL_SIZE 1
|
||||
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
#define MSG_DATA sizeof(struct timeval)
|
||||
#else
|
||||
#define MSG_DATA 0
|
||||
#endif
|
||||
|
||||
/* CAN bit timing values */
|
||||
#define CLK_FREQ 80000000
|
||||
|
|
|
|||
|
|
@ -51,9 +51,7 @@
|
|||
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_KINETIS_FLEXCAN
|
||||
|
||||
|
|
@ -90,11 +88,7 @@
|
|||
|
||||
#define POOL_SIZE 1
|
||||
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
#define MSG_DATA sizeof(struct timeval)
|
||||
#else
|
||||
#define MSG_DATA 0
|
||||
#endif
|
||||
|
||||
/* CAN bit timing values */
|
||||
#define CLK_FREQ BOARD_EXTAL_FREQ
|
||||
|
|
|
|||
|
|
@ -53,9 +53,7 @@
|
|||
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_S32K1XX_FLEXCAN
|
||||
|
||||
|
|
@ -92,11 +90,7 @@
|
|||
|
||||
#define POOL_SIZE 1
|
||||
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
#define MSG_DATA sizeof(struct timeval)
|
||||
#else
|
||||
#define MSG_DATA 0
|
||||
#endif
|
||||
|
||||
/* CAN bit timing values */
|
||||
#define CLK_FREQ 80000000
|
||||
|
|
|
|||
|
|
@ -197,26 +197,16 @@ struct sock_intf_s
|
|||
FAR struct socket *newsock);
|
||||
CODE int (*si_poll)(FAR struct socket *psock,
|
||||
FAR struct pollfd *fds, bool setup);
|
||||
CODE ssize_t (*si_send)(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags);
|
||||
CODE ssize_t (*si_sendto)(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags, FAR const struct sockaddr *to,
|
||||
socklen_t tolen);
|
||||
CODE ssize_t (*si_sendmsg)(FAR struct socket *psock,
|
||||
FAR struct msghdr *msg, int flags);
|
||||
CODE ssize_t (*si_recvmsg)(FAR struct socket *psock,
|
||||
FAR struct msghdr *msg, int flags);
|
||||
CODE int (*si_close)(FAR struct socket *psock);
|
||||
#ifdef CONFIG_NET_SENDFILE
|
||||
CODE ssize_t (*si_sendfile)(FAR struct socket *psock,
|
||||
FAR struct file *infile, FAR off_t *offset,
|
||||
size_t count);
|
||||
#endif
|
||||
CODE ssize_t (*si_recvfrom)(FAR struct socket *psock, FAR void *buf,
|
||||
size_t len, int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen);
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
CODE ssize_t (*si_recvmsg)(FAR struct socket *psock,
|
||||
FAR struct msghdr *msg, int flags);
|
||||
CODE ssize_t (*si_sendmsg)(FAR struct socket *psock,
|
||||
FAR struct msghdr *msg, int flags);
|
||||
#endif
|
||||
CODE int (*si_close)(FAR struct socket *psock);
|
||||
#ifdef CONFIG_NET_USRSOCK
|
||||
CODE int (*si_ioctl)(FAR struct socket *psock, int cmd,
|
||||
FAR void *arg, size_t arglen);
|
||||
|
|
@ -805,6 +795,66 @@ int psock_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||
int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
|
||||
socklen_t addrlen);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* psock_sendmsg() sends messages to a socket, and may be used to
|
||||
* send data on a socket whether or not it is connection-oriented.
|
||||
* This is an internal OS interface. It is functionally equivalent to
|
||||
* sendmsg() except that:
|
||||
*
|
||||
* - It is not a cancellation point,
|
||||
* - It does not modify the errno variable, and
|
||||
* - I accepts the internal socket structure as an input rather than an
|
||||
* task-specific socket descriptor.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* msg Message to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. Otherwise, on any
|
||||
* failure, a negated errno value is returned (see comments with sendmsg()
|
||||
* for a list of appropriate errno values).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t psock_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* psock_recvmsg() receives messages from a socket, and may be used to
|
||||
* receive data on a socket whether or not it is connection-oriented.
|
||||
* This is an internal OS interface. It is functionally equivalent to
|
||||
* recvmsg() except that:
|
||||
*
|
||||
* - It is not a cancellation point,
|
||||
* - It does not modify the errno variable, and
|
||||
* - It accepts the internal socket structure as an input rather than an
|
||||
* task-specific socket descriptor.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* msg Buffer to receive data
|
||||
* flags Receive flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* recvmsg() will return 0. Otherwise, on any failure, a negated errno
|
||||
* value is returned (see comments with recvmsg() for a list of appropriate
|
||||
* errno values).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t psock_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_send
|
||||
*
|
||||
|
|
@ -823,10 +873,10 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
|
|||
* functionality.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock - An instance of the internal socket structure.
|
||||
* buf - Data to send
|
||||
* len - Length of data to send
|
||||
* flags - Send flags
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On any failure, a
|
||||
|
|
@ -854,10 +904,10 @@ ssize_t psock_send(FAR struct socket *psock, const void *buf, size_t len,
|
|||
* functionality.
|
||||
*
|
||||
* Input Parameters:
|
||||
* sockfd - Socket descriptor of the socket
|
||||
* buf - Data to send
|
||||
* len - Length of data to send
|
||||
* flags - Send flags
|
||||
* sockfd Socket descriptor of the socket
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On any failure, a
|
||||
|
|
@ -946,16 +996,16 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
*
|
||||
* - It is not a cancellation point,
|
||||
* - It does not modify the errno variable, and
|
||||
* - I accepts the internal socket structure as an input rather than an
|
||||
* - It accepts the internal socket structure as an input rather than an
|
||||
* task-specific socket descriptor.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock - A pointer to a NuttX-specific, internal socket structure
|
||||
* buf - Buffer to receive data
|
||||
* len - Length of buffer
|
||||
* flags - Receive flags
|
||||
* from - Address of source (may be NULL)
|
||||
* fromlen - The length of the address structure
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
|
|
@ -988,12 +1038,12 @@ ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||
* - It does not modify the errno variable.
|
||||
*
|
||||
* Input Parameters:
|
||||
* sockfd - Socket descriptor of socket
|
||||
* buf - Buffer to receive data
|
||||
* len - Length of buffer
|
||||
* flags - Receive flags
|
||||
* from - Address of source (may be NULL)
|
||||
* fromlen - The length of the address structure
|
||||
* sockfd Socket descriptor of socket
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ struct linger
|
|||
struct msghdr
|
||||
{
|
||||
FAR void *msg_name; /* Socket name */
|
||||
int msg_namelen; /* Length of name */
|
||||
socklen_t msg_namelen; /* Length of name */
|
||||
FAR struct iovec *msg_iov; /* Data blocks */
|
||||
unsigned long msg_iovlen; /* Number of blocks */
|
||||
FAR void *msg_control; /* Per protocol magic (eg BSD file descriptor passing) */
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ CSRCS += lib_inetntop.c lib_inetpton.c
|
|||
CSRCS += lib_etherntoa.c lib_etheraton.c
|
||||
|
||||
ifeq ($(CONFIG_NET),y)
|
||||
CSRCS += lib_recvmsg.c lib_sendmsg.c lib_shutdown.c lib_socketpair.c
|
||||
CSRCS += lib_shutdown.c lib_socketpair.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NET_LOOPBACK),y)
|
||||
|
|
|
|||
|
|
@ -1,75 +0,0 @@
|
|||
/****************************************************************************
|
||||
* libc/net/lib_recvmsg.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#if defined(CONFIG_NET) && !defined(CONFIG_NET_CMSG)
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: recvmsg
|
||||
*
|
||||
* Description:
|
||||
* The recvmsg() call is identical to recvfrom() with a NULL from
|
||||
* parameter.
|
||||
*
|
||||
* Parameters:
|
||||
* sockfd Socket descriptor of socket
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* flags Receive flags
|
||||
*
|
||||
* Returned Value:
|
||||
* (see recvfrom)
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t recvmsg(int sockfd, FAR struct msghdr *msg, int flags)
|
||||
{
|
||||
FAR void *buf = msg->msg_iov->iov_base;
|
||||
FAR struct sockaddr *from = msg->msg_name;
|
||||
FAR socklen_t *fromlen = (FAR socklen_t *)&msg->msg_namelen;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
|
||||
if (msg->msg_iovlen == 1)
|
||||
{
|
||||
return recvfrom(sockfd, buf, len, flags, from, fromlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
set_errno(ENOTSUP);
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET && !CONFIG_NET_CMSG */
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
/****************************************************************************
|
||||
* libc/net/lib_sendmsg.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#if defined(CONFIG_NET) && !defined(CONFIG_NET_CMSG)
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: sendmsg
|
||||
*
|
||||
* Description:
|
||||
* The sendmsg() call is identical to sendto() with a NULL from parameter.
|
||||
*
|
||||
* Parameters:
|
||||
* sockfd Socket descriptor of socket
|
||||
* buf Buffer to send data
|
||||
* len Length of buffer
|
||||
* flags Receive flags
|
||||
*
|
||||
* Returned Value:
|
||||
* (see sendto)
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t sendmsg(int sockfd, FAR struct msghdr *msg, int flags)
|
||||
{
|
||||
FAR void *buf = msg->msg_iov->iov_base;
|
||||
FAR struct sockaddr *to = msg->msg_name;
|
||||
socklen_t tolen = msg->msg_namelen;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
|
||||
if (msg->msg_iovlen == 1)
|
||||
{
|
||||
return sendto(sockfd, buf, len, flags, to, tolen);
|
||||
}
|
||||
else
|
||||
{
|
||||
set_errno(ENOTSUP);
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET && !CONFIG_NET_CMSG */
|
||||
|
|
@ -31,8 +31,8 @@ NET_CSRCS += bluetooth_container.c
|
|||
# Socket layer
|
||||
|
||||
SOCK_CSRCS += bluetooth_sockif.c
|
||||
SOCK_CSRCS += bluetooth_sendto.c
|
||||
SOCK_CSRCS += bluetooth_recvfrom.c
|
||||
SOCK_CSRCS += bluetooth_sendmsg.c
|
||||
SOCK_CSRCS += bluetooth_recvmsg.c
|
||||
|
||||
# Device interface
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <queue.h>
|
||||
|
||||
#include <nuttx/wireless/bluetooth/bt_hci.h>
|
||||
|
|
@ -275,39 +276,35 @@ uint16_t bluetooth_callback(FAR struct radio_driver_s *radio,
|
|||
uint16_t flags);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bluetooth_recvfrom
|
||||
* Name: bluetooth_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* Implements the socket recvfrom interface for the case of the AF_INET
|
||||
* and AF_INET6 address families. bluetooth_recvfrom() receives messages
|
||||
* and AF_INET6 address families. bluetooth_recvmsg() receives messages
|
||||
* from a socket, and may be used to receive data on a socket whether or
|
||||
* not it is connection-oriented.
|
||||
*
|
||||
* If 'from' is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'fromlen' is
|
||||
* initialized to the size of the buffer associated with from, and
|
||||
* If msg_name is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'msg_namelen' is
|
||||
* initialized to the size of the buffer associated with msg_name, and
|
||||
* modified on return to indicate the actual size of the address stored
|
||||
* there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* msg Buffer to receive data
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* recv() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvfrom() for the list of appropriate error values).
|
||||
* recvmsg() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvmsg() for the list of appropriate error values).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t bluetooth_recvfrom(FAR struct socket *psock, FAR void *buf,
|
||||
size_t len, int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen);
|
||||
ssize_t bluetooth_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bluetooth_find_device
|
||||
|
|
@ -352,34 +349,28 @@ void bluetooth_poll(FAR struct net_driver_s *dev,
|
|||
FAR struct bluetooth_conn_s *conn);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_bluetooth_sendto
|
||||
* Name: bluetooth_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
|
||||
* socket, the parameters to and 'tolen' are ignored (and the error EISCONN
|
||||
* may be returned when they are not NULL and 0), and the error ENOTCONN is
|
||||
* returned when the socket was not actually connected.
|
||||
* If sendmsg() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
|
||||
* socket, the parameters msg_name and msg_namelen are ignored (and the
|
||||
* error EISCONN may be returned when they are not NULL and 0), and the
|
||||
* error ENOTCONN is returned when the socket was not actually connected.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* msg data to send
|
||||
* flags Send flags
|
||||
* to Address of recipient
|
||||
* tolen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error,
|
||||
* a negated errno value is retruend. See sendto() for the complete list
|
||||
* On success, returns the number of characters sent. On error,
|
||||
* a negated errno value is returned. See sendmsg() for the complete list
|
||||
* of return values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t psock_bluetooth_sendto(FAR struct socket *psock,
|
||||
FAR const void *buf,
|
||||
size_t len, int flags,
|
||||
FAR const struct sockaddr *to,
|
||||
socklen_t tolen);
|
||||
ssize_t bluetooth_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bluetooth_container_initialize
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/socket/bluetooth_recvfrom.c
|
||||
* net/socket/bluetooth_recvmsg.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -272,43 +272,43 @@ static uint16_t bluetooth_recvfrom_eventhandler(FAR struct net_driver_s *dev,
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bluetooth_recvfrom
|
||||
* Name: bluetooth_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* Implements the socket recvfrom interface for the case of the AF_INET
|
||||
* and AF_INET6 address families. bluetooth_recvfrom() receives messages
|
||||
* and AF_INET6 address families. bluetooth_recvmsg() receives messages
|
||||
* from a socket, and may be used to receive data on a socket whether or
|
||||
* not it is connection-oriented.
|
||||
*
|
||||
* If 'from' is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'fromlen' is
|
||||
* initialized to the size of the buffer associated with from, and
|
||||
* If msg_name is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'msg_namelen' is
|
||||
* initialized to the size of the buffer associated with msg_name, and
|
||||
* modified on return to indicate the actual size of the address stored
|
||||
* there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* msg Buffer to receive data
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* recv() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvfrom() for the list of appropriate error values).
|
||||
* recvmsg() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvmsg() for the list of appropriate error values).
|
||||
*
|
||||
* Assumptions:
|
||||
* The network is locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t bluetooth_recvfrom(FAR struct socket *psock, FAR void *buf,
|
||||
size_t len, int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen)
|
||||
ssize_t bluetooth_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
FAR void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR struct sockaddr *from = msg->msg_name;
|
||||
FAR socklen_t *fromlen = &msg->msg_namelen;
|
||||
FAR struct bluetooth_conn_s *conn =
|
||||
(FAR struct bluetooth_conn_s *)psock->s_conn;
|
||||
FAR struct radio_driver_s *radio;
|
||||
|
|
@ -330,7 +330,7 @@ ssize_t bluetooth_recvfrom(FAR struct socket *psock, FAR void *buf,
|
|||
return -EPROTONOSUPPORT;
|
||||
}
|
||||
|
||||
/* Perform the packet recvfrom() operation */
|
||||
/* Perform the packet recvmsg() operation */
|
||||
|
||||
/* Initialize the state structure. This is done with the network
|
||||
* locked because we don't want anything to happen until we are ready.
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/bluetooth/bluetooth_sendto.c
|
||||
* net/bluetooth/bluetooth_sendmsg.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -204,11 +204,7 @@ errout:
|
|||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_bluetooth_sendto
|
||||
* Name: bluetooth_sendto
|
||||
*
|
||||
* Description:
|
||||
* If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
|
||||
|
|
@ -231,16 +227,27 @@ errout:
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t psock_bluetooth_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags,
|
||||
FAR const struct sockaddr *to,
|
||||
socklen_t tolen)
|
||||
static ssize_t bluetooth_sendto(FAR struct socket *psock,
|
||||
FAR const void *buf, size_t len, int flags,
|
||||
FAR const struct sockaddr *to,
|
||||
socklen_t tolen)
|
||||
{
|
||||
FAR struct radio_driver_s *radio;
|
||||
FAR struct bluetooth_conn_s *conn;
|
||||
struct bluetooth_sendto_s state;
|
||||
int ret = OK;
|
||||
|
||||
/* Only SOCK_RAW is supported */
|
||||
|
||||
if (psock->s_type != SOCK_RAW)
|
||||
{
|
||||
/* EDESTADDRREQ. Signifies that the socket is not connection-mode and
|
||||
* no peer address is set.
|
||||
*/
|
||||
|
||||
return -EDESTADDRREQ;
|
||||
}
|
||||
|
||||
/* Verify that the sockfd corresponds to valid, allocated socket */
|
||||
|
||||
if (psock == NULL || psock->s_conn == NULL)
|
||||
|
|
@ -389,4 +396,182 @@ err_with_net:
|
|||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bluetooth_l2cap_send
|
||||
*
|
||||
* Description:
|
||||
* Socket send() method for the PF_BLUETOOTH socket over BTPROTO_L2CAP.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t bluetooth_l2cap_send(FAR struct socket *psock,
|
||||
FAR const void *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
struct sockaddr_l2 to;
|
||||
FAR struct bluetooth_conn_s *conn;
|
||||
ssize_t ret;
|
||||
|
||||
conn = (FAR struct bluetooth_conn_s *)psock->s_conn;
|
||||
DEBUGASSERT(conn != NULL);
|
||||
|
||||
if (!_SS_ISCONNECTED(psock->s_flags))
|
||||
{
|
||||
ret = -ENOTCONN;
|
||||
}
|
||||
else
|
||||
{
|
||||
to.l2_family = AF_BLUETOOTH;
|
||||
memcpy(&to.l2_bdaddr, &conn->bc_raddr, sizeof(bt_addr_t));
|
||||
to.l2_cid = conn->bc_channel;
|
||||
|
||||
/* Then perform the send() as sendto() */
|
||||
|
||||
ret = bluetooth_sendto(psock, buf, len, flags,
|
||||
(FAR const struct sockaddr *)&to,
|
||||
sizeof(struct sockaddr_l2));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bluetooth_hci_send
|
||||
*
|
||||
* Description:
|
||||
* Socket send() method for the PF_BLUETOOTH socket over BTPROTO_HCI.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t bluetooth_hci_send(FAR struct socket *psock,
|
||||
FAR const void *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
/* We only support sendto() for HCI sockets */
|
||||
|
||||
return -EPFNOSUPPORT;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bluetooth_send
|
||||
*
|
||||
* Description:
|
||||
* Socket send() method for the PF_BLUETOOTH socket.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t bluetooth_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
DEBUGASSERT(psock != NULL || buf != NULL);
|
||||
|
||||
/* Only SOCK_RAW is supported */
|
||||
|
||||
if (psock->s_type == SOCK_RAW)
|
||||
{
|
||||
switch (psock->s_proto)
|
||||
{
|
||||
case BTPROTO_L2CAP:
|
||||
{
|
||||
ret = bluetooth_l2cap_send(psock, buf, len, flags);
|
||||
break;
|
||||
}
|
||||
|
||||
case BTPROTO_HCI:
|
||||
{
|
||||
ret = bluetooth_hci_send(psock, buf, len, flags);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
ret = -EPFNOSUPPORT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bluetooth_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* If sendmsg() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
|
||||
* socket, the parameters 'msg_name' and 'msg_namelen' are ignored (and the
|
||||
* error EISCONN may be returned when they are not NULL and 0), and the
|
||||
* error ENOTCONN is returned when the socket was not actually connected.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* msg data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error,
|
||||
* a negated errno value is returned. See sendmsg() for the complete list
|
||||
* of return values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t bluetooth_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
FAR const void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR const struct sockaddr *to = msg->msg_name;
|
||||
socklen_t tolen = msg->msg_namelen;
|
||||
|
||||
/* Validity check, only single iov supported */
|
||||
|
||||
if (msg->msg_iovlen != 1)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return to ? bluetooth_sendto(psock, buf, len, flags, to, tolen) :
|
||||
bluetooth_send(psock, buf, len, flags);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_BLUETOOTH */
|
||||
|
|
@ -65,11 +65,6 @@ static int bluetooth_accept(FAR struct socket *psock,
|
|||
FAR struct socket *newsock);
|
||||
static int bluetooth_poll_local(FAR struct socket *psock,
|
||||
FAR struct pollfd *fds, bool setup);
|
||||
static ssize_t bluetooth_send(FAR struct socket *psock,
|
||||
FAR const void *buf, size_t len, int flags);
|
||||
static ssize_t bluetooth_sendto(FAR struct socket *psock,
|
||||
FAR const void *buf, size_t len, int flags,
|
||||
FAR const struct sockaddr *to, socklen_t tolen);
|
||||
static int bluetooth_close(FAR struct socket *psock);
|
||||
|
||||
/* Protocol Specific Interfaces */
|
||||
|
|
@ -79,10 +74,6 @@ static int bluetooth_l2cap_bind(FAR struct socket *psock,
|
|||
static int bluetooth_hci_bind(FAR struct socket *psock,
|
||||
FAR const struct sockaddr_hci *addr,
|
||||
socklen_t addrlen);
|
||||
static ssize_t bluetooth_l2cap_send(FAR struct socket *psock,
|
||||
FAR const void *buf, size_t len, int flags);
|
||||
static ssize_t bluetooth_hci_send(FAR struct socket *psock,
|
||||
FAR const void *buf, size_t len, int flags);
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
|
|
@ -100,16 +91,8 @@ const struct sock_intf_s g_bluetooth_sockif =
|
|||
bluetooth_connect, /* si_connect */
|
||||
bluetooth_accept, /* si_accept */
|
||||
bluetooth_poll_local, /* si_poll */
|
||||
bluetooth_send, /* si_send */
|
||||
bluetooth_sendto, /* si_sendto */
|
||||
#ifdef CONFIG_NET_SENDFILE
|
||||
NULL, /* si_sendfile */
|
||||
#endif
|
||||
bluetooth_recvfrom, /* si_recvfrom */
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
NULL, /* si_recvmsg */
|
||||
NULL, /* si_sendmsg */
|
||||
#endif
|
||||
bluetooth_sendmsg, /* si_sendmsg */
|
||||
bluetooth_recvmsg, /* si_recvmsg */
|
||||
bluetooth_close /* si_close */
|
||||
};
|
||||
|
||||
|
|
@ -747,189 +730,6 @@ static int bluetooth_poll_local(FAR struct socket *psock,
|
|||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bluetooth_send
|
||||
*
|
||||
* Description:
|
||||
* Socket send() method for the PF_BLUETOOTH socket.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t bluetooth_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
DEBUGASSERT(psock != NULL || buf != NULL);
|
||||
|
||||
/* Only SOCK_RAW is supported */
|
||||
|
||||
if (psock->s_type == SOCK_RAW)
|
||||
{
|
||||
switch (psock->s_proto)
|
||||
{
|
||||
case BTPROTO_L2CAP:
|
||||
{
|
||||
ret = bluetooth_l2cap_send(psock, buf, len, flags);
|
||||
break;
|
||||
}
|
||||
|
||||
case BTPROTO_HCI:
|
||||
{
|
||||
ret = bluetooth_hci_send(psock, buf, len, flags);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
ret = -EPFNOSUPPORT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bluetooth_l2cap_send
|
||||
*
|
||||
* Description:
|
||||
* Socket send() method for the PF_BLUETOOTH socket over BTPROTO_L2CAP.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t bluetooth_l2cap_send(FAR struct socket *psock,
|
||||
FAR const void *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
struct sockaddr_l2 to;
|
||||
FAR struct bluetooth_conn_s *conn;
|
||||
ssize_t ret;
|
||||
|
||||
conn = (FAR struct bluetooth_conn_s *)psock->s_conn;
|
||||
DEBUGASSERT(conn != NULL);
|
||||
|
||||
if (!_SS_ISCONNECTED(psock->s_flags))
|
||||
{
|
||||
ret = -ENOTCONN;
|
||||
}
|
||||
else
|
||||
{
|
||||
to.l2_family = AF_BLUETOOTH;
|
||||
memcpy(&to.l2_bdaddr, &conn->bc_raddr, sizeof(bt_addr_t));
|
||||
to.l2_cid = conn->bc_channel;
|
||||
|
||||
/* Then perform the send() as sendto() */
|
||||
|
||||
ret = psock_bluetooth_sendto(psock, buf, len, flags,
|
||||
(FAR const struct sockaddr *)&to,
|
||||
sizeof(struct sockaddr_l2));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bluetooth_hci_send
|
||||
*
|
||||
* Description:
|
||||
* Socket send() method for the PF_BLUETOOTH socket over BTPROTO_HCI.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t bluetooth_hci_send(FAR struct socket *psock,
|
||||
FAR const void *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
/* We only support sendto() for HCI sockets */
|
||||
|
||||
return -EPFNOSUPPORT;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bluetooth_sendto
|
||||
*
|
||||
* Description:
|
||||
* Implements the sendto() operation for the case of the PF_BLUETOOTH
|
||||
* socket.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
* to Address of recipient
|
||||
* tolen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send_to() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t bluetooth_sendto(FAR struct socket *psock,
|
||||
FAR const void *buf, size_t len, int flags,
|
||||
FAR const struct sockaddr *to,
|
||||
socklen_t tolen)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
/* Only SOCK_RAW is supported */
|
||||
|
||||
if (psock->s_type == SOCK_RAW)
|
||||
{
|
||||
/* Raw packet send */
|
||||
|
||||
ret = psock_bluetooth_sendto(psock, buf, len, flags, to, tolen);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* EDESTADDRREQ. Signifies that the socket is not connection-mode and
|
||||
* no peer address is set.
|
||||
*/
|
||||
|
||||
ret = -EDESTADDRREQ;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bluetooth_close
|
||||
*
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ config NET_CAN_RAW_TX_DEADLINE
|
|||
bool "TX deadline sockopt"
|
||||
default n
|
||||
depends on NET_CAN_SOCK_OPTS && NET_CAN_HAVE_TX_DEADLINE
|
||||
select NET_CMSG
|
||||
---help---
|
||||
Note: Non-standard SocketCAN sockopt, but this options helps us in
|
||||
real-time use cases.
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ ifeq ($(CONFIG_NET_CAN),y)
|
|||
# Socket layer
|
||||
|
||||
SOCK_CSRCS += can_sockif.c
|
||||
SOCK_CSRCS += can_send.c
|
||||
SOCK_CSRCS += can_recvfrom.c
|
||||
SOCK_CSRCS += can_sendmsg.c
|
||||
SOCK_CSRCS += can_recvmsg.c
|
||||
|
||||
ifeq ($(CONFIG_NET_CAN_NOTIFIER),y)
|
||||
SOCK_CSRCS += can_notifier.c
|
||||
|
|
|
|||
|
|
@ -235,34 +235,6 @@ uint16_t can_callback(FAR struct net_driver_s *dev,
|
|||
uint16_t can_datahandler(FAR struct can_conn_s *conn, FAR uint8_t *buffer,
|
||||
uint16_t buflen);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: can_recvfrom
|
||||
*
|
||||
* Description:
|
||||
* Implements the socket recvfrom interface pkt_recvfrom() receives
|
||||
* messages from a socket, and may be used to receive data on a socket
|
||||
* whether or not it is connection-oriented.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* recv() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvfrom() for the list of appropriate error values).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t can_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
||||
int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: can_recvmsg
|
||||
*
|
||||
|
|
@ -271,20 +243,19 @@ ssize_t can_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||
* data on a socket whether or not it is connection-oriented.
|
||||
*
|
||||
* If from is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'fromlen'
|
||||
* address, this source address is filled in. The argument 'msg_namelen'
|
||||
* initialized to the size of the buffer associated with from, and modified
|
||||
* on return to indicate the actual size of the address stored there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* msg Buffer to receive msg
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags (ignored)
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
|
||||
ssize_t can_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: can_poll
|
||||
|
|
@ -307,49 +278,26 @@ ssize_t can_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
|||
void can_poll(FAR struct net_driver_s *dev, FAR struct can_conn_s *conn);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_can_send
|
||||
* Name: can_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* The psock_can_send() call may be used only when the packet socket is in
|
||||
* a connected state (so that the intended recipient is known).
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error,
|
||||
* a negated errno value is returned. See send() for the complete list
|
||||
* of return values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct socket;
|
||||
ssize_t psock_can_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_can_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* The psock_can_sendmsg() call may be used only when the packet socket is
|
||||
* The can_sendmsg() call may be used only when the packet socket is
|
||||
* in a connected state (so that the intended recipient is known).
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* msg msg to send
|
||||
* msg CAN frame and optional CMSG
|
||||
* flags Send flags (ignored)
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error,
|
||||
* a negated errno value is returned. See send() for the complete list
|
||||
* a negated errno value is retruend. See sendmsg() for the complete list
|
||||
* of return values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
ssize_t psock_can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg);
|
||||
#endif
|
||||
ssize_t can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: can_readahead_signal
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/can/can_recvfrom.c
|
||||
* net/can/can_recvmsg.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -62,10 +62,8 @@ struct can_recvfrom_s
|
|||
size_t pr_buflen; /* Length of receive buffer */
|
||||
FAR uint8_t *pr_buffer; /* Pointer to receive buffer */
|
||||
ssize_t pr_recvlen; /* The received length */
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
size_t pr_msglen; /* Length of msg buffer */
|
||||
FAR uint8_t *pr_msgbuf; /* Pointer to msg buffer */
|
||||
#endif
|
||||
int pr_result; /* Success:OK, failure:negated errno */
|
||||
};
|
||||
|
||||
|
|
@ -542,139 +540,6 @@ static ssize_t can_recvfrom_result(int result,
|
|||
return pstate->pr_recvlen;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: can_recvfrom
|
||||
*
|
||||
* Description:
|
||||
* recvfrom() receives messages from a socket, and may be used to receive
|
||||
* data on a socket whether or not it is connection-oriented.
|
||||
*
|
||||
* If from is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'fromlen'
|
||||
* initialized to the size of the buffer associated with from, and modified
|
||||
* on return to indicate the actual size of the address stored there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* flags Receive flags (ignored)
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t can_recvfrom(FAR struct socket *psock, FAR void *buf,
|
||||
size_t len, int flags,
|
||||
FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen)
|
||||
{
|
||||
FAR struct can_conn_s *conn;
|
||||
FAR struct net_driver_s *dev;
|
||||
struct can_recvfrom_s state;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && buf != NULL);
|
||||
DEBUGASSERT(from == NULL ||
|
||||
(fromlen != NULL && *fromlen >= sizeof(struct sockaddr_can)));
|
||||
|
||||
conn = (FAR struct can_conn_s *)psock->s_conn;
|
||||
|
||||
if (psock->s_type != SOCK_RAW)
|
||||
{
|
||||
nerr("ERROR: Unsupported socket type: %d\n", psock->s_type);
|
||||
ret = -ENOSYS;
|
||||
}
|
||||
|
||||
net_lock();
|
||||
|
||||
/* Initialize the state structure. */
|
||||
|
||||
memset(&state, 0, sizeof(struct can_recvfrom_s));
|
||||
|
||||
/* This semaphore is used for signaling and, hence, should not have
|
||||
* priority inheritance enabled.
|
||||
*/
|
||||
|
||||
nxsem_init(&state.pr_sem, 0, 0); /* Doesn't really fail */
|
||||
nxsem_set_protocol(&state.pr_sem, SEM_PRIO_NONE);
|
||||
|
||||
state.pr_buflen = len;
|
||||
state.pr_buffer = buf;
|
||||
state.pr_sock = psock;
|
||||
|
||||
/* Handle any any CAN data already buffered in a read-ahead buffer. NOTE
|
||||
* that there may be read-ahead data to be retrieved even after the
|
||||
* socket has been disconnected.
|
||||
*/
|
||||
|
||||
ret = can_readahead(&state);
|
||||
if (ret > 0)
|
||||
{
|
||||
goto errout_with_state;
|
||||
}
|
||||
|
||||
ret = state.pr_recvlen;
|
||||
|
||||
/* Handle non-blocking CAN sockets */
|
||||
|
||||
if (_SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0)
|
||||
{
|
||||
/* Return the number of bytes read from the read-ahead buffer if
|
||||
* something was received (already in 'ret'); EAGAIN if not.
|
||||
*/
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
/* Nothing was received */
|
||||
|
||||
ret = -EAGAIN;
|
||||
goto errout_with_state;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the device driver that will service this transfer */
|
||||
|
||||
dev = conn->dev;
|
||||
if (dev == NULL)
|
||||
{
|
||||
ret = -ENODEV;
|
||||
goto errout_with_state;
|
||||
}
|
||||
|
||||
/* Set up the callback in the connection */
|
||||
|
||||
state.pr_cb = can_callback_alloc(dev, conn);
|
||||
if (state.pr_cb)
|
||||
{
|
||||
state.pr_cb->flags = (CAN_NEWDATA | CAN_POLL);
|
||||
state.pr_cb->priv = (FAR void *)&state;
|
||||
state.pr_cb->event = can_recvfrom_eventhandler;
|
||||
|
||||
/* Wait for either the receive to complete or for an error/timeout to
|
||||
* occur. NOTES: (1) net_lockedwait will also terminate if a signal
|
||||
* is received, (2) the network is locked! It will be un-locked while
|
||||
* the task sleeps and automatically re-locked when the task restarts.
|
||||
*/
|
||||
|
||||
ret = net_lockedwait(&state.pr_sem);
|
||||
|
||||
/* Make sure that no further events are processed */
|
||||
|
||||
can_callback_free(dev, conn, state.pr_cb);
|
||||
ret = can_recvfrom_result(ret, &state);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -EBUSY;
|
||||
}
|
||||
|
||||
errout_with_state:
|
||||
net_unlock();
|
||||
nxsem_destroy(&state.pr_sem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: can_recvmsg
|
||||
*
|
||||
|
|
@ -683,18 +548,17 @@ errout_with_state:
|
|||
* data on a socket whether or not it is connection-oriented.
|
||||
*
|
||||
* If from is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'fromlen'
|
||||
* address, this source address is filled in. The argument 'msg_namelen'
|
||||
* initialized to the size of the buffer associated with from, and modified
|
||||
* on return to indicate the actual size of the address stored there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* msg Buffer to receive msg
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags (ignored)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
ssize_t can_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
|
|
@ -703,7 +567,7 @@ ssize_t can_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
|||
struct can_recvfrom_s state;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && msg != NULL);
|
||||
DEBUGASSERT(psock != NULL && psock->s_conn != NULL);
|
||||
|
||||
conn = (FAR struct can_conn_s *)psock->s_conn;
|
||||
|
||||
|
|
@ -841,6 +705,5 @@ errout_with_state:
|
|||
nxsem_destroy(&state.pr_sem);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_NET_CAN */
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/can/can_send.c
|
||||
* net/can/can_sendmsg.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -46,9 +46,7 @@
|
|||
#include "socket/socket.h"
|
||||
#include "can/can.h"
|
||||
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
|
|
@ -65,10 +63,8 @@ struct send_s
|
|||
sem_t snd_sem; /* Used to wake up the waiting thread */
|
||||
FAR const uint8_t *snd_buffer; /* Points to the buffer of data to send */
|
||||
size_t snd_buflen; /* Number of bytes in the buffer to send */
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
size_t pr_msglen; /* Length of msg buffer */
|
||||
FAR uint8_t *pr_msgbuf; /* Pointer to msg buffer */
|
||||
#endif
|
||||
ssize_t snd_sent; /* The number of bytes sent */
|
||||
};
|
||||
|
||||
|
|
@ -114,14 +110,12 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
|
|||
|
||||
devif_can_send(dev, pstate->snd_buffer, pstate->snd_buflen);
|
||||
pstate->snd_sent = pstate->snd_buflen;
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
if (pstate->pr_msglen > 0) /* concat cmsg data after packet */
|
||||
{
|
||||
memcpy(dev->d_buf + pstate->snd_buflen, pstate->pr_msgbuf,
|
||||
pstate->pr_msglen);
|
||||
dev->d_sndlen = pstate->snd_buflen + pstate->pr_msglen;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Don't allow any further call backs. */
|
||||
|
|
@ -143,158 +137,26 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_can_send
|
||||
* Name: can_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* The psock_can_send() call may be used only when the packet socket is in
|
||||
* a connected state (so that the intended recipient is known).
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error,
|
||||
* a negated errno value is retruend. See send() for the complete list
|
||||
* of return values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t psock_can_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len)
|
||||
{
|
||||
FAR struct net_driver_s *dev;
|
||||
FAR struct can_conn_s *conn;
|
||||
struct send_s state;
|
||||
int ret = OK;
|
||||
|
||||
/* Verify that the sockfd corresponds to valid, allocated socket */
|
||||
|
||||
if (psock == NULL || psock->s_conn == NULL)
|
||||
{
|
||||
return -EBADF;
|
||||
}
|
||||
|
||||
conn = (FAR struct can_conn_s *)psock->s_conn;
|
||||
|
||||
/* Get the device driver that will service this transfer */
|
||||
|
||||
dev = conn->dev;
|
||||
if (dev == NULL)
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
#if defined(CONFIG_NET_CANPROTO_OPTIONS) && defined(CONFIG_NET_CAN_CANFD)
|
||||
|
||||
if (conn->fd_frames)
|
||||
{
|
||||
if (len != CANFD_MTU && len != CAN_MTU)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
if (len != CAN_MTU)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Perform the send operation */
|
||||
|
||||
/* Initialize the state structure. This is done with the network locked
|
||||
* because we don't want anything to happen until we are ready.
|
||||
*/
|
||||
|
||||
net_lock();
|
||||
memset(&state, 0, sizeof(struct send_s));
|
||||
|
||||
/* This semaphore is used for signaling and, hence, should not have
|
||||
* priority inheritance enabled.
|
||||
*/
|
||||
|
||||
nxsem_init(&state.snd_sem, 0, 0); /* Doesn't really fail */
|
||||
nxsem_set_protocol(&state.snd_sem, SEM_PRIO_NONE);
|
||||
|
||||
state.snd_sock = psock; /* Socket descriptor to use */
|
||||
state.snd_buflen = len; /* Number of bytes to send */
|
||||
state.snd_buffer = buf; /* Buffer to send from */
|
||||
|
||||
/* Allocate resource to receive a callback */
|
||||
|
||||
state.snd_cb = can_callback_alloc(dev, conn);
|
||||
if (state.snd_cb)
|
||||
{
|
||||
/* Set up the callback in the connection */
|
||||
|
||||
state.snd_cb->flags = CAN_POLL;
|
||||
state.snd_cb->priv = (FAR void *)&state;
|
||||
state.snd_cb->event = psock_send_eventhandler;
|
||||
|
||||
/* Notify the device driver that new TX data is available. */
|
||||
|
||||
netdev_txnotify_dev(dev);
|
||||
|
||||
/* Wait for the send to complete or an error to occur.
|
||||
* net_lockedwait will also terminate if a signal is received.
|
||||
*/
|
||||
|
||||
ret = net_lockedwait(&state.snd_sem);
|
||||
|
||||
/* Make sure that no further events are processed */
|
||||
|
||||
can_callback_free(dev, conn, state.snd_cb);
|
||||
}
|
||||
|
||||
nxsem_destroy(&state.snd_sem);
|
||||
net_unlock();
|
||||
|
||||
/* Check for a errors, Errors are signalled by negative errno values
|
||||
* for the send length
|
||||
*/
|
||||
|
||||
if (state.snd_sent < 0)
|
||||
{
|
||||
return state.snd_sent;
|
||||
}
|
||||
|
||||
/* If net_lockedwait failed, then we were probably reawakened by a signal.
|
||||
* In this case, net_lockedwait will have returned negated errno
|
||||
* appropriately.
|
||||
*/
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Return the number of bytes actually sent */
|
||||
|
||||
return state.snd_sent;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_can_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* The psock_can_sendmsg() call may be used only when the packet socket is
|
||||
* The can_sendmsg() call may be used only when the packet socket is
|
||||
* in a connected state (so that the intended recipient is known).
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* msg msg to send
|
||||
* msg CAN frame and optional CMSG
|
||||
* flags Send flags (ignored)
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error,
|
||||
* a negated errno value is retruend. See send() for the complete list
|
||||
* a negated errno value is retruend. See sendmsg() for the complete list
|
||||
* of return values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t psock_can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg)
|
||||
ssize_t can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
FAR struct net_driver_s *dev;
|
||||
FAR struct can_conn_s *conn;
|
||||
|
|
@ -308,6 +170,17 @@ ssize_t psock_can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg)
|
|||
return -EBADF;
|
||||
}
|
||||
|
||||
/* Only SOCK_RAW is supported */
|
||||
|
||||
if (psock->s_type != SOCK_RAW)
|
||||
{
|
||||
/* EDESTADDRREQ. Signifies that the socket is not connection-mode and
|
||||
* no peer address is set.
|
||||
*/
|
||||
|
||||
return -EDESTADDRREQ;
|
||||
}
|
||||
|
||||
conn = (FAR struct can_conn_s *)psock->s_conn;
|
||||
|
||||
/* Get the device driver that will service this transfer */
|
||||
|
|
@ -64,15 +64,6 @@ static int can_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||
FAR socklen_t *addrlen, FAR struct socket *newsock);
|
||||
static int can_poll_local(FAR struct socket *psock, FAR struct pollfd *fds,
|
||||
bool setup);
|
||||
static ssize_t can_send(FAR struct socket *psock,
|
||||
FAR const void *buf, size_t len, int flags);
|
||||
static ssize_t can_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags, FAR const struct sockaddr *to,
|
||||
socklen_t tolen);
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
static ssize_t can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
#endif
|
||||
static int can_close(FAR struct socket *psock);
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -91,16 +82,8 @@ const struct sock_intf_s g_can_sockif =
|
|||
can_connect, /* si_connect */
|
||||
can_accept, /* si_accept */
|
||||
can_poll_local, /* si_poll */
|
||||
can_send, /* si_send */
|
||||
can_sendto, /* si_sendto */
|
||||
#ifdef CONFIG_NET_SENDFILE
|
||||
NULL, /* si_sendfile */
|
||||
#endif
|
||||
can_recvfrom, /* si_recvfrom */
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
can_recvmsg, /* si_recvmsg */
|
||||
can_sendmsg, /* si_sendmsg */
|
||||
#endif
|
||||
can_recvmsg, /* si_recvmsg */
|
||||
can_close /* si_close */
|
||||
};
|
||||
|
||||
|
|
@ -675,128 +658,6 @@ errout_with_lock:
|
|||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: can_send
|
||||
*
|
||||
* Description:
|
||||
* The can_send() call may be used only when the socket is in
|
||||
* a connected state (so that the intended recipient is known).
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock - An instance of the internal socket structure.
|
||||
* buf - Data to send
|
||||
* len - Length of data to send
|
||||
* flags - Send flags (ignored)
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t can_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
/* Only SOCK_RAW is supported */
|
||||
|
||||
if (psock->s_type == SOCK_RAW)
|
||||
{
|
||||
/* Raw packet send */
|
||||
|
||||
ret = psock_can_send(psock, buf, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* EDESTADDRREQ. Signifies that the socket is not connection-mode and
|
||||
* no peer address is set.
|
||||
*/
|
||||
|
||||
ret = -EDESTADDRREQ;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: can_sendto
|
||||
*
|
||||
* Description:
|
||||
* If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
|
||||
* socket, the parameters to and 'tolen' are ignored (and the error EISCONN
|
||||
* may be returned when they are not NULL and 0), and the error ENOTCONN is
|
||||
* returned when the socket was not actually connected.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A reference to the socket structure of the socket
|
||||
* to be connected
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags (ignored)
|
||||
* to Address of recipient
|
||||
* tolen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t can_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags,
|
||||
FAR const struct sockaddr *to, socklen_t tolen)
|
||||
{
|
||||
nerr("ERROR: sendto() not supported for raw packet sockets\n");
|
||||
return -EAFNOSUPPORT;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: can_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* The can_sendmsg() send a CAN frame to psock
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock - An instance of the internal socket structure.
|
||||
* msg - CAN frame and optional CMSG
|
||||
* flags - Send flags (ignored)
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
static ssize_t can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
/* Only SOCK_RAW is supported */
|
||||
|
||||
if (psock->s_type == SOCK_RAW)
|
||||
{
|
||||
/* Raw packet send */
|
||||
|
||||
ret = psock_can_sendmsg(psock, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* EDESTADDRREQ. Signifies that the socket is not connection-mode and
|
||||
* no peer address is set.
|
||||
*/
|
||||
|
||||
ret = -EDESTADDRREQ;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: can_close
|
||||
*
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ ifneq ($(CONFIG_NET_ICMP_NO_STACK),y)
|
|||
NET_CSRCS += icmp_input.c
|
||||
|
||||
ifeq ($(CONFIG_NET_ICMP_SOCKET),y)
|
||||
SOCK_CSRCS += icmp_sockif.c icmp_poll.c icmp_conn.c icmp_sendto.c
|
||||
SOCK_CSRCS += icmp_recvfrom.c icmp_netpoll.c
|
||||
SOCK_CSRCS += icmp_sockif.c icmp_poll.c icmp_conn.c icmp_sendmsg.c
|
||||
SOCK_CSRCS += icmp_recvmsg.c icmp_netpoll.c
|
||||
endif
|
||||
|
||||
# Include ICMP build support
|
||||
|
|
|
|||
|
|
@ -263,10 +263,10 @@ void icmp_poll(FAR struct net_driver_s *dev, FAR struct icmp_conn_s *conn);
|
|||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: icmp_sendto
|
||||
* Name: icmp_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* Implements the sendto() operation for the case of the IPPROTO_ICMP
|
||||
* Implements the sendmsg() operation for the case of the IPPROTO_ICMP
|
||||
* socket. The 'buf' parameter points to a block of memory that includes
|
||||
* an ICMP request header, followed by any payload that accompanies the
|
||||
* request. The 'len' parameter includes both the size of the ICMP header
|
||||
|
|
@ -274,59 +274,51 @@ void icmp_poll(FAR struct net_driver_s *dev, FAR struct icmp_conn_s *conn);
|
|||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* msg Message to send
|
||||
* flags Send flags
|
||||
* to Address of recipient
|
||||
* tolen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send_to() for the list of appropriate error
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see sendmsg() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_ICMP_SOCKET
|
||||
ssize_t icmp_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags, FAR const struct sockaddr *to,
|
||||
socklen_t tolen);
|
||||
ssize_t icmp_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: icmp_recvfrom
|
||||
* Name: icmp_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* Implements the socket recvfrom interface for the case of the AF_INET
|
||||
* data gram socket with the IPPROTO_ICMP protocol. icmp_recvfrom()
|
||||
* data gram socket with the IPPROTO_ICMP protocol. icmp_recvmsg()
|
||||
* receives ICMP ECHO replies for the a socket.
|
||||
*
|
||||
* If 'from' is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'fromlen' is
|
||||
* initialized to the size of the buffer associated with from, and
|
||||
* If msg_name is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'msg_namelen' is
|
||||
* initialized to the size of the buffer associated with msg_name, and
|
||||
* modified on return to indicate the actual size of the address stored
|
||||
* there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* recv() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvfrom() for the list of appropriate error values).
|
||||
* recvmsg() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvmsg() for the list of appropriate error values).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_ICMP_SOCKET
|
||||
ssize_t icmp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
||||
int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen);
|
||||
ssize_t icmp_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/icmp/icmp_recvfrom.c
|
||||
* net/icmp/icmp_recvmsg.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -317,39 +317,39 @@ out:
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: icmp_recvfrom
|
||||
* Name: icmp_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* Implements the socket recvfrom interface for the case of the AF_INET
|
||||
* data gram socket with the IPPROTO_ICMP protocol. icmp_recvfrom()
|
||||
* data gram socket with the IPPROTO_ICMP protocol. icmp_recvmsg()
|
||||
* receives ICMP ECHO replies for the a socket.
|
||||
*
|
||||
* If 'from' is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'fromlen' is
|
||||
* initialized to the size of the buffer associated with from, and
|
||||
* If msg_name is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'msg_namelen' is
|
||||
* initialized to the size of the buffer associated with msg_name, and
|
||||
* modified on return to indicate the actual size of the address stored
|
||||
* there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* recv() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvfrom() for the list of appropriate error values).
|
||||
* recvmsg() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvmsg() for the list of appropriate error values).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t icmp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
||||
int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen)
|
||||
ssize_t icmp_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
FAR void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR struct sockaddr *from = msg->msg_name;
|
||||
FAR socklen_t *fromlen = &msg->msg_namelen;
|
||||
FAR struct sockaddr_in *inaddr;
|
||||
FAR struct icmp_conn_s *conn;
|
||||
FAR struct net_driver_s *dev;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/icmp/icmp_sendto.c
|
||||
* net/icmp/icmp_sendmsg.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -259,10 +259,10 @@ end_wait:
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: icmp_sendto
|
||||
* Name: icmp_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* Implements the sendto() operation for the case of the IPPROTO_ICMP
|
||||
* Implements the sendmsg() operation for the case of the IPPROTO_ICMP
|
||||
* socket. The 'buf' parameter points to a block of memory that includes
|
||||
* an ICMP request header, followed by any payload that accompanies the
|
||||
* request. The 'len' parameter includes both the size of the ICMP header
|
||||
|
|
@ -270,29 +270,47 @@ end_wait:
|
|||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* msg Message to send
|
||||
* flags Send flags
|
||||
* to Address of recipient
|
||||
* tolen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send_to() for the list of appropriate error
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see sendmsg() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t icmp_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags, FAR const struct sockaddr *to,
|
||||
socklen_t tolen)
|
||||
ssize_t icmp_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
FAR const void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR const struct sockaddr *to = msg->msg_name;
|
||||
socklen_t tolen = msg->msg_namelen;
|
||||
FAR const struct sockaddr_in *inaddr;
|
||||
FAR struct net_driver_s *dev;
|
||||
FAR struct icmp_conn_s *conn;
|
||||
FAR struct icmp_hdr_s *icmp;
|
||||
struct icmp_sendto_s state;
|
||||
int ret;
|
||||
ssize_t ret;
|
||||
|
||||
/* Validity check, only single iov supported */
|
||||
|
||||
if (msg->msg_iovlen != 1)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (to == NULL)
|
||||
{
|
||||
/* icmp_send() */
|
||||
|
||||
/* ICMP sockets cannot be bound and, hence, cannot support any
|
||||
* connection-oriented data transfer.
|
||||
*/
|
||||
|
||||
return -EDESTADDRREQ;
|
||||
}
|
||||
|
||||
/* Some sanity checks */
|
||||
|
||||
|
|
@ -61,8 +61,6 @@ static int icmp_accept(FAR struct socket *psock,
|
|||
FAR struct socket *newsock);
|
||||
static int icmp_netpoll(FAR struct socket *psock,
|
||||
FAR struct pollfd *fds, bool setup);
|
||||
static ssize_t icmp_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags);
|
||||
static int icmp_close(FAR struct socket *psock);
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -81,16 +79,8 @@ const struct sock_intf_s g_icmp_sockif =
|
|||
icmp_connect, /* si_connect */
|
||||
icmp_accept, /* si_accept */
|
||||
icmp_netpoll, /* si_poll */
|
||||
icmp_send, /* si_send */
|
||||
icmp_sendto, /* si_sendto */
|
||||
#ifdef CONFIG_NET_SENDFILE
|
||||
NULL, /* si_sendfile */
|
||||
#endif
|
||||
icmp_recvfrom, /* si_recvfrom */
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
NULL, /* si_recvmsg */
|
||||
NULL, /* si_sendmsg */
|
||||
#endif
|
||||
icmp_sendmsg, /* si_sendmsg */
|
||||
icmp_recvmsg, /* si_recvmsg */
|
||||
icmp_close /* si_close */
|
||||
};
|
||||
|
||||
|
|
@ -452,35 +442,6 @@ static int icmp_netpoll(FAR struct socket *psock, FAR struct pollfd *fds,
|
|||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: icmp_send
|
||||
*
|
||||
* Description:
|
||||
* Socket send() method for the raw packet socket.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t icmp_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
/* ICMP sockets cannot be bound and, hence, cannot support any connection-
|
||||
* oriented data transfer.
|
||||
*/
|
||||
|
||||
return -EDESTADDRREQ;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: icmp_close
|
||||
*
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ NET_CSRCS += icmpv6_input.c icmpv6_solicit.c icmpv6_advertise.c
|
|||
NET_CSRCS += icmpv6_linkipaddr.c
|
||||
|
||||
ifeq ($(CONFIG_NET_ICMPv6_SOCKET),y)
|
||||
SOCK_CSRCS += icmpv6_sockif.c icmpv6_conn.c icmpv6_sendto.c
|
||||
SOCK_CSRCS += icmpv6_recvfrom.c icmpv6_netpoll.c
|
||||
SOCK_CSRCS += icmpv6_sockif.c icmpv6_conn.c icmpv6_sendmsg.c
|
||||
SOCK_CSRCS += icmpv6_recvmsg.c icmpv6_netpoll.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NET_ICMPv6_NEIGHBOR),y)
|
||||
|
|
|
|||
|
|
@ -604,10 +604,10 @@ FAR struct icmpv6_conn_s *icmpv6_findconn(FAR struct net_driver_s *dev,
|
|||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: icmpv6_sendto
|
||||
* Name: icmpv6_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* Implements the sendto() operation for the case of the IPPROTO_ICMP6
|
||||
* Implements the sendmsg() operation for the case of the IPPROTO_ICMP6
|
||||
* socket. The 'buf' parameter points to a block of memory that includes
|
||||
* an ICMPv6 request header, followed by any payload that accompanies the
|
||||
* request. The 'len' parameter includes both the size of the ICMPv6
|
||||
|
|
@ -615,62 +615,51 @@ FAR struct icmpv6_conn_s *icmpv6_findconn(FAR struct net_driver_s *dev,
|
|||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* msg Message to send
|
||||
* flags Send flags
|
||||
* to Address of recipient
|
||||
* tolen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send_to() for the list of appropriate error
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see sendmsg() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_SOCKET
|
||||
ssize_t icmpv6_sendto(FAR struct socket *psock,
|
||||
FAR const void *buf,
|
||||
size_t len,
|
||||
int flags,
|
||||
FAR const struct sockaddr *to,
|
||||
socklen_t tolen);
|
||||
ssize_t icmpv6_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: icmpv6_recvfrom
|
||||
* Name: icmpv6_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* Implements the socket recvfrom interface for the case of the AF_INET6
|
||||
* data gram socket with the IPPROTO_ICMP6 protocol. icmpv6_recvfrom()
|
||||
* Implements the socket recvfrom interface for the case of the AF_INET
|
||||
* data gram socket with the IPPROTO_ICMP6 protocol. icmpv6_recvmsg()
|
||||
* receives ICMPv6 ECHO replies for the a socket.
|
||||
*
|
||||
* If 'from' is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'fromlen' is
|
||||
* initialized to the size of the buffer associated with from, and
|
||||
* If msg_name is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'msg_namelen' is
|
||||
* initialized to the size of the buffer associated with msg_name, and
|
||||
* modified on return to indicate the actual size of the address stored
|
||||
* there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* recv() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvfrom() for the list of appropriate error values).
|
||||
* recvmsg() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvmsg() for the list of appropriate error values).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_SOCKET
|
||||
ssize_t icmpv6_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
||||
int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen);
|
||||
ssize_t icmpv6_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/icmpv6/icmpv6_recvfrom.c
|
||||
* net/icmpv6/icmpv6_recvmsg.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -324,39 +324,39 @@ out:
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: icmpv6_recvfrom
|
||||
* Name: icmpv6_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* Implements the socket recvfrom interface for the case of the AF_INET
|
||||
* data gram socket with the IPPROTO_ICMP6 protocol. icmpv6_recvfrom()
|
||||
* data gram socket with the IPPROTO_ICMP6 protocol. icmpv6_recvmsg()
|
||||
* receives ICMPv6 ECHO replies for the a socket.
|
||||
*
|
||||
* If 'from' is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'fromlen' is
|
||||
* initialized to the size of the buffer associated with from, and
|
||||
* If msg_name is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'msg_namelen' is
|
||||
* initialized to the size of the buffer associated with msg_name, and
|
||||
* modified on return to indicate the actual size of the address stored
|
||||
* there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* recv() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvfrom() for the list of appropriate error values).
|
||||
* recvmsg() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvmsg() for the list of appropriate error values).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t icmpv6_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
||||
int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen)
|
||||
ssize_t icmpv6_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
FAR void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR struct sockaddr *from = msg->msg_name;
|
||||
FAR socklen_t *fromlen = &msg->msg_namelen;
|
||||
FAR struct sockaddr_in6 *inaddr;
|
||||
FAR struct icmpv6_conn_s *conn;
|
||||
FAR struct net_driver_s *dev;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/icmpv6/icmpv6_sendto.c
|
||||
* net/icmpv6/icmpv6_sendmsg.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -249,10 +249,10 @@ end_wait:
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: icmpv6_sendto
|
||||
* Name: icmpv6_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* Implements the sendto() operation for the case of the IPPROTO_ICMP6
|
||||
* Implements the sendmsg() operation for the case of the IPPROTO_ICMP6
|
||||
* socket. The 'buf' parameter points to a block of memory that includes
|
||||
* an ICMPv6 request header, followed by any payload that accompanies the
|
||||
* request. The 'len' parameter includes both the size of the ICMPv6
|
||||
|
|
@ -260,29 +260,47 @@ end_wait:
|
|||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* msg Message to send
|
||||
* flags Send flags
|
||||
* to Address of recipient
|
||||
* tolen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send_to() for the list of appropriate error
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see sendmsg() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t icmpv6_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags, FAR const struct sockaddr *to,
|
||||
socklen_t tolen)
|
||||
ssize_t icmpv6_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
FAR const void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR const struct sockaddr *to = msg->msg_name;
|
||||
socklen_t tolen = msg->msg_namelen;
|
||||
FAR const struct sockaddr_in6 *inaddr;
|
||||
FAR struct net_driver_s *dev;
|
||||
FAR struct icmpv6_conn_s *conn;
|
||||
FAR struct icmpv6_echo_request_s *icmpv6;
|
||||
struct icmpv6_sendto_s state;
|
||||
int ret;
|
||||
ssize_t ret;
|
||||
|
||||
/* Validity check, only single iov supported */
|
||||
|
||||
if (msg->msg_iovlen != 1)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (to == NULL)
|
||||
{
|
||||
/* icmpv6_send() */
|
||||
|
||||
/* ICMPv6 sockets cannot be bound and, hence, cannot support any
|
||||
* connection-oriented data transfer.
|
||||
*/
|
||||
|
||||
return -EDESTADDRREQ;
|
||||
}
|
||||
|
||||
/* Some sanity checks */
|
||||
|
||||
|
|
@ -61,8 +61,6 @@ static int icmpv6_accept(FAR struct socket *psock,
|
|||
FAR struct socket *newsock);
|
||||
static int icmpv6_netpoll(FAR struct socket *psock,
|
||||
FAR struct pollfd *fds, bool setup);
|
||||
static ssize_t icmpv6_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags);
|
||||
static int icmpv6_close(FAR struct socket *psock);
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -81,16 +79,8 @@ const struct sock_intf_s g_icmpv6_sockif =
|
|||
icmpv6_connect, /* si_connect */
|
||||
icmpv6_accept, /* si_accept */
|
||||
icmpv6_netpoll, /* si_poll */
|
||||
icmpv6_send, /* si_send */
|
||||
icmpv6_sendto, /* si_sendto */
|
||||
#ifdef CONFIG_NET_SENDFILE
|
||||
NULL, /* si_sendfile */
|
||||
#endif
|
||||
icmpv6_recvfrom, /* si_recvfrom */
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
NULL, /* si_recvmsg */
|
||||
NULL, /* si_sendmsg */
|
||||
#endif
|
||||
icmpv6_sendmsg, /* si_sendmsg */
|
||||
icmpv6_recvmsg, /* si_recvmsg */
|
||||
icmpv6_close /* si_close */
|
||||
};
|
||||
|
||||
|
|
@ -452,35 +442,6 @@ static int icmpv6_netpoll(FAR struct socket *psock, FAR struct pollfd *fds,
|
|||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: icmpv6_send
|
||||
*
|
||||
* Description:
|
||||
* Socket send() method for the raw packet socket.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t icmpv6_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
/* ICMPv6 sockets cannot be bound and, hence, cannot support any
|
||||
* connection-oriented data transfer.
|
||||
*/
|
||||
|
||||
return -EDESTADDRREQ;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: icmpv6_close
|
||||
*
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ NET_CSRCS += ieee802154_container.c
|
|||
# Socket layer
|
||||
|
||||
SOCK_CSRCS += ieee802154_sockif.c
|
||||
SOCK_CSRCS += ieee802154_sendto.c
|
||||
SOCK_CSRCS += ieee802154_recvfrom.c
|
||||
SOCK_CSRCS += ieee802154_sendmsg.c
|
||||
SOCK_CSRCS += ieee802154_recvmsg.c
|
||||
|
||||
# Device interface
|
||||
|
||||
|
|
|
|||
|
|
@ -290,39 +290,35 @@ uint16_t ieee802154_callback(FAR struct radio_driver_s *radio,
|
|||
uint16_t flags);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ieee802154_recvfrom
|
||||
* Name: ieee802154_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* Implements the socket recvfrom interface for the case of the AF_INET
|
||||
* and AF_INET6 address families. ieee802154_recvfrom() receives messages
|
||||
* and AF_INET6 address families. ieee802154_recvmsg() receives messages
|
||||
* from a socket, and may be used to receive data on a socket whether or
|
||||
* not it is connection-oriented.
|
||||
*
|
||||
* If 'from' is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'fromlen' is
|
||||
* initialized to the size of the buffer associated with from, and
|
||||
* If msg_name is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'msg_namelen' is
|
||||
* initialized to the size of the buffer associated with msg_name, and
|
||||
* modified on return to indicate the actual size of the address stored
|
||||
* there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* recv() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvfrom() for the list of appropriate error values).
|
||||
* recvmsg() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvmsg() for the list of appropriate error values).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t ieee802154_recvfrom(FAR struct socket *psock, FAR void *buf,
|
||||
size_t len, int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen);
|
||||
ssize_t ieee802154_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ieee802154_find_device
|
||||
|
|
@ -367,34 +363,28 @@ void ieee802154_poll(FAR struct net_driver_s *dev,
|
|||
FAR struct ieee802154_conn_s *conn);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_ieee802154_sendto
|
||||
* Name: ieee802154_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
|
||||
* socket, the parameters to and 'tolen' are ignored (and the error EISCONN
|
||||
* may be returned when they are not NULL and 0), and the error ENOTCONN is
|
||||
* returned when the socket was not actually connected.
|
||||
* If sendmsg() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
|
||||
* socket, the parameters 'msg_name' and 'msg_namelen' are ignored (and the
|
||||
* error EISCONN may be returned when they are not NULL and 0), and the
|
||||
* error ENOTCONN is returned when the socket was not actually connected.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* psock An instance of the internal socket structure.
|
||||
* msg Message to send
|
||||
* flags Send flags
|
||||
* to Address of recipient
|
||||
* tolen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error,
|
||||
* a negated errno value is retruend. See sendto() for the complete list
|
||||
* of return values.
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see sendmsg() for the complete list of return
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t psock_ieee802154_sendto(FAR struct socket *psock,
|
||||
FAR const void *buf,
|
||||
size_t len, int flags,
|
||||
FAR const struct sockaddr *to,
|
||||
socklen_t tolen);
|
||||
ssize_t ieee802154_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ieee802154_container_initialize
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/socket/ieee802154_recvfrom.c
|
||||
* net/socket/ieee802154_recvmsg.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -272,43 +272,43 @@ static uint16_t
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ieee802154_recvfrom
|
||||
* Name: ieee802154_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* Implements the socket recvfrom interface for the case of the AF_INET
|
||||
* and AF_INET6 address families. ieee802154_recvfrom() receives messages
|
||||
* and AF_INET6 address families. ieee802154_recvmsg() receives messages
|
||||
* from a socket, and may be used to receive data on a socket whether or
|
||||
* not it is connection-oriented.
|
||||
*
|
||||
* If 'from' is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'fromlen' is
|
||||
* initialized to the size of the buffer associated with from, and
|
||||
* If msg_name is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'msg_namelen' is
|
||||
* initialized to the size of the buffer associated with msg_name, and
|
||||
* modified on return to indicate the actual size of the address stored
|
||||
* there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* recv() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvfrom() for the list of appropriate error values).
|
||||
* recvmsg() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvmsg() for the list of appropriate error values).
|
||||
*
|
||||
* Assumptions:
|
||||
* The network is locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t ieee802154_recvfrom(FAR struct socket *psock, FAR void *buf,
|
||||
size_t len, int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen)
|
||||
ssize_t ieee802154_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
FAR void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR struct sockaddr *from = msg->msg_name;
|
||||
FAR socklen_t *fromlen = &msg->msg_namelen;
|
||||
FAR struct ieee802154_conn_s *conn =
|
||||
(FAR struct ieee802154_conn_s *)psock->s_conn;
|
||||
FAR struct radio_driver_s *radio;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/ieee802154/ieee802154_sendto.c
|
||||
* net/ieee802154/ieee802154_sendmsg.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -391,11 +391,7 @@ errout:
|
|||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_ieee802154_sendto
|
||||
* Name: ieee802154_sendto
|
||||
*
|
||||
* Description:
|
||||
* If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
|
||||
|
|
@ -418,10 +414,11 @@ errout:
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t psock_ieee802154_sendto(FAR struct socket *psock,
|
||||
FAR const void *buf, size_t len, int flags,
|
||||
FAR const struct sockaddr *to,
|
||||
socklen_t tolen)
|
||||
static ssize_t ieee802154_sendto(FAR struct socket *psock,
|
||||
FAR const void *buf,
|
||||
size_t len, int flags,
|
||||
FAR const struct sockaddr *to,
|
||||
socklen_t tolen)
|
||||
{
|
||||
FAR struct sockaddr_ieee802154_s *destaddr;
|
||||
FAR struct radio_driver_s *radio;
|
||||
|
|
@ -436,6 +433,17 @@ ssize_t psock_ieee802154_sendto(FAR struct socket *psock,
|
|||
return -EBADF;
|
||||
}
|
||||
|
||||
/* Only SOCK_DGRAM is supported (because the MAC header is stripped) */
|
||||
|
||||
if (psock->s_type != SOCK_DGRAM)
|
||||
{
|
||||
/* EDESTADDRREQ. Signifies that the socket is not connection-mode and
|
||||
* no peer address is set.
|
||||
*/
|
||||
|
||||
return -EDESTADDRREQ;
|
||||
}
|
||||
|
||||
conn = (FAR struct ieee802154_conn_s *)psock->s_conn;
|
||||
|
||||
/* Verify that the address is large enough to be a valid PF_IEEE802154
|
||||
|
|
@ -538,4 +546,111 @@ ssize_t psock_ieee802154_sendto(FAR struct socket *psock,
|
|||
return state.is_sent;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ieee802154_send
|
||||
*
|
||||
* Description:
|
||||
* Socket send() method for the PF_IEEE802154 socket.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t ieee802154_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
struct sockaddr_ieee802154_s to;
|
||||
FAR struct ieee802154_conn_s *conn;
|
||||
ssize_t ret;
|
||||
|
||||
DEBUGASSERT(psock != NULL || buf != NULL);
|
||||
conn = (FAR struct ieee802154_conn_s *)psock->s_conn;
|
||||
DEBUGASSERT(conn != NULL);
|
||||
|
||||
/* Only SOCK_DGRAM is supported (because the MAC header is stripped) */
|
||||
|
||||
if (psock->s_type == SOCK_DGRAM)
|
||||
{
|
||||
/* send() may be used only if the socket has been connected. */
|
||||
|
||||
if (!_SS_ISCONNECTED(psock->s_flags) ||
|
||||
conn->raddr.s_mode == IEEE802154_ADDRMODE_NONE)
|
||||
{
|
||||
ret = -ENOTCONN;
|
||||
}
|
||||
else
|
||||
{
|
||||
to.sa_family = AF_IEEE802154;
|
||||
memcpy(&to.sa_addr, &conn->raddr,
|
||||
sizeof(struct ieee802154_saddr_s));
|
||||
|
||||
/* Then perform the send() as sendto() */
|
||||
|
||||
ret = ieee802154_sendto(psock, buf, len, flags,
|
||||
(FAR const struct sockaddr *)&to,
|
||||
sizeof(struct sockaddr_ieee802154_s));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* EDESTADDRREQ. Signifies that the socket is not connection-mode and
|
||||
* no peer address is set.
|
||||
*/
|
||||
|
||||
ret = -EDESTADDRREQ;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ieee802154_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* Socket sendmsg() method for the PF_IEEE802154 socket.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* msg Message to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see sendmsg() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t ieee802154_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
FAR const void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR const struct sockaddr *to = msg->msg_name;
|
||||
socklen_t tolen = msg->msg_namelen;
|
||||
|
||||
/* Validity check, only single iov supported */
|
||||
|
||||
if (msg->msg_iovlen != 1)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return to ? ieee802154_sendto(psock, buf, len, flags, to, tolen) :
|
||||
ieee802154_send(psock, buf, len, flags);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_IEEE802154 */
|
||||
|
|
@ -63,11 +63,6 @@ static int ieee802154_accept(FAR struct socket *psock,
|
|||
FAR struct socket *newsock);
|
||||
static int ieee802154_poll_local(FAR struct socket *psock,
|
||||
FAR struct pollfd *fds, bool setup);
|
||||
static ssize_t ieee802154_send(FAR struct socket *psock,
|
||||
FAR const void *buf, size_t len, int flags);
|
||||
static ssize_t ieee802154_sendto(FAR struct socket *psock,
|
||||
FAR const void *buf, size_t len, int flags,
|
||||
FAR const struct sockaddr *to, socklen_t tolen);
|
||||
static int ieee802154_close(FAR struct socket *psock);
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -86,16 +81,8 @@ const struct sock_intf_s g_ieee802154_sockif =
|
|||
ieee802154_connect, /* si_connect */
|
||||
ieee802154_accept, /* si_accept */
|
||||
ieee802154_poll_local, /* si_poll */
|
||||
ieee802154_send, /* si_send */
|
||||
ieee802154_sendto, /* si_sendto */
|
||||
#ifdef CONFIG_NET_SENDFILE
|
||||
NULL, /* si_sendfile */
|
||||
#endif
|
||||
ieee802154_recvfrom, /* si_recvfrom */
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
NULL, /* si_recvmsg */
|
||||
NULL, /* si_sendmsg */
|
||||
#endif
|
||||
ieee802154_sendmsg, /* si_sendmsg */
|
||||
ieee802154_recvmsg, /* si_recvmsg */
|
||||
ieee802154_close /* si_close */
|
||||
};
|
||||
|
||||
|
|
@ -617,123 +604,6 @@ static int ieee802154_poll_local(FAR struct socket *psock,
|
|||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ieee802154_send
|
||||
*
|
||||
* Description:
|
||||
* Socket send() method for the PF_IEEE802154 socket.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t ieee802154_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
struct sockaddr_ieee802154_s to;
|
||||
FAR struct ieee802154_conn_s *conn;
|
||||
ssize_t ret;
|
||||
|
||||
DEBUGASSERT(psock != NULL || buf != NULL);
|
||||
conn = (FAR struct ieee802154_conn_s *)psock->s_conn;
|
||||
DEBUGASSERT(conn != NULL);
|
||||
|
||||
/* Only SOCK_DGRAM is supported (because the MAC header is stripped) */
|
||||
|
||||
if (psock->s_type == SOCK_DGRAM)
|
||||
{
|
||||
/* send() may be used only if the socket has been connected. */
|
||||
|
||||
if (!_SS_ISCONNECTED(psock->s_flags) ||
|
||||
conn->raddr.s_mode == IEEE802154_ADDRMODE_NONE)
|
||||
{
|
||||
ret = -ENOTCONN;
|
||||
}
|
||||
else
|
||||
{
|
||||
to.sa_family = AF_IEEE802154;
|
||||
memcpy(&to.sa_addr, &conn->raddr,
|
||||
sizeof(struct ieee802154_saddr_s));
|
||||
|
||||
/* Then perform the send() as sendto() */
|
||||
|
||||
ret = psock_ieee802154_sendto(psock, buf, len, flags,
|
||||
(FAR const struct sockaddr *)&to,
|
||||
sizeof(
|
||||
struct sockaddr_ieee802154_s));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* EDESTADDRREQ. Signifies that the socket is not connection-mode and
|
||||
* no peer address is set.
|
||||
*/
|
||||
|
||||
ret = -EDESTADDRREQ;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ieee802154_sendto
|
||||
*
|
||||
* Description:
|
||||
* Implements the sendto() operation for the case of the PF_IEEE802154
|
||||
* socket.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
* to Address of recipient
|
||||
* tolen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send_to() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t ieee802154_sendto(FAR struct socket *psock,
|
||||
FAR const void *buf,
|
||||
size_t len, int flags,
|
||||
FAR const struct sockaddr *to,
|
||||
socklen_t tolen)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
/* Only SOCK_DGRAM is supported (because the MAC header is stripped) */
|
||||
|
||||
if (psock->s_type == SOCK_DGRAM)
|
||||
{
|
||||
/* Raw packet send */
|
||||
|
||||
ret = psock_ieee802154_sendto(psock, buf, len, flags, to, tolen);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* EDESTADDRREQ. Signifies that the socket is not connection-mode and
|
||||
* no peer address is set.
|
||||
*/
|
||||
|
||||
ret = -EDESTADDRREQ;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ieee802154_close
|
||||
*
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
#include <debug.h>
|
||||
|
||||
#include <nuttx/net/net.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
|
||||
#include "tcp/tcp.h"
|
||||
#include "udp/udp.h"
|
||||
|
|
@ -71,14 +72,15 @@ static ssize_t inet_send(FAR struct socket *psock, FAR const void *buf,
|
|||
static ssize_t inet_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags, FAR const struct sockaddr *to,
|
||||
socklen_t tolen);
|
||||
static ssize_t inet_sendmsg(FAR struct socket *psock,
|
||||
FAR struct msghdr *msg, int flags);
|
||||
static ssize_t inet_recvmsg(FAR struct socket *psock,
|
||||
FAR struct msghdr *msg, int flags);
|
||||
#ifdef CONFIG_NET_SENDFILE
|
||||
static ssize_t inet_sendfile(FAR struct socket *psock,
|
||||
FAR struct file *infile, FAR off_t *offset,
|
||||
size_t count);
|
||||
#endif
|
||||
static ssize_t inet_recvfrom(FAR struct socket *psock, FAR void *buf,
|
||||
size_t len, int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
|
|
@ -96,17 +98,13 @@ static const struct sock_intf_s g_inet_sockif =
|
|||
inet_connect, /* si_connect */
|
||||
inet_accept, /* si_accept */
|
||||
inet_poll, /* si_poll */
|
||||
inet_send, /* si_send */
|
||||
inet_sendto, /* si_sendto */
|
||||
#ifdef CONFIG_NET_SENDFILE
|
||||
inet_sendfile, /* si_sendfile */
|
||||
#endif
|
||||
inet_recvfrom, /* si_recvfrom */
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
NULL, /* si_recvmsg */
|
||||
NULL, /* si_sendmsg */
|
||||
#endif
|
||||
inet_sendmsg, /* si_sendmsg */
|
||||
inet_recvmsg, /* si_recvmsg */
|
||||
inet_close /* si_close */
|
||||
#ifdef CONFIG_NET_SENDFILE
|
||||
,
|
||||
inet_sendfile /* si_sendfile */
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -1224,6 +1222,68 @@ static ssize_t inet_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
return nsent;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: inet_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* The inet_send() call may be used only when the socket is in a connected
|
||||
* state (so that the intended recipient is known).
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* msg Message to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see sendmsg() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t inet_sendmsg(FAR struct socket *psock,
|
||||
FAR struct msghdr *msg, int flags)
|
||||
{
|
||||
FAR void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR const struct sockaddr *to = msg->msg_name;
|
||||
socklen_t tolen = msg->msg_namelen;
|
||||
FAR const struct iovec *iov;
|
||||
FAR const struct iovec *end;
|
||||
int ret;
|
||||
|
||||
if (msg->msg_iovlen == 1)
|
||||
{
|
||||
return to ? inet_sendto(psock, buf, len, flags, to, tolen) :
|
||||
inet_send(psock, buf, len, flags);
|
||||
}
|
||||
|
||||
end = &msg->msg_iov[msg->msg_iovlen];
|
||||
for (len = 0, iov = msg->msg_iov; iov != end; iov++)
|
||||
{
|
||||
len += iov->iov_len;
|
||||
}
|
||||
|
||||
buf = kmm_malloc(len);
|
||||
if (buf == NULL)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
for (len = 0, iov = msg->msg_iov; iov != end; iov++)
|
||||
{
|
||||
memcpy(buf + len, iov->iov_base, iov->iov_len);
|
||||
len += iov->iov_len;
|
||||
}
|
||||
|
||||
ret = to ? inet_sendto(psock, buf, len, flags, to, tolen) :
|
||||
inet_send(psock, buf, len, flags);
|
||||
|
||||
kmm_free(buf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: inet_sendfile
|
||||
*
|
||||
|
|
@ -1261,41 +1321,40 @@ static ssize_t inet_sendfile(FAR struct socket *psock,
|
|||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: inet_recvfrom
|
||||
* Name: inet_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* Implements the socket recvfrom interface for the case of the AF_INET
|
||||
* and AF_INET6 address families. inet_recvfrom() receives messages from
|
||||
* and AF_INET6 address families. inet_recvmsg() receives messages from
|
||||
* a socket, and may be used to receive data on a socket whether or not it
|
||||
* is connection-oriented.
|
||||
*
|
||||
* If 'from' is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'fromlen' is
|
||||
* initialized to the size of the buffer associated with from, and
|
||||
* If msg_name is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'msg_namelen' is
|
||||
* initialized to the size of the buffer associated with msg_name, and
|
||||
* modified on return to indicate the actual size of the address stored
|
||||
* there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
* psock - A pointer to a NuttX-specific, internal socket structure
|
||||
* msg - Buffer to receive the message
|
||||
* flags - Receive flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* recv() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvfrom() for the list of appropriate error values).
|
||||
* recvmsg() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvmsg() for the list of appropriate error values).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t inet_recvfrom(FAR struct socket *psock, FAR void *buf,
|
||||
size_t len, int flags,
|
||||
FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen)
|
||||
static ssize_t inet_recvmsg(FAR struct socket *psock,
|
||||
FAR struct msghdr *msg, int flags)
|
||||
{
|
||||
FAR void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR struct sockaddr *from = msg->msg_name;
|
||||
FAR socklen_t *fromlen = &msg->msg_namelen;
|
||||
ssize_t ret;
|
||||
|
||||
/* If a 'from' address has been provided, verify that it is large
|
||||
|
|
|
|||
|
|
@ -23,15 +23,11 @@
|
|||
ifeq ($(CONFIG_NET_LOCAL),y)
|
||||
|
||||
NET_CSRCS += local_conn.c local_release.c local_bind.c local_fifo.c
|
||||
NET_CSRCS += local_recvfrom.c local_sendpacket.c local_recvutils.c
|
||||
NET_CSRCS += local_sockif.c local_netpoll.c
|
||||
NET_CSRCS += local_recvmsg.c local_sendpacket.c local_recvutils.c
|
||||
NET_CSRCS += local_sockif.c local_netpoll.c local_sendmsg.c
|
||||
|
||||
ifeq ($(CONFIG_NET_LOCAL_STREAM),y)
|
||||
NET_CSRCS += local_connect.c local_listen.c local_accept.c local_send.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NET_LOCAL_DGRAM),y)
|
||||
NET_CSRCS += local_sendto.c
|
||||
NET_CSRCS += local_connect.c local_listen.c local_accept.c
|
||||
endif
|
||||
|
||||
# Include Unix domain socket build support
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/local/loal.h
|
||||
* net/local/local.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -362,59 +362,25 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_local_send
|
||||
* Name: local_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* Send a local packet as a stream.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags (ignored for now)
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error,
|
||||
* -1 is returned, and errno is set appropriately (see send() for the
|
||||
* list of errno numbers).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_LOCAL_STREAM
|
||||
ssize_t psock_local_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_local_sendto
|
||||
*
|
||||
* Description:
|
||||
* This function implements the Unix domain-specific logic of the
|
||||
* standard sendto() socket operation.
|
||||
* Implements the sendmsg() operation for the case of the local Unix socket
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* msg msg to send
|
||||
* flags Send flags
|
||||
* to Address of recipient
|
||||
* tolen The length of the address structure
|
||||
*
|
||||
* NOTE: All input parameters were verified by sendto() before this
|
||||
* function was called.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error,
|
||||
* a negated errno value is returned. See the description in
|
||||
* net/socket/sendto.c for the list of appropriate return value.
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see sendmsg() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_LOCAL_DGRAM
|
||||
ssize_t psock_local_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags,
|
||||
FAR const struct sockaddr *to, socklen_t tolen);
|
||||
#endif
|
||||
ssize_t local_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: local_send_packet
|
||||
|
|
@ -433,14 +399,14 @@ ssize_t psock_local_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int local_send_packet(FAR struct file *filep, FAR const uint8_t *buf,
|
||||
int local_send_packet(FAR struct file *filep, FAR const struct iovec *buf,
|
||||
size_t len);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: local_recvfrom
|
||||
* Name: local_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* recvfrom() receives messages from a local socket, and may be used to
|
||||
* recvmsg() receives messages from a local socket and may be used to
|
||||
* receive data on a socket whether or not it is connection-oriented.
|
||||
*
|
||||
* If from is not NULL, and the underlying protocol provides the source
|
||||
|
|
@ -450,23 +416,19 @@ int local_send_packet(FAR struct file *filep, FAR const uint8_t *buf,
|
|||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags (ignored for now)
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. If no data is
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* recv() will return 0. Otherwise, on errors, -1 is returned, and errno
|
||||
* is set appropriately (see receivefrom for the complete list).
|
||||
* recvmsg() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvmsg() for the list of appropriate error values).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t local_recvfrom(FAR struct socket *psock, FAR void *buf,
|
||||
size_t len, int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen);
|
||||
ssize_t local_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: local_fifo_read
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/local/local_recvfrom.c
|
||||
* net/local/local_recvmsg.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -378,11 +378,11 @@ errout_with_halfduplex:
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: local_recvfrom
|
||||
* Name: local_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* local_recvfrom() receives messages from a local socket and may be used
|
||||
* to receive data on a socket whether or not it is connection-oriented.
|
||||
* recvmsg() receives messages from a local socket and may be used to
|
||||
* receive data on a socket whether or not it is connection-oriented.
|
||||
*
|
||||
* If from is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument fromlen
|
||||
|
|
@ -391,25 +391,25 @@ errout_with_halfduplex:
|
|||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags (ignored for now)
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* recv() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recv_from() for the complete list of appropriate error
|
||||
* values).
|
||||
* recvmsg() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvmsg() for the list of appropriate error values).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t local_recvfrom(FAR struct socket *psock, FAR void *buf,
|
||||
size_t len, int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen)
|
||||
ssize_t local_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
FAR void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR struct sockaddr *from = msg->msg_name;
|
||||
FAR socklen_t *fromlen = &msg->msg_namelen;
|
||||
|
||||
DEBUGASSERT(psock && psock->s_conn && buf);
|
||||
|
||||
/* Check for a stream socket */
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/local/local_sendto.c
|
||||
* net/local/local_sendmsg.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#if defined(CONFIG_NET) && defined(CONFIG_NET_LOCAL_DGRAM)
|
||||
#if defined(CONFIG_NET) && defined(CONFIG_NET_LOCAL)
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
|
@ -38,11 +38,101 @@
|
|||
#include "local/local.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_local_sendto
|
||||
* Name: local_send
|
||||
*
|
||||
* Description:
|
||||
* Send a local packet as a stream.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags (ignored for now)
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error,
|
||||
* -1 is returned, and errno is set appropriately (see send() for the
|
||||
* list of errno numbers).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t local_send(FAR struct socket *psock,
|
||||
FAR const struct iovec *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
switch (psock->s_type)
|
||||
{
|
||||
#ifdef CONFIG_NET_LOCAL_STREAM
|
||||
case SOCK_STREAM:
|
||||
{
|
||||
FAR struct local_conn_s *peer;
|
||||
|
||||
/* Local TCP packet send */
|
||||
|
||||
DEBUGASSERT(psock && psock->s_conn && buf);
|
||||
peer = (FAR struct local_conn_s *)psock->s_conn;
|
||||
|
||||
/* Verify that this is a connected peer socket and that it has
|
||||
* opened the outgoing FIFO for write-only access.
|
||||
*/
|
||||
|
||||
if (peer->lc_state != LOCAL_STATE_CONNECTED ||
|
||||
peer->lc_outfile.f_inode == NULL)
|
||||
{
|
||||
nerr("ERROR: not connected\n");
|
||||
return -ENOTCONN;
|
||||
}
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
ret = local_send_packet(&peer->lc_outfile, buf, len);
|
||||
|
||||
/* If the send was successful, then the full packet will have been
|
||||
* sent
|
||||
*/
|
||||
|
||||
if (ret >= 0)
|
||||
{
|
||||
ret = len;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif /* CONFIG_NET_LOCAL_STREAM */
|
||||
|
||||
#ifdef CONFIG_NET_LOCAL_DGRAM
|
||||
case SOCK_DGRAM:
|
||||
{
|
||||
/* Local UDP packet send */
|
||||
|
||||
#warning Missing logic
|
||||
|
||||
ret = -ENOSYS;
|
||||
}
|
||||
break;
|
||||
#endif /* CONFIG_NET_LOCAL_DGRAM */
|
||||
|
||||
default:
|
||||
{
|
||||
/* EDESTADDRREQ. Signifies that the socket is not connection-mode
|
||||
* and no peer address is set.
|
||||
*/
|
||||
|
||||
ret = -EDESTADDRREQ;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: local_sendto
|
||||
*
|
||||
* Description:
|
||||
* This function implements the Unix domain-specific logic of the
|
||||
|
|
@ -66,22 +156,34 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t psock_local_sendto(FAR struct socket *psock,
|
||||
FAR const void *buf,
|
||||
size_t len, int flags,
|
||||
FAR const struct sockaddr *to,
|
||||
socklen_t tolen)
|
||||
static ssize_t local_sendto(FAR struct socket *psock,
|
||||
FAR const struct iovec *buf,
|
||||
size_t len, int flags,
|
||||
FAR const struct sockaddr *to,
|
||||
socklen_t tolen)
|
||||
{
|
||||
#ifdef CONFIG_NET_LOCAL_DGRAM
|
||||
FAR struct local_conn_s *conn = (FAR struct local_conn_s *)psock->s_conn;
|
||||
FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)to;
|
||||
ssize_t nsent;
|
||||
int ret;
|
||||
|
||||
/* We keep packet sizes in a uint16_t, so there is a upper limit to the
|
||||
* 'len' that can be supported.
|
||||
*/
|
||||
/* Verify that a valid address has been provided */
|
||||
|
||||
DEBUGASSERT(buf && len <= UINT16_MAX);
|
||||
if (to->sa_family != AF_LOCAL || tolen < sizeof(sa_family_t))
|
||||
{
|
||||
nerr("ERROR: Unrecognized address family: %d\n",
|
||||
to->sa_family);
|
||||
return -EAFNOSUPPORT;
|
||||
}
|
||||
|
||||
/* If this is a connected socket, then return EISCONN */
|
||||
|
||||
if (psock->s_type != SOCK_DGRAM)
|
||||
{
|
||||
nerr("ERROR: Connected socket\n");
|
||||
return -EISCONN;
|
||||
}
|
||||
|
||||
/* Verify that this is not a connected peer socket. It need not be
|
||||
* bound, however. If unbound, recvfrom will see this as a nameless
|
||||
|
|
@ -163,6 +265,43 @@ errout_with_halfduplex:
|
|||
|
||||
local_release_halfduplex(conn);
|
||||
return nsent;
|
||||
#else
|
||||
return -EISCONN;
|
||||
#endif /* CONFIG_NET_LOCAL_DGRAM */
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET && CONFIG_NET_LOCAL_DGRAM */
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: local_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* Implements the sendmsg() operation for the case of the local Unix socket
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* msg msg to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see sendmsg() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t local_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
FAR const struct iovec *buf = msg->msg_iov;
|
||||
size_t len = msg->msg_iovlen;
|
||||
FAR const struct sockaddr *to = msg->msg_name;
|
||||
socklen_t tolen = msg->msg_namelen;
|
||||
|
||||
return to ? local_sendto(psock, buf, len, flags, to, tolen) :
|
||||
local_send(psock, buf, len, flags);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET && CONFIG_NET_LOCAL */
|
||||
|
|
@ -125,9 +125,11 @@ static int local_fifo_write(FAR struct file *filep, FAR const uint8_t *buf,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int local_send_packet(FAR struct file *filep, FAR const uint8_t *buf,
|
||||
int local_send_packet(FAR struct file *filep, FAR const struct iovec *buf,
|
||||
size_t len)
|
||||
{
|
||||
FAR const struct iovec *iov;
|
||||
FAR const struct iovec *end;
|
||||
uint16_t len16;
|
||||
int ret;
|
||||
|
||||
|
|
@ -138,14 +140,29 @@ int local_send_packet(FAR struct file *filep, FAR const uint8_t *buf,
|
|||
{
|
||||
/* Send the packet length */
|
||||
|
||||
len16 = len;
|
||||
end = buf + len;
|
||||
for (len16 = 0, iov = buf; iov != end; iov++)
|
||||
{
|
||||
len16 += iov->iov_len;
|
||||
}
|
||||
|
||||
ret = local_fifo_write(filep, (FAR const uint8_t *)&len16,
|
||||
sizeof(uint16_t));
|
||||
if (ret == OK)
|
||||
{
|
||||
/* Send the packet data */
|
||||
|
||||
ret = local_fifo_write(filep, buf, len);
|
||||
for (len16 = 0, iov = buf; iov != end; iov++)
|
||||
{
|
||||
ret = local_fifo_write(filep, iov->iov_base, iov->iov_len);
|
||||
if (ret < 0)
|
||||
break;
|
||||
else
|
||||
len16 += ret;
|
||||
}
|
||||
|
||||
if (ret > 0)
|
||||
ret = len16;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,11 +66,6 @@ static int local_accept(FAR struct socket *psock,
|
|||
#endif
|
||||
static int local_poll(FAR struct socket *psock,
|
||||
FAR struct pollfd *fds, bool setup);
|
||||
static ssize_t local_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags);
|
||||
static ssize_t local_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags, FAR const struct sockaddr *to,
|
||||
socklen_t tolen);
|
||||
static int local_close(FAR struct socket *psock);
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -89,16 +84,8 @@ const struct sock_intf_s g_local_sockif =
|
|||
local_connect, /* si_connect */
|
||||
local_accept, /* si_accept */
|
||||
local_poll, /* si_poll */
|
||||
local_send, /* si_send */
|
||||
local_sendto, /* si_sendto */
|
||||
#ifdef CONFIG_NET_SENDFILE
|
||||
NULL, /* si_sendfile */
|
||||
#endif
|
||||
local_recvfrom, /* si_recvfrom */
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
NULL, /* si_recvmsg */
|
||||
NULL, /* si_sendmsg */
|
||||
#endif
|
||||
local_sendmsg, /* si_sendmsg */
|
||||
local_recvmsg, /* si_recvmsg */
|
||||
local_close /* si_close */
|
||||
};
|
||||
|
||||
|
|
@ -642,123 +629,6 @@ static int local_poll(FAR struct socket *psock, FAR struct pollfd *fds,
|
|||
#endif /* HAVE_LOCAL_POLL */
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: local_send
|
||||
*
|
||||
* Description:
|
||||
* Implements the send() operation for the case of the local, Unix socket.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t local_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
switch (psock->s_type)
|
||||
{
|
||||
#ifdef CONFIG_NET_LOCAL_STREAM
|
||||
case SOCK_STREAM:
|
||||
{
|
||||
/* Local TCP packet send */
|
||||
|
||||
ret = psock_local_send(psock, buf, len, flags);
|
||||
}
|
||||
break;
|
||||
#endif /* CONFIG_NET_LOCAL_STREAM */
|
||||
|
||||
#ifdef CONFIG_NET_LOCAL_DGRAM
|
||||
case SOCK_DGRAM:
|
||||
{
|
||||
/* Local UDP packet send */
|
||||
|
||||
#warning Missing logic
|
||||
|
||||
ret = -ENOSYS;
|
||||
}
|
||||
break;
|
||||
#endif /* CONFIG_NET_LOCAL_DGRAM */
|
||||
|
||||
default:
|
||||
{
|
||||
/* EDESTADDRREQ. Signifies that the socket is not connection-mode
|
||||
* and no peer address is set.
|
||||
*/
|
||||
|
||||
ret = -EDESTADDRREQ;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: local_sendto
|
||||
*
|
||||
* Description:
|
||||
* Implements the sendto() operation for the case of the local Unix socket.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
* to Address of recipient
|
||||
* tolen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send_to() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t local_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags, FAR const struct sockaddr *to,
|
||||
socklen_t tolen)
|
||||
{
|
||||
ssize_t nsent;
|
||||
|
||||
/* Verify that a valid address has been provided */
|
||||
|
||||
if (to->sa_family != AF_LOCAL || tolen < sizeof(sa_family_t))
|
||||
{
|
||||
nerr("ERROR: Unrecognized address family: %d\n",
|
||||
to->sa_family);
|
||||
return -EAFNOSUPPORT;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NET_LOCAL_DGRAM
|
||||
/* If this is a connected socket, then return EISCONN */
|
||||
|
||||
if (psock->s_type != SOCK_DGRAM)
|
||||
{
|
||||
nerr("ERROR: Connected socket\n");
|
||||
return -EISCONN;
|
||||
}
|
||||
|
||||
/* Now handle the local UDP sendto() operation */
|
||||
|
||||
nsent = psock_local_sendto(psock, buf, len, flags, to, tolen);
|
||||
#else
|
||||
nsent = -EISCONN;
|
||||
#endif /* CONFIG_NET_LOCAL_DGRAM */
|
||||
|
||||
return nsent;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: local_close
|
||||
*
|
||||
|
|
|
|||
|
|
@ -64,14 +64,10 @@ static int netlink_accept(FAR struct socket *psock,
|
|||
FAR struct socket *newsock);
|
||||
static int netlink_poll(FAR struct socket *psock, FAR struct pollfd *fds,
|
||||
bool setup);
|
||||
static ssize_t netlink_send(FAR struct socket *psock,
|
||||
FAR const void *buf, size_t len, int flags);
|
||||
static ssize_t netlink_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags, FAR const struct sockaddr *to,
|
||||
socklen_t tolen);
|
||||
static ssize_t netlink_recvfrom(FAR struct socket *psock, FAR void *buf,
|
||||
size_t len, int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen);
|
||||
static ssize_t netlink_sendmsg(FAR struct socket *psock,
|
||||
FAR struct msghdr *msg, int flags);
|
||||
static ssize_t netlink_recvmsg(FAR struct socket *psock,
|
||||
FAR struct msghdr *msg, int flags);
|
||||
static int netlink_close(FAR struct socket *psock);
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -90,16 +86,8 @@ const struct sock_intf_s g_netlink_sockif =
|
|||
netlink_connect, /* si_connect */
|
||||
netlink_accept, /* si_accept */
|
||||
netlink_poll, /* si_poll */
|
||||
netlink_send, /* si_send */
|
||||
netlink_sendto, /* si_sendto */
|
||||
#ifdef CONFIG_NET_SENDFILE
|
||||
NULL, /* si_sendfile */
|
||||
#endif
|
||||
netlink_recvfrom, /* si_recvfrom */
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
NULL, /* si_recvmsg */
|
||||
NULL, /* si_sendmsg */
|
||||
#endif
|
||||
netlink_sendmsg, /* si_sendmsg */
|
||||
netlink_recvmsg, /* si_recvmsg */
|
||||
netlink_close /* si_close */
|
||||
};
|
||||
|
||||
|
|
@ -659,87 +647,68 @@ static int netlink_poll(FAR struct socket *psock, FAR struct pollfd *fds,
|
|||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netlink_send
|
||||
* Name: netlink_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* The netlink_send() call may be used only when the socket is in
|
||||
* a connected state (so that the intended recipient is known).
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock - An instance of the internal socket structure.
|
||||
* buf - Data to send
|
||||
* len - Length of data to send
|
||||
* flags - Send flags (ignored)
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t netlink_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
FAR struct netlink_conn_s *conn;
|
||||
struct sockaddr_nl nladdr;
|
||||
|
||||
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && buf != NULL);
|
||||
|
||||
/* Get the underlying connection structure */
|
||||
|
||||
conn = (FAR struct netlink_conn_s *)psock->s_conn;
|
||||
|
||||
/* Format the address */
|
||||
|
||||
nladdr.nl_family = AF_NETLINK;
|
||||
nladdr.nl_pad = 0;
|
||||
nladdr.nl_pid = conn->dst_pid;
|
||||
nladdr.nl_groups = conn->dst_groups;
|
||||
|
||||
/* Then let sendto() perform the actual send operation */
|
||||
|
||||
return netlink_sendto(psock, buf, len, flags,
|
||||
(FAR const struct sockaddr *)&nladdr,
|
||||
sizeof(struct sockaddr_nl));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netlink_sendto
|
||||
*
|
||||
* Description:
|
||||
* If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
|
||||
* socket, the parameters to and 'tolen' are ignored (and the error EISCONN
|
||||
* may be returned when they are not NULL and 0), and the error ENOTCONN is
|
||||
* returned when the socket was not actually connected.
|
||||
* If sendmsg() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
|
||||
* socket, the parameters 'msg_name' and 'msg_namelen' are ignored (and the
|
||||
* error EISCONN may be returned when they are not NULL and 0), and the
|
||||
* error ENOTCONN is returned when the socket was not actually connected.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A reference to the structure of the socket to be connected
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* msg msg to send
|
||||
* flags Send flags (ignored)
|
||||
* to Address of recipient
|
||||
* tolen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see sendmsg() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t netlink_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags,
|
||||
FAR const struct sockaddr *to, socklen_t tolen)
|
||||
static ssize_t netlink_sendmsg(FAR struct socket *psock,
|
||||
FAR struct msghdr *msg, int flags)
|
||||
{
|
||||
FAR const void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR const struct sockaddr *to = msg->msg_name;
|
||||
socklen_t tolen = msg->msg_namelen;
|
||||
FAR struct netlink_conn_s *conn;
|
||||
FAR struct nlmsghdr *nlmsg;
|
||||
struct sockaddr_nl nladdr;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && buf != NULL &&
|
||||
to != NULL && tolen >= sizeof(struct sockaddr_nl));
|
||||
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && buf != NULL);
|
||||
|
||||
/* Validity check, only single iov supported */
|
||||
|
||||
if (msg->msg_iovlen != 1)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
/* Get the underlying connection structure */
|
||||
|
||||
conn = (FAR struct netlink_conn_s *)psock->s_conn;
|
||||
if (to == NULL)
|
||||
{
|
||||
/* netlink_send() */
|
||||
|
||||
/* Format the address */
|
||||
|
||||
nladdr.nl_family = AF_NETLINK;
|
||||
nladdr.nl_pad = 0;
|
||||
nladdr.nl_pid = conn->dst_pid;
|
||||
nladdr.nl_groups = conn->dst_groups;
|
||||
|
||||
to = (FAR const struct sockaddr *)&nladdr;
|
||||
tolen = sizeof(struct sockaddr_nl);
|
||||
}
|
||||
|
||||
DEBUGASSERT(tolen >= sizeof(struct sockaddr_nl));
|
||||
|
||||
/* Get a reference to the netlink message */
|
||||
|
||||
|
|
@ -751,7 +720,7 @@ static ssize_t netlink_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
#ifdef CONFIG_NETLINK_ROUTE
|
||||
case NETLINK_ROUTE:
|
||||
ret = netlink_route_sendto(conn, nlmsg, len, flags,
|
||||
(FAR struct sockaddr_nl *)to,
|
||||
(FAR const struct sockaddr_nl *)to,
|
||||
tolen);
|
||||
break;
|
||||
#endif
|
||||
|
|
@ -765,32 +734,32 @@ static ssize_t netlink_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netlink_recvfrom
|
||||
* Name: netlink_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* recvfrom() receives messages from a socket, and may be used to receive
|
||||
* recvmsg() receives messages from a socket, and may be used to receive
|
||||
* data on a socket whether or not it is connection-oriented.
|
||||
*
|
||||
* If from is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'fromlen'
|
||||
* initialized to the size of the buffer associated with from, and modified
|
||||
* on return to indicate the actual size of the address stored there.
|
||||
* If msg_name is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'msg_namelen' is
|
||||
* initialized to the size of the buffer associated with msg_name, and
|
||||
* modified on return to indicate the actual size of the address stored
|
||||
* there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags (ignored)
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t netlink_recvfrom(FAR struct socket *psock, FAR void *buf,
|
||||
size_t len, int flags,
|
||||
FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen)
|
||||
static ssize_t netlink_recvmsg(FAR struct socket *psock,
|
||||
FAR struct msghdr *msg, int flags)
|
||||
{
|
||||
FAR void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR struct sockaddr *from = msg->msg_name;
|
||||
FAR socklen_t *fromlen = &msg->msg_namelen;
|
||||
FAR struct netlink_response_s *entry;
|
||||
|
||||
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && buf != NULL);
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ ifeq ($(CONFIG_NET_PKT),y)
|
|||
# Socket layer
|
||||
|
||||
SOCK_CSRCS += pkt_sockif.c
|
||||
SOCK_CSRCS += pkt_send.c
|
||||
SOCK_CSRCS += pkt_recvfrom.c
|
||||
SOCK_CSRCS += pkt_sendmsg.c
|
||||
SOCK_CSRCS += pkt_recvmsg.c
|
||||
|
||||
# Transport layer
|
||||
|
||||
|
|
|
|||
|
|
@ -199,39 +199,35 @@ uint16_t pkt_callback(FAR struct net_driver_s *dev,
|
|||
/* pkt_input() is prototyped in include/nuttx/net/pkt.h */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pkt_recvfrom
|
||||
* Name: pkt_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* Implements the socket recvfrom interface for the case of the AF_INET
|
||||
* and AF_INET6 address families. pkt_recvfrom() receives messages from
|
||||
* Implements the socket recvmsg interface for the case of the AF_INET
|
||||
* and AF_INET6 address families. pkt_recvmsg() receives messages from
|
||||
* a socket, and may be used to receive data on a socket whether or not it
|
||||
* is connection-oriented.
|
||||
*
|
||||
* If 'from' is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'fromlen' is
|
||||
* initialized to the size of the buffer associated with from, and
|
||||
* modified on return to indicate the actual size of the address stored
|
||||
* there.
|
||||
* If 'msg_name' is not NULL, and the underlying protocol provides the
|
||||
* source address, this source address is filled in. The argument
|
||||
* 'msg_namelen' is initialized to the size of the buffer associated with
|
||||
* msg_name, and modified on return to indicate the actual size of the
|
||||
* address stored there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* recv() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvfrom() for the list of appropriate error values).
|
||||
* recvmsg() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvmsg() for the list of appropriate error values).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t pkt_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
||||
int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen);
|
||||
ssize_t pkt_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pkt_find_device
|
||||
|
|
@ -271,26 +267,26 @@ FAR struct net_driver_s *pkt_find_device(FAR struct pkt_conn_s *conn);
|
|||
void pkt_poll(FAR struct net_driver_s *dev, FAR struct pkt_conn_s *conn);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_pkt_send
|
||||
* Name: pkt_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* The psock_pkt_send() call may be used only when the packet socket is in
|
||||
* The pkt_sendmsg() call may be used only when the packet socket is in
|
||||
* a connected state (so that the intended recipient is known).
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* msg Message to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error,
|
||||
* a negated errno value is retruend. See send() for the complete list
|
||||
* of return values.
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see sendmsg() for the complete list of return
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t psock_pkt_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len);
|
||||
ssize_t pkt_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/pkt/pkt_recvfrom.c
|
||||
* net/pkt/pkt_recvmsg.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -312,40 +312,40 @@ static ssize_t pkt_recvfrom_result(int result,
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pkt_recvfrom
|
||||
* Name: pkt_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* Implements the socket recvfrom interface for the case of the AF_INET
|
||||
* and AF_INET6 address families. pkt_recvfrom() receives messages from
|
||||
* Implements the socket recvmsg interface for the case of the AF_INET
|
||||
* and AF_INET6 address families. pkt_recvmsg() receives messages from
|
||||
* a socket, and may be used to receive data on a socket whether or not it
|
||||
* is connection-oriented.
|
||||
*
|
||||
* If 'from' is not NULL, and the underlying protocol provides the source
|
||||
* address, this source address is filled in. The argument 'fromlen' is
|
||||
* initialized to the size of the buffer associated with from, and
|
||||
* modified on return to indicate the actual size of the address stored
|
||||
* there.
|
||||
* If 'msg_name' is not NULL, and the underlying protocol provides the
|
||||
* source address, this source address is filled in. The argument
|
||||
* 'msg_namelen' is initialized to the size of the buffer associated with
|
||||
* msg_name, and modified on return to indicate the actual size of the
|
||||
* address stored there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* On success, returns the number of characters received. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* recv() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvfrom() for the list of appropriate error values).
|
||||
* recvmsg() will return 0. Otherwise, on errors, a negated errno value is
|
||||
* returned (see recvmsg() for the list of appropriate error values).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t pkt_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
||||
int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen)
|
||||
ssize_t pkt_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
FAR void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR struct sockaddr *from = msg->msg_name;
|
||||
FAR socklen_t *fromlen = &msg->msg_namelen;
|
||||
FAR struct pkt_conn_s *conn = (FAR struct pkt_conn_s *)psock->s_conn;
|
||||
FAR struct net_driver_s *dev;
|
||||
struct pkt_recvfrom_s state;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/pkt/pkt_send.c
|
||||
* net/pkt/pkt_sendmsg.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -78,7 +78,7 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
|
|||
{
|
||||
FAR struct send_s *pstate = (FAR struct send_s *)pvpriv;
|
||||
|
||||
ninfo("flags: %04x sent: %d\n", flags, pstate->snd_sent);
|
||||
ninfo("flags: %04x sent: %zd\n", flags, pstate->snd_sent);
|
||||
|
||||
if (pstate)
|
||||
{
|
||||
|
|
@ -135,31 +135,48 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_pkt_send
|
||||
* Name: pkt_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* The psock_pkt_send() call may be used only when the packet socket is in
|
||||
* The pkt_sendmsg() call may be used only when the packet socket is in
|
||||
* a connected state (so that the intended recipient is known).
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* msg Message to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error,
|
||||
* a negated errno value is returned. See send() for the complete list
|
||||
* of return values.
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see sendmsg() for the complete list of return
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t psock_pkt_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len)
|
||||
ssize_t pkt_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
FAR const void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR struct net_driver_s *dev;
|
||||
struct send_s state;
|
||||
int ret = OK;
|
||||
|
||||
/* Validity check, only single iov supported */
|
||||
|
||||
if (msg->msg_iovlen != 1)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (msg->msg_name != NULL)
|
||||
{
|
||||
/* pkt_sendto */
|
||||
|
||||
nerr("ERROR: sendto() not supported for raw packet sockets\n");
|
||||
return -EAFNOSUPPORT;
|
||||
}
|
||||
|
||||
/* Verify that the sockfd corresponds to valid, allocated socket */
|
||||
|
||||
if (psock == NULL || psock->s_conn == NULL)
|
||||
|
|
@ -167,6 +184,17 @@ ssize_t psock_pkt_send(FAR struct socket *psock, FAR const void *buf,
|
|||
return -EBADF;
|
||||
}
|
||||
|
||||
/* Only SOCK_RAW is supported */
|
||||
|
||||
if (psock->s_type == SOCK_RAW)
|
||||
{
|
||||
/* EDESTADDRREQ. Signifies that the socket is not connection-mode and
|
||||
* no peer address is set.
|
||||
*/
|
||||
|
||||
return -EDESTADDRREQ;
|
||||
}
|
||||
|
||||
/* Get the device driver that will service this transfer */
|
||||
|
||||
dev = pkt_find_device((FAR struct pkt_conn_s *)psock->s_conn);
|
||||
|
|
@ -60,15 +60,10 @@ static int pkt_listen(FAR struct socket *psock, int backlog);
|
|||
static int pkt_connect(FAR struct socket *psock,
|
||||
FAR const struct sockaddr *addr, socklen_t addrlen);
|
||||
static int pkt_accept(FAR struct socket *psock,
|
||||
FAR struct sockaddr *addr, FAR socklen_t *addrlen,
|
||||
FAR struct socket *newsock);
|
||||
FAR struct sockaddr *addr, FAR socklen_t *addrlen,
|
||||
FAR struct socket *newsock);
|
||||
static int pkt_poll_local(FAR struct socket *psock,
|
||||
FAR struct pollfd *fds, bool setup);
|
||||
static ssize_t pkt_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags);
|
||||
static ssize_t pkt_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags, FAR const struct sockaddr *to,
|
||||
socklen_t tolen);
|
||||
static int pkt_close(FAR struct socket *psock);
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -87,16 +82,8 @@ const struct sock_intf_s g_pkt_sockif =
|
|||
pkt_connect, /* si_connect */
|
||||
pkt_accept, /* si_accept */
|
||||
pkt_poll_local, /* si_poll */
|
||||
pkt_send, /* si_send */
|
||||
pkt_sendto, /* si_sendto */
|
||||
#ifdef CONFIG_NET_SENDFILE
|
||||
NULL, /* si_sendfile */
|
||||
#endif
|
||||
pkt_recvfrom, /* si_recvfrom */
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
NULL, /* si_recvmsg */
|
||||
NULL, /* si_sendmsg */
|
||||
#endif
|
||||
pkt_sendmsg, /* si_sendmsg */
|
||||
pkt_recvmsg, /* si_recvmsg */
|
||||
pkt_close /* si_close */
|
||||
};
|
||||
|
||||
|
|
@ -341,7 +328,7 @@ static int pkt_bind(FAR struct socket *psock,
|
|||
|
||||
if (addr->sa_family != AF_PACKET || addrlen < sizeof(struct sockaddr_ll))
|
||||
{
|
||||
nerr("ERROR: Invalid address length: %d < %d\n",
|
||||
nerr("ERROR: Invalid address length: %d < %zu\n",
|
||||
addrlen, sizeof(struct sockaddr_ll));
|
||||
return -EBADF;
|
||||
}
|
||||
|
|
@ -508,79 +495,6 @@ static int pkt_poll_local(FAR struct socket *psock, FAR struct pollfd *fds,
|
|||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pkt_send
|
||||
*
|
||||
* Description:
|
||||
* Socket send() method for the raw packet socket.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t pkt_send(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
/* Only SOCK_RAW is supported */
|
||||
|
||||
if (psock->s_type == SOCK_RAW)
|
||||
{
|
||||
/* Raw packet send */
|
||||
|
||||
ret = psock_pkt_send(psock, buf, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* EDESTADDRREQ. Signifies that the socket is not connection-mode and
|
||||
* no peer address is set.
|
||||
*/
|
||||
|
||||
ret = -EDESTADDRREQ;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pkt_sendto
|
||||
*
|
||||
* Description:
|
||||
* Implements the sendto() operation for the case of the raw packet socket.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
* to Address of recipient
|
||||
* tolen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send_to() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t pkt_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags,
|
||||
FAR const struct sockaddr *to, socklen_t tolen)
|
||||
{
|
||||
nerr("ERROR: sendto() not supported for raw packet sockets\n");
|
||||
return -EAFNOSUPPORT;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pkt_close
|
||||
*
|
||||
|
|
|
|||
|
|
@ -52,19 +52,9 @@ config NET_TIMESTAMP
|
|||
bool "SO_TIMESTAMP socket option"
|
||||
default n
|
||||
depends on NET_CAN
|
||||
select NET_CMSG
|
||||
---help---
|
||||
Enable or disable support for the SO_TIMESTAMP socket option. Currently only tested & implemented in SocketCAN but should work on all sockets
|
||||
|
||||
endif # NET_SOCKOPTS
|
||||
|
||||
config NET_CMSG
|
||||
bool "Control messages (CMSG) support"
|
||||
default n
|
||||
---help---
|
||||
Enable or disable support for control messages in the recvmsg() and
|
||||
sendmsg() function. Control messages (also defined in POSIX 1003.1g
|
||||
as ancillary data object information). Includes additional
|
||||
information on the packet received or to be transmitted.
|
||||
|
||||
endmenu # Socket Support
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
SOCK_CSRCS += bind.c connect.c getsockname.c getpeername.c
|
||||
SOCK_CSRCS += recv.c recvfrom.c send.c sendto.c
|
||||
SOCK_CSRCS += socket.c net_close.c
|
||||
SOCK_CSRCS += recvmsg.c sendmsg.c
|
||||
SOCK_CSRCS += net_dup2.c net_sockif.c net_poll.c net_vfcntl.c
|
||||
SOCK_CSRCS += net_fstat.c
|
||||
|
||||
|
|
@ -54,8 +55,3 @@ endif
|
|||
DEPPATH += --dep-path socket
|
||||
VPATH += :socket
|
||||
|
||||
# Support for control messages (CMSG)
|
||||
ifeq ($(CONFIG_NET_CMSG),y)
|
||||
SOCK_CSRCS += recvmsg.c
|
||||
SOCK_CSRCS += sendmsg.c
|
||||
endif
|
||||
|
|
|
|||
|
|
@ -49,16 +49,16 @@
|
|||
*
|
||||
* - It is not a cancellation point,
|
||||
* - It does not modify the errno variable, and
|
||||
* - I accepts the internal socket structure as an input rather than an
|
||||
* - It accepts the internal socket structure as an input rather than an
|
||||
* task-specific socket descriptor.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock - A pointer to a NuttX-specific, internal socket structure
|
||||
* buf - Buffer to receive data
|
||||
* len - Length of buffer
|
||||
* flags - Receive flags
|
||||
* from - Address of source (may be NULL)
|
||||
* fromlen - The length of the address structure
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
|
|
@ -73,33 +73,27 @@ ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||
int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen)
|
||||
{
|
||||
/* Verify that non-NULL pointers were passed */
|
||||
struct msghdr msg;
|
||||
struct iovec iov;
|
||||
ssize_t ret;
|
||||
|
||||
if (buf == NULL)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
iov.iov_base = buf;
|
||||
iov.iov_len = len;
|
||||
msg.msg_name = from;
|
||||
msg.msg_namelen = fromlen ? *fromlen : 0;
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_control = NULL;
|
||||
msg.msg_controllen = 0;
|
||||
msg.msg_flags = 0;
|
||||
|
||||
if (from != NULL && fromlen != NULL && *fromlen <= 0)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
/* And let psock_recvmsg do all of the work */
|
||||
|
||||
/* Verify that the sockfd corresponds to valid, allocated socket */
|
||||
ret = psock_recvmsg(psock, &msg, flags);
|
||||
if (ret >= 0 && fromlen != NULL)
|
||||
*fromlen = msg.msg_namelen;
|
||||
|
||||
if (psock == NULL || psock->s_conn == NULL)
|
||||
{
|
||||
return -EBADF;
|
||||
}
|
||||
|
||||
/* Let logic specific to this address family handle the recvfrom()
|
||||
* operation.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(psock->s_sockif != NULL &&
|
||||
psock->s_sockif->si_recvfrom != NULL);
|
||||
|
||||
return psock->s_sockif->si_recvfrom(psock, buf, len, flags, from, fromlen);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -115,12 +109,12 @@ ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||
* - It does not modify the errno variable.
|
||||
*
|
||||
* Input Parameters:
|
||||
* sockfd - Socket descriptor of socket
|
||||
* buf - Buffer to receive data
|
||||
* len - Length of buffer
|
||||
* flags - Receive flags
|
||||
* from - Address of source (may be NULL)
|
||||
* fromlen - The length of the address structure
|
||||
* sockfd Socket descriptor of socket
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
|
|
@ -158,12 +152,12 @@ ssize_t nx_recvfrom(int sockfd, FAR void *buf, size_t len, int flags,
|
|||
* on return to indicate the actual size of the address stored there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* sockfd - Socket descriptor of socket
|
||||
* buf - Buffer to receive data
|
||||
* len - Length of buffer
|
||||
* flags - Receive flags
|
||||
* from - Address of source (may be NULL)
|
||||
* fromlen - The length of the address structure
|
||||
* sockfd Socket descriptor of socket
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* flags Receive flags
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. On error,
|
||||
|
|
@ -199,23 +193,18 @@ ssize_t nx_recvfrom(int sockfd, FAR void *buf, size_t len, int flags,
|
|||
ssize_t recvfrom(int sockfd, FAR void *buf, size_t len, int flags,
|
||||
FAR struct sockaddr *from, FAR socklen_t *fromlen)
|
||||
{
|
||||
FAR struct socket *psock;
|
||||
ssize_t ret;
|
||||
|
||||
/* recvfrom() is a cancellation point */
|
||||
|
||||
enter_cancellation_point();
|
||||
|
||||
/* Get the underlying socket structure */
|
||||
|
||||
psock = sockfd_socket(sockfd);
|
||||
|
||||
/* Let psock_recvfrom() do all of the work */
|
||||
|
||||
ret = psock_recvfrom(psock, buf, len, flags, from, fromlen);
|
||||
ret = nx_recvfrom(sockfd, buf, len, flags, from, fromlen);
|
||||
if (ret < 0)
|
||||
{
|
||||
_SO_SETERRNO(psock, -ret);
|
||||
_SO_SETERRNO(sockfd_socket(sockfd), -ret);
|
||||
ret = ERROR;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
#include "socket/socket.h"
|
||||
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
#ifdef CONFIG_NET
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
|
|
@ -42,21 +42,20 @@
|
|||
* Name: psock_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* psock_recvfrom() receives messages from a socket, and may be used to
|
||||
* psock_recvmsg() receives messages from a socket, and may be used to
|
||||
* receive data on a socket whether or not it is connection-oriented.
|
||||
* This is an internal OS interface. It is functionally equivalent to
|
||||
* recvfrom() except that:
|
||||
* recvmsg() except that:
|
||||
*
|
||||
* - It is not a cancellation point,
|
||||
* - It does not modify the errno variable, and
|
||||
* - I accepts the internal socket structure as an input rather than an
|
||||
* - It accepts the internal socket structure as an input rather than an
|
||||
* task-specific socket descriptor.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock - A pointer to a NuttX-specific, internal socket structure
|
||||
* msg Buffer to receive msg
|
||||
* len - Length of buffer
|
||||
* flags - Receive flags
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* msg Buffer to receive data
|
||||
* flags Receive flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
|
|
@ -72,7 +71,12 @@ ssize_t psock_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
|||
{
|
||||
/* Verify that non-NULL pointers were passed */
|
||||
|
||||
if (msg == NULL)
|
||||
if (msg == NULL || msg->msg_iov == NULL || msg->msg_iov->iov_base == NULL)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (msg->msg_name != NULL && msg->msg_namelen <= 0)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
@ -89,48 +93,31 @@ ssize_t psock_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
|||
return -EBADF;
|
||||
}
|
||||
|
||||
/* Let logic specific to this address family handle the recvfrom()
|
||||
/* Let logic specific to this address family handle the recvmsg()
|
||||
* operation.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(psock->s_sockif != NULL &&
|
||||
(psock->s_sockif->si_recvmsg != NULL ||
|
||||
psock->s_sockif->si_recvfrom != NULL));
|
||||
psock->s_sockif->si_recvmsg != NULL);
|
||||
|
||||
if (psock->s_sockif->si_recvmsg != NULL)
|
||||
{
|
||||
return psock->s_sockif->si_recvmsg(psock, msg, flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Socket doesn't implement si_recvmsg fallback to si_recvfrom */
|
||||
|
||||
FAR void *buf = msg->msg_iov->iov_base;
|
||||
FAR struct sockaddr *from = msg->msg_name;
|
||||
FAR socklen_t *fromlen = (FAR socklen_t *)&msg->msg_namelen;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
|
||||
return psock->s_sockif->si_recvfrom(psock, buf, len, flags, from,
|
||||
fromlen);
|
||||
}
|
||||
return psock->s_sockif->si_recvmsg(psock, msg, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nx_recvfrom
|
||||
* Name: nx_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* nx_recvfrom() receives messages from a socket, and may be used to
|
||||
* nx_recvmsg() receives messages from a socket, and may be used to
|
||||
* receive data on a socket whether or not it is connection-oriented.
|
||||
* This is an internal OS interface. It is functionally equivalent to
|
||||
* recvfrom() except that:
|
||||
* recvmsg() except that:
|
||||
*
|
||||
* - It is not a cancellation point, and
|
||||
* - It does not modify the errno variable.
|
||||
*
|
||||
* Input Parameters:
|
||||
* sockfd - Socket descriptor of socket
|
||||
* msg Buffer to receive msg
|
||||
* len - Length of buffer
|
||||
* msg Buffer to receive the message
|
||||
* flags - Receive flags
|
||||
*
|
||||
* Returned Value:
|
||||
|
|
@ -159,13 +146,12 @@ ssize_t nx_recvmsg(int sockfd, FAR struct msghdr *msg, int flags)
|
|||
* Function: recvmsg
|
||||
*
|
||||
* Description:
|
||||
* The recvmsg() call is identical to recvfrom() with a NULL from
|
||||
* parameter.
|
||||
* recvmsg() receives messages from a socket, and may be used to
|
||||
* receive data on a socket whether or not it is connection-oriented.
|
||||
*
|
||||
* Parameters:
|
||||
* sockfd Socket descriptor of socket
|
||||
* msg Buffer to receive msg
|
||||
* len Length of buffer
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags
|
||||
*
|
||||
* Returned Value:
|
||||
|
|
@ -201,23 +187,18 @@ ssize_t nx_recvmsg(int sockfd, FAR struct msghdr *msg, int flags)
|
|||
|
||||
ssize_t recvmsg(int sockfd, FAR struct msghdr *msg, int flags)
|
||||
{
|
||||
FAR struct socket *psock;
|
||||
ssize_t ret;
|
||||
|
||||
/* recvfrom() is a cancellation point */
|
||||
/* recvmsg() is a cancellation point */
|
||||
|
||||
enter_cancellation_point();
|
||||
|
||||
/* Get the underlying socket structure */
|
||||
/* Let nx_recvmsg() do all of the work */
|
||||
|
||||
psock = sockfd_socket(sockfd);
|
||||
|
||||
/* Let psock_recvfrom() do all of the work */
|
||||
|
||||
ret = psock_recvmsg(psock, msg, flags);
|
||||
ret = nx_recvmsg(sockfd, msg, flags);
|
||||
if (ret < 0)
|
||||
{
|
||||
_SO_SETERRNO(psock, -ret);
|
||||
_SO_SETERRNO(sockfd_socket(sockfd), -ret);
|
||||
ret = ERROR;
|
||||
}
|
||||
|
||||
|
|
@ -225,4 +206,4 @@ ssize_t recvmsg(int sockfd, FAR struct msghdr *msg, int flags)
|
|||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_CMSG */
|
||||
#endif /* CONFIG_NET */
|
||||
|
|
|
|||
|
|
@ -57,10 +57,10 @@
|
|||
* functionality.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock - An instance of the internal socket structure.
|
||||
* buf - Data to send
|
||||
* len - Length of data to send
|
||||
* flags - Send flags
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On any failure, a
|
||||
|
|
@ -72,34 +72,22 @@
|
|||
ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len,
|
||||
int flags)
|
||||
{
|
||||
ssize_t ret;
|
||||
struct msghdr msg;
|
||||
struct iovec iov;
|
||||
|
||||
/* Verify that non-NULL pointers were passed */
|
||||
iov.iov_base = (FAR void *)buf;
|
||||
iov.iov_len = len;
|
||||
msg.msg_name = NULL;
|
||||
msg.msg_namelen = 0;
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_control = NULL;
|
||||
msg.msg_controllen = 0;
|
||||
msg.msg_flags = 0;
|
||||
|
||||
if (buf == NULL)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
/* And let psock_sendmsg do all of the work */
|
||||
|
||||
/* Verify that the sockfd corresponds to valid, allocated socket */
|
||||
|
||||
if (psock == NULL || psock->s_conn == NULL)
|
||||
{
|
||||
return -EBADF;
|
||||
}
|
||||
|
||||
/* Let the address family's send() method handle the operation */
|
||||
|
||||
DEBUGASSERT(psock->s_sockif != NULL && psock->s_sockif->si_send != NULL);
|
||||
|
||||
ret = psock->s_sockif->si_send(psock, buf, len, flags);
|
||||
if (ret < 0)
|
||||
{
|
||||
nerr("ERROR: socket si_send() (or usrsock_sendto()) failed: %zd\n",
|
||||
ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return psock_sendmsg(psock, &msg, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -118,10 +106,10 @@ ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len,
|
|||
* functionality.
|
||||
*
|
||||
* Input Parameters:
|
||||
* sockfd - Socket descriptor of the socket
|
||||
* buf - Data to send
|
||||
* len - Length of data to send
|
||||
* flags - Send flags
|
||||
* sockfd Socket descriptor of the socket
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On any failure, a
|
||||
|
|
@ -154,10 +142,10 @@ ssize_t nx_send(int sockfd, FAR const void *buf, size_t len, int flags)
|
|||
* equivalent to sendto(sockfd,buf,len,flags,NULL,0).
|
||||
*
|
||||
* Input Parameters:
|
||||
* sockfd - Socket descriptor of the socket
|
||||
* buf - Data to send
|
||||
* len - Length of data to send
|
||||
* flags - Send flags
|
||||
* sockfd Socket descriptor of the socket
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error,
|
||||
|
|
@ -209,23 +197,18 @@ ssize_t nx_send(int sockfd, FAR const void *buf, size_t len, int flags)
|
|||
|
||||
ssize_t send(int sockfd, FAR const void *buf, size_t len, int flags)
|
||||
{
|
||||
FAR struct socket *psock;
|
||||
ssize_t ret;
|
||||
|
||||
/* send() is a cancellation point */
|
||||
|
||||
enter_cancellation_point();
|
||||
|
||||
/* Get the underlying socket structure */
|
||||
|
||||
psock = sockfd_socket(sockfd);
|
||||
|
||||
/* Let psock_send() do all of the work */
|
||||
|
||||
ret = psock_send(psock, buf, len, flags);
|
||||
ret = nx_send(sockfd, buf, len, flags);
|
||||
if (ret < 0)
|
||||
{
|
||||
_SO_SETERRNO(psock, -ret);
|
||||
_SO_SETERRNO(sockfd_socket(sockfd), -ret);
|
||||
ret = ERROR;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
#include "socket/socket.h"
|
||||
|
||||
#ifdef CONFIG_NET_CMSG
|
||||
#ifdef CONFIG_NET
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
|
|
@ -49,21 +49,20 @@
|
|||
*
|
||||
* - It is not a cancellation point,
|
||||
* - It does not modify the errno variable, and
|
||||
* - I accepts the internal socket structure as an input rather than an
|
||||
* - It accepts the internal socket structure as an input rather than an
|
||||
* task-specific socket descriptor.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock - A pointer to a NuttX-specific, internal socket structure
|
||||
* msg - Buffer to of the msg
|
||||
* len - Length of buffer
|
||||
* flags - Receive flags
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* msg Message to send
|
||||
* flags Receive flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* send() will return 0. Otherwise, on any failure, a negated errno value
|
||||
* is returned (see comments with send() for a list of appropriate errno
|
||||
* values).
|
||||
* sendmsg() will return 0. Otherwise, on any failure, a negated errno
|
||||
* value is returned (see comments with sendmsg() for a list of appropriate
|
||||
* errno values).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -72,16 +71,11 @@ ssize_t psock_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
|||
{
|
||||
/* Verify that non-NULL pointers were passed */
|
||||
|
||||
if (msg == NULL)
|
||||
if (msg == NULL || msg->msg_iov == NULL || msg->msg_iov->iov_base == NULL)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (msg->msg_iovlen != 1)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
/* Verify that the sockfd corresponds to valid, allocated socket */
|
||||
|
||||
if (psock == NULL || psock->s_conn == NULL)
|
||||
|
|
@ -94,50 +88,34 @@ ssize_t psock_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
|||
*/
|
||||
|
||||
DEBUGASSERT(psock->s_sockif != NULL &&
|
||||
(psock->s_sockif->si_sendmsg != NULL ||
|
||||
psock->s_sockif->si_sendto != NULL));
|
||||
psock->s_sockif->si_sendmsg != NULL);
|
||||
|
||||
if (psock->s_sockif->si_sendmsg != NULL)
|
||||
{
|
||||
return psock->s_sockif->si_sendmsg(psock, msg, flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Socket doesn't implement si_sendmsg fallback to si_sendto */
|
||||
|
||||
FAR void *buf = msg->msg_iov->iov_base;
|
||||
FAR struct sockaddr *to = msg->msg_name;
|
||||
socklen_t tolen = msg->msg_namelen;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
|
||||
return psock->s_sockif->si_sendto(psock, buf, len, flags, to, tolen);
|
||||
}
|
||||
return psock->s_sockif->si_sendmsg(psock, msg, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nx_sendfrom
|
||||
* Name: nx_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* nx_sendfrom() receives messages from a socket, and may be used to
|
||||
* nx_sendmsg() receives messages from a socket, and may be used to
|
||||
* receive data on a socket whether or not it is connection-oriented.
|
||||
* This is an internal OS interface. It is functionally equivalent to
|
||||
* sendfrom() except that:
|
||||
* sendmsg() except that:
|
||||
*
|
||||
* - It is not a cancellation point, and
|
||||
* - It does not modify the errno variable.
|
||||
*
|
||||
* Input Parameters:
|
||||
* sockfd - Socket descriptor of socket
|
||||
* msg Buffer to receive msg
|
||||
* len - Length of buffer
|
||||
* flags - Receive flags
|
||||
* sockfd Socket descriptor of socket
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. If no data is
|
||||
* available to be received and the peer has performed an orderly shutdown,
|
||||
* send() will return 0. Otherwise, on any failure, a negated errno value
|
||||
* is returned (see comments with send() for a list of appropriate errno
|
||||
* values).
|
||||
* sendmsg() will return 0. Otherwise, on any failure, a negated errno
|
||||
* value is returned (see comments with sendmsg() for a list of appropriate
|
||||
* errno values).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -163,8 +141,7 @@ ssize_t nx_sendmsg(int sockfd, FAR struct msghdr *msg, int flags)
|
|||
*
|
||||
* Parameters:
|
||||
* sockfd Socket descriptor of socket
|
||||
* msg Buffer to receive msg
|
||||
* len Length of buffer
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags
|
||||
*
|
||||
* Returned Value:
|
||||
|
|
@ -200,23 +177,18 @@ ssize_t nx_sendmsg(int sockfd, FAR struct msghdr *msg, int flags)
|
|||
|
||||
ssize_t sendmsg(int sockfd, FAR struct msghdr *msg, int flags)
|
||||
{
|
||||
FAR struct socket *psock;
|
||||
ssize_t ret;
|
||||
|
||||
/* sendfrom() is a cancellation point */
|
||||
/* sendmsg() is a cancellation point */
|
||||
|
||||
enter_cancellation_point();
|
||||
|
||||
/* Get the underlying socket structure */
|
||||
/* Let psock_sendmsg() do all of the work */
|
||||
|
||||
psock = sockfd_socket(sockfd);
|
||||
|
||||
/* Let psock_sendfrom() do all of the work */
|
||||
|
||||
ret = psock_sendmsg(psock, msg, flags);
|
||||
ret = nx_sendmsg(sockfd, msg, flags);
|
||||
if (ret < 0)
|
||||
{
|
||||
_SO_SETERRNO(psock, -ret);
|
||||
_SO_SETERRNO(sockfd_socket(sockfd), -ret);
|
||||
ret = ERROR;
|
||||
}
|
||||
|
||||
|
|
@ -224,4 +196,4 @@ ssize_t sendmsg(int sockfd, FAR struct msghdr *msg, int flags)
|
|||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_CMSG */
|
||||
#endif /* CONFIG_NET */
|
||||
|
|
|
|||
|
|
@ -107,46 +107,22 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
size_t len, int flags, FAR const struct sockaddr *to,
|
||||
socklen_t tolen)
|
||||
{
|
||||
ssize_t nsent;
|
||||
struct iovec iov;
|
||||
struct msghdr msg;
|
||||
|
||||
/* Verify that non-NULL pointers were passed */
|
||||
iov.iov_base = (FAR void *)buf;
|
||||
iov.iov_len = len;
|
||||
msg.msg_name = (FAR struct sockaddr *)to;
|
||||
msg.msg_namelen = tolen;
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_control = NULL;
|
||||
msg.msg_controllen = 0;
|
||||
msg.msg_flags = 0;
|
||||
|
||||
if (buf == NULL)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
/* And let psock_sendmsg do all of the work */
|
||||
|
||||
/* If to is NULL or tolen is zero, then this function is same as send (for
|
||||
* connected socket types)
|
||||
*/
|
||||
|
||||
if (to == NULL || tolen <= 0)
|
||||
{
|
||||
return psock_send(psock, buf, len, flags);
|
||||
}
|
||||
|
||||
/* Verify that the psock corresponds to valid, allocated socket */
|
||||
|
||||
if (psock == NULL || psock->s_conn == NULL)
|
||||
{
|
||||
nerr("ERROR: Invalid socket\n");
|
||||
return -EBADF;
|
||||
}
|
||||
|
||||
/* Let the address family's sendto() method handle the operation */
|
||||
|
||||
DEBUGASSERT(psock->s_sockif != NULL && psock->s_sockif->si_sendto != NULL);
|
||||
nsent = psock->s_sockif->si_sendto(psock, buf, len, flags, to, tolen);
|
||||
|
||||
/* Check if the domain-specific sendto() logic failed */
|
||||
|
||||
if (nsent < 0)
|
||||
{
|
||||
nerr("ERROR: Family-specific send failed: %ld\n", (long)nsent);
|
||||
return nsent;
|
||||
}
|
||||
|
||||
return nsent;
|
||||
return psock_sendmsg(psock, &msg, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ ifeq ($(CONFIG_NET_USRSOCK),y)
|
|||
NET_CSRCS += usrsock_close.c usrsock_conn.c usrsock_bind.c usrsock_connect.c
|
||||
NET_CSRCS += usrsock_dev.c usrsock_getpeername.c
|
||||
NET_CSRCS += usrsock_event.c usrsock_getsockname.c usrsock_getsockopt.c
|
||||
NET_CSRCS += usrsock_poll.c usrsock_recvfrom.c usrsock_sendto.c
|
||||
NET_CSRCS += usrsock_poll.c usrsock_recvmsg.c usrsock_sendmsg.c
|
||||
NET_CSRCS += usrsock_setsockopt.c usrsock_socket.c usrsock_sockif.c
|
||||
NET_CSRCS += usrsock_accept.c usrsock_listen.c usrsock_ioctl.c
|
||||
|
||||
|
|
|
|||
|
|
@ -516,21 +516,18 @@ int usrsock_poll(FAR struct socket *psock, FAR struct pollfd *fds,
|
|||
bool setup);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_sendto
|
||||
* Name: usrsock_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
|
||||
* socket, the parameters to and 'tolen' are ignored (and the error EISCONN
|
||||
* may be returned when they are not NULL and 0), and the error ENOTCONN is
|
||||
* returned when the socket was not actually connected.
|
||||
* If sendmsg() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
|
||||
* socket, the parameters 'msg_name' and 'msg_namelen' are ignored (and the
|
||||
* error EISCONN may be returned when they are not NULL and 0), and the
|
||||
* error ENOTCONN is returned when the socket was not actually connected.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A reference to the socket structure of the socket
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* msg Message to send
|
||||
* flags Send flags (ignored)
|
||||
* to Address of recipient
|
||||
* tolen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On any failure, a
|
||||
|
|
@ -538,15 +535,14 @@ int usrsock_poll(FAR struct socket *psock, FAR struct pollfd *fds,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t usrsock_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags, FAR const struct sockaddr *to,
|
||||
socklen_t tolen);
|
||||
ssize_t usrsock_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_recvfrom
|
||||
* Name: usrsock_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* recvfrom() receives messages from a socket, and may be used to receive
|
||||
* recvmsg() receives messages from a socket, and may be used to receive
|
||||
* data on a socket whether or not it is connection-oriented.
|
||||
*
|
||||
* If from is not NULL, and the underlying protocol provides the source
|
||||
|
|
@ -555,12 +551,9 @@ ssize_t usrsock_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
* on return to indicate the actual size of the address stored there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A reference to the socket structure of the socket
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags (ignored)
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
|
|
@ -570,9 +563,8 @@ ssize_t usrsock_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t usrsock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
||||
int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen);
|
||||
ssize_t usrsock_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_getsockopt
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/usrsock/usrsock_recvfrom.c
|
||||
* net/usrsock/usrsock_recvmsg.c
|
||||
*
|
||||
* Copyright (C) 2015, 2017 Haltian Ltd. All rights reserved.
|
||||
* Author: Jussi Kivilinna <jussi.kivilinna@haltian.com>
|
||||
|
|
@ -194,10 +194,10 @@ static int do_recvfrom_request(FAR struct usrsock_conn_s *conn,
|
|||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_recvfrom
|
||||
* Name: usrsock_recvmsg
|
||||
*
|
||||
* Description:
|
||||
* recvfrom() receives messages from a socket, and may be used to receive
|
||||
* recvmsg() receives messages from a socket, and may be used to receive
|
||||
* data on a socket whether or not it is connection-oriented.
|
||||
*
|
||||
* If from is not NULL, and the underlying protocol provides the source
|
||||
|
|
@ -206,12 +206,9 @@ static int do_recvfrom_request(FAR struct usrsock_conn_s *conn,
|
|||
* on return to indicate the actual size of the address stored there.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A reference to the socket structure of the socket
|
||||
* buf Buffer to receive data
|
||||
* len Length of buffer
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* msg Buffer to receive the message
|
||||
* flags Receive flags (ignored)
|
||||
* from Address of source (may be NULL)
|
||||
* fromlen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters received. If no data is
|
||||
|
|
@ -221,10 +218,13 @@ static int do_recvfrom_request(FAR struct usrsock_conn_s *conn,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t usrsock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
||||
int flags, FAR struct sockaddr *from,
|
||||
FAR socklen_t *fromlen)
|
||||
ssize_t usrsock_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
FAR void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR struct sockaddr *from = msg->msg_name;
|
||||
FAR socklen_t *fromlen = &msg->msg_namelen;
|
||||
FAR struct usrsock_conn_s *conn = psock->s_conn;
|
||||
struct usrsock_data_reqstate_s state =
|
||||
{
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/usrsock/usrsock_sendto.c
|
||||
* net/usrsock/usrsock_sendmsg.c
|
||||
*
|
||||
* Copyright (C) 2015, 2017 Haltian Ltd. All rights reserved.
|
||||
* Author: Jussi Kivilinna <jussi.kivilinna@haltian.com>
|
||||
|
|
@ -191,21 +191,18 @@ static int do_sendto_request(FAR struct usrsock_conn_s *conn,
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_sendto
|
||||
* Name: usrsock_sendmsg
|
||||
*
|
||||
* Description:
|
||||
* If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
|
||||
* socket, the parameters to and 'tolen' are ignored (and the error EISCONN
|
||||
* may be returned when they are not NULL and 0), and the error ENOTCONN is
|
||||
* returned when the socket was not actually connected.
|
||||
* If sendmsg() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
|
||||
* socket, the parameters 'msg_name' and 'msg_namelen' are ignored (and the
|
||||
* error EISCONN may be returned when they are not NULL and 0), and the
|
||||
* error ENOTCONN is returned when the socket was not actually connected.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A reference to the socket structure of the socket
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* msg Message to send
|
||||
* flags Send flags (ignored)
|
||||
* to Address of recipient
|
||||
* tolen The length of the address structure
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On any failure, a
|
||||
|
|
@ -213,10 +210,13 @@ static int do_sendto_request(FAR struct usrsock_conn_s *conn,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t usrsock_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
size_t len, int flags, FAR const struct sockaddr *to,
|
||||
socklen_t tolen)
|
||||
ssize_t usrsock_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
FAR const void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR const struct sockaddr *to = msg->msg_name;
|
||||
socklen_t tolen = msg->msg_namelen;
|
||||
FAR struct usrsock_conn_s *conn = psock->s_conn;
|
||||
struct usrsock_reqstate_s state =
|
||||
{
|
||||
|
|
@ -226,6 +226,13 @@ ssize_t usrsock_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
|
||||
DEBUGASSERT(conn);
|
||||
|
||||
/* Validity check, only single iov supported */
|
||||
|
||||
if (msg->msg_iovlen != 1)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
net_lock();
|
||||
|
||||
if (conn->state == USRSOCK_CONN_STATE_UNINITIALIZED ||
|
||||
|
|
@ -60,9 +60,6 @@ static int usrsock_sockif_setup(FAR struct socket *psock,
|
|||
int protocol);
|
||||
static sockcaps_t usrsock_sockif_sockcaps(FAR struct socket *psock);
|
||||
static void usrsock_sockif_addref(FAR struct socket *psock);
|
||||
static ssize_t usrsock_sockif_send(FAR struct socket *psock,
|
||||
FAR const void *buf, size_t len,
|
||||
int flags);
|
||||
static int usrsock_sockif_close(FAR struct socket *psock);
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -81,13 +78,12 @@ const struct sock_intf_s g_usrsock_sockif =
|
|||
usrsock_connect, /* si_connect */
|
||||
usrsock_accept, /* si_accept */
|
||||
usrsock_poll, /* si_poll */
|
||||
usrsock_sockif_send, /* si_send */
|
||||
usrsock_sendto, /* si_sendto */
|
||||
usrsock_sendmsg, /* si_sendmsg */
|
||||
usrsock_recvmsg, /* si_recvmsg */
|
||||
usrsock_sockif_close, /* si_close */
|
||||
#ifdef CONFIG_NET_SENDFILE
|
||||
NULL, /* si_sendfile */
|
||||
#endif
|
||||
usrsock_recvfrom, /* si_recvfrom */
|
||||
usrsock_sockif_close, /* si_close */
|
||||
usrsock_ioctl /* si_ioctl */
|
||||
};
|
||||
|
||||
|
|
@ -224,33 +220,6 @@ static void usrsock_sockif_addref(FAR struct socket *psock)
|
|||
conn->crefs++;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_sockif_send
|
||||
*
|
||||
* Description:
|
||||
* The usrsock_sockif_send() call may be used only when the socket is in
|
||||
* a connected state (so that the intended recipient is known).
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags (ignored)
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On error, a negated
|
||||
* errno value is returned (see send() for the list of appropriate error
|
||||
* values.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t usrsock_sockif_send(FAR struct socket *psock,
|
||||
FAR const void *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
return usrsock_sendto(psock, buf, len, flags, NULL, 0);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_sockif_close
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue