2007-09-07 02:10:10 +02:00
|
|
|
/****************************************************************************
|
2014-06-29 01:25:18 +02:00
|
|
|
* net/socket/getsockopt.c
|
2007-09-07 02:10:10 +02:00
|
|
|
*
|
2019-12-24 15:09:55 +01:00
|
|
|
* Copyright (C) 2007-2009, 2012, 2014, 2017-2019 Gregory Nutt. All rights
|
2018-03-12 17:59:46 +01:00
|
|
|
* reserved.
|
2012-03-02 20:57:52 +01:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-09-07 02:10:10 +02:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2007-09-08 21:50:59 +02:00
|
|
|
#if defined(CONFIG_NET) && defined(CONFIG_NET_SOCKOPTS)
|
2007-09-07 02:10:10 +02:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
2015-02-15 22:18:35 +01:00
|
|
|
#include <sys/time.h>
|
2017-03-31 16:58:14 +02:00
|
|
|
#include <debug.h>
|
|
|
|
#include <assert.h>
|
2007-09-07 02:10:10 +02:00
|
|
|
#include <errno.h>
|
|
|
|
|
2014-06-29 01:25:18 +02:00
|
|
|
#include "socket/socket.h"
|
2018-03-12 17:59:46 +01:00
|
|
|
#include "tcp/tcp.h"
|
2017-03-31 16:58:14 +02:00
|
|
|
#include "usrsock/usrsock.h"
|
2014-06-26 22:23:21 +02:00
|
|
|
#include "utils/utils.h"
|
2007-09-07 02:10:10 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2018-03-12 17:59:46 +01:00
|
|
|
* Private Functions
|
2007-09-07 02:10:10 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-03-12 17:59:46 +01:00
|
|
|
* Name: psock_socketlevel_option
|
2007-09-07 02:10:10 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2018-03-12 17:59:46 +01:00
|
|
|
* getsockopt() retrieve the value for the option specified by the
|
|
|
|
* 'option' argument for the socket specified by the 'psock' argument. If
|
2007-09-07 02:10:10 +02:00
|
|
|
* the size of the option value is greater than 'value_len', the value
|
|
|
|
* stored in the object pointed to by the 'value' argument will be silently
|
|
|
|
* truncated. Otherwise, the length pointed to by the 'value_len' argument
|
|
|
|
* will be modified to indicate the actual length of the'value'.
|
|
|
|
*
|
|
|
|
* The 'level' argument specifies the protocol level of the option. To
|
|
|
|
* retrieve options at the socket level, specify the level argument as
|
2018-03-12 17:59:46 +01:00
|
|
|
* SOL_SOCKET; to retrieve options at the TCP-protocol level, the level
|
|
|
|
* argument is SOL_CP.
|
2007-09-07 02:10:10 +02:00
|
|
|
*
|
2018-03-12 17:59:46 +01:00
|
|
|
* See <sys/socket.h> a complete list of values for the socket-level
|
|
|
|
* 'option' argument. Protocol-specific options are are protocol specific
|
|
|
|
* header files (such as netinet/tcp.h for the case of the TCP protocol).
|
2007-09-07 02:10:10 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2012-03-02 20:57:52 +01:00
|
|
|
* psock Socket structure of the socket to query
|
2007-09-07 02:10:10 +02:00
|
|
|
* level Protocol level to set the option
|
|
|
|
* option identifies the option to get
|
|
|
|
* value Points to the argument value
|
|
|
|
* value_len The length of the argument value
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2018-03-12 17:59:46 +01:00
|
|
|
* Returns zero (OK) on success. On failure, it returns a negated errno
|
|
|
|
* value to indicate the nature of the error. See psock_getsockopt() for
|
|
|
|
* the complete list of appropriate return error codes.
|
2007-09-07 02:10:10 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-03-12 17:59:46 +01:00
|
|
|
static int psock_socketlevel_option(FAR struct socket *psock, int option,
|
|
|
|
FAR void *value, FAR socklen_t *value_len)
|
2007-09-07 02:10:10 +02:00
|
|
|
{
|
2007-09-08 21:50:59 +02:00
|
|
|
/* Verify that the socket option if valid (but might not be supported ) */
|
|
|
|
|
2007-09-09 00:41:00 +02:00
|
|
|
if (!_SO_GETVALID(option) || !value || !value_len)
|
2007-09-08 21:50:59 +02:00
|
|
|
{
|
2017-09-30 16:18:08 +02:00
|
|
|
return -EINVAL;
|
2007-09-08 21:50:59 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 16:58:14 +02:00
|
|
|
#ifdef CONFIG_NET_USRSOCK
|
|
|
|
if (psock->s_type == SOCK_USRSOCK_TYPE)
|
|
|
|
{
|
|
|
|
FAR struct usrsock_conn_s *conn = psock->s_conn;
|
|
|
|
|
|
|
|
DEBUGASSERT(conn);
|
|
|
|
|
|
|
|
/* Some of the socket options are handled from this function. */
|
|
|
|
|
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case SO_TYPE: /* Type can be read from NuttX psock structure. */
|
|
|
|
case SO_RCVTIMEO: /* Rx timeouts can be handled at NuttX side, thus
|
|
|
|
* simplify daemon implementation. */
|
|
|
|
case SO_SNDTIMEO: /* Rx timeouts can be handled at NuttX side, thus
|
|
|
|
* simplify daemon implementation. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* Other options are passed to usrsock daemon. */
|
|
|
|
{
|
2018-03-12 17:59:46 +01:00
|
|
|
return usrsock_getsockopt(conn, SOL_SOCKET, option, value, value_len);
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
/* Process the option */
|
2012-03-02 20:57:52 +01:00
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
switch (option)
|
|
|
|
{
|
2020-01-31 10:57:02 +01:00
|
|
|
case SO_ACCEPTCONN: /* Reports whether socket listening is enabled */
|
|
|
|
if (*value_len < sizeof(int))
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*(FAR int *)value = _SS_ISLISTENING(psock->s_flags);
|
|
|
|
*value_len = sizeof(int);
|
|
|
|
break;
|
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
/* The following options take a point to an integer boolean value.
|
|
|
|
* We will blindly report the bit here although the implementation
|
|
|
|
* is outside of the scope of getsockopt.
|
|
|
|
*/
|
|
|
|
|
|
|
|
case SO_BROADCAST: /* Permits sending of broadcast messages */
|
2018-03-13 15:07:03 +01:00
|
|
|
case SO_DEBUG: /* Enables recording of debugging information */
|
|
|
|
case SO_DONTROUTE: /* Requests outgoing messages bypass standard routing */
|
2018-03-12 17:59:46 +01:00
|
|
|
#ifndef CONFIG_NET_TCPPROTO_OPTIONS
|
|
|
|
case SO_KEEPALIVE: /* Verifies TCP connections active by enabling the
|
|
|
|
* periodic transmission of probes */
|
|
|
|
#endif
|
2007-09-08 21:50:59 +02:00
|
|
|
case SO_OOBINLINE: /* Leaves received out-of-band data inline */
|
2018-03-13 15:07:03 +01:00
|
|
|
case SO_REUSEADDR: /* Allow reuse of local addresses */
|
2007-09-08 21:50:59 +02:00
|
|
|
{
|
|
|
|
sockopt_t optionset;
|
|
|
|
|
|
|
|
/* Verify that option is the size of an 'int'. Should also check
|
|
|
|
* that 'value' is properly aligned for an 'int'
|
|
|
|
*/
|
|
|
|
|
2007-09-09 00:41:00 +02:00
|
|
|
if (*value_len < sizeof(int))
|
2007-09-08 21:50:59 +02:00
|
|
|
{
|
2017-09-30 16:18:08 +02:00
|
|
|
return -EINVAL;
|
2007-09-08 21:50:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sample the current options. This is atomic operation and so
|
|
|
|
* should not require any special steps for thread safety. We
|
|
|
|
* this outside of the macro because you can never be sure what
|
|
|
|
* a macro will do.
|
|
|
|
*/
|
|
|
|
|
2015-10-08 23:10:04 +02:00
|
|
|
optionset = psock->s_options;
|
|
|
|
*(FAR int *)value = _SO_GETOPT(optionset, option);
|
|
|
|
*value_len = sizeof(int);
|
2007-09-08 21:50:59 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-03-12 17:59:46 +01:00
|
|
|
#ifdef CONFIG_NET_TCPPROTO_OPTIONS
|
|
|
|
/* Any connection-oriented protocol could potentially support
|
|
|
|
* SO_KEEPALIVE. However, this option is currently only available for
|
|
|
|
* TCP/IP.
|
|
|
|
*
|
|
|
|
* NOTE: SO_KEEPALIVE is not really a socket-level option; it is a
|
|
|
|
* protocol-level option. A given TCP connection may service multiple
|
|
|
|
* sockets (via dup'ing of the socket). There is, however, still only
|
|
|
|
* one connection to be monitored and that is a global attribute across
|
|
|
|
* all of the clones that may use the underlying connection.
|
|
|
|
*/
|
|
|
|
|
|
|
|
case SO_KEEPALIVE: /* Verifies TCP connections active by enabling the
|
|
|
|
* periodic transmission of probes */
|
|
|
|
return tcp_getsockopt(psock, option, value, value_len);
|
|
|
|
#endif
|
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
case SO_TYPE: /* Reports the socket type */
|
|
|
|
{
|
|
|
|
/* Verify that option is the size of an 'int'. Should also check
|
|
|
|
* that 'value' is properly aligned for an 'int'
|
|
|
|
*/
|
|
|
|
|
2007-09-09 00:41:00 +02:00
|
|
|
if (*value_len < sizeof(int))
|
2007-09-08 21:50:59 +02:00
|
|
|
{
|
2017-09-30 16:18:08 +02:00
|
|
|
return -EINVAL;
|
2013-04-05 14:40:40 +02:00
|
|
|
}
|
2007-09-08 21:50:59 +02:00
|
|
|
|
2017-03-31 16:58:14 +02:00
|
|
|
#ifdef CONFIG_NET_USRSOCK
|
|
|
|
if (psock->s_type == SOCK_USRSOCK_TYPE)
|
|
|
|
{
|
|
|
|
FAR struct usrsock_conn_s *conn = psock->s_conn;
|
|
|
|
|
|
|
|
/* Return the actual socket type */
|
|
|
|
|
2018-10-30 01:00:30 +01:00
|
|
|
*(FAR int *)value = conn->type;
|
|
|
|
*value_len = sizeof(int);
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
/* Return the socket type */
|
|
|
|
|
2015-10-08 23:10:04 +02:00
|
|
|
*(FAR int *)value = psock->s_type;
|
|
|
|
*value_len = sizeof(int);
|
2007-09-08 21:50:59 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* The following are valid only if the OS CLOCK feature is enabled */
|
|
|
|
|
|
|
|
case SO_RCVTIMEO:
|
|
|
|
case SO_SNDTIMEO:
|
|
|
|
{
|
|
|
|
socktimeo_t timeo;
|
|
|
|
|
|
|
|
/* Verify that option is the size of an 'int'. Should also check
|
|
|
|
* that 'value' is properly aligned for an 'int'
|
|
|
|
*/
|
|
|
|
|
2007-09-09 00:41:00 +02:00
|
|
|
if (*value_len < sizeof(struct timeval))
|
2007-09-08 21:50:59 +02:00
|
|
|
{
|
2017-09-30 16:18:08 +02:00
|
|
|
return -EINVAL;
|
2013-04-05 14:40:40 +02:00
|
|
|
}
|
2007-09-08 21:50:59 +02:00
|
|
|
|
|
|
|
/* Get the timeout value. This is a atomic operation and should
|
|
|
|
* require no special operation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (option == SO_RCVTIMEO)
|
|
|
|
{
|
|
|
|
timeo = psock->s_rcvtimeo;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
timeo = psock->s_sndtimeo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then return the timeout value to the caller */
|
|
|
|
|
|
|
|
net_dsec2timeval(timeo, (struct timeval *)value);
|
2007-09-09 00:41:00 +02:00
|
|
|
*value_len = sizeof(struct timeval);
|
2007-09-08 21:50:59 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-12-24 15:09:55 +01:00
|
|
|
case SO_ERROR: /* Reports and clears error status. */
|
|
|
|
{
|
|
|
|
if (*value_len != sizeof(int))
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*(FAR int *)value = (int)psock->s_error;
|
|
|
|
psock->s_error = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-03-13 15:07:03 +01:00
|
|
|
/* The following are not yet implemented (return values other than {0,1) */
|
2007-09-08 21:50:59 +02:00
|
|
|
|
2018-03-13 15:07:03 +01:00
|
|
|
case SO_LINGER: /* Lingers on a close() if data is present */
|
|
|
|
case SO_RCVBUF: /* Sets receive buffer size */
|
2007-09-08 21:50:59 +02:00
|
|
|
case SO_RCVLOWAT: /* Sets the minimum number of bytes to input */
|
2018-03-13 15:07:03 +01:00
|
|
|
case SO_SNDBUF: /* Sets send buffer size */
|
2007-09-08 21:50:59 +02:00
|
|
|
case SO_SNDLOWAT: /* Sets the minimum number of bytes to output */
|
|
|
|
|
|
|
|
default:
|
2017-09-30 16:18:08 +02:00
|
|
|
return -ENOPROTOOPT;
|
2007-09-08 21:50:59 +02:00
|
|
|
}
|
2013-04-05 14:40:40 +02:00
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
return OK;
|
2007-09-07 02:10:10 +02:00
|
|
|
}
|
|
|
|
|
2018-03-12 17:59:46 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: psock_getsockopt
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* getsockopt() retrieve the value for the option specified by the
|
|
|
|
* 'option' argument for the socket specified by the 'psock' argument. If
|
|
|
|
* the size of the option value is greater than 'value_len', the value
|
|
|
|
* stored in the object pointed to by the 'value' argument will be silently
|
|
|
|
* truncated. Otherwise, the length pointed to by the 'value_len' argument
|
|
|
|
* will be modified to indicate the actual length of the 'value'.
|
|
|
|
*
|
|
|
|
* The 'level' argument specifies the protocol level of the option. To
|
|
|
|
* retrieve options at the socket level, specify the level argument as
|
|
|
|
* SOL_SOCKET; to retrieve options at the TCP-protocol level, the level
|
|
|
|
* argument is SOL_CP.
|
|
|
|
*
|
|
|
|
* See <sys/socket.h> a complete list of values for the socket-level
|
|
|
|
* 'option' argument. Protocol-specific options are are protocol specific
|
|
|
|
* header files (such as netinet/tcp.h for the case of the TCP protocol).
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2018-03-12 17:59:46 +01:00
|
|
|
* psock Socket structure of the socket to query
|
|
|
|
* level Protocol level to set the option
|
|
|
|
* option identifies the option to get
|
|
|
|
* value Points to the argument value
|
|
|
|
* value_len The length of the argument value
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Returns zero (OK) on success. On failure, it returns a negated errno
|
|
|
|
* value to indicate the nature of the error.
|
|
|
|
*
|
|
|
|
* EINVAL
|
|
|
|
* The specified option is invalid at the specified socket 'level' or the
|
|
|
|
* socket has been shutdown.
|
|
|
|
* ENOPROTOOPT
|
|
|
|
* The 'option' is not supported by the protocol.
|
|
|
|
* ENOTSOCK
|
|
|
|
* The 'psock' argument does not refer to a socket.
|
|
|
|
* ENOBUFS
|
|
|
|
* Insufficient resources are available in the system to complete the
|
|
|
|
* call.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int psock_getsockopt(FAR struct socket *psock, int level, int option,
|
|
|
|
FAR void *value, FAR socklen_t *value_len)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2020-01-31 10:48:46 +01:00
|
|
|
/* Verify that the sockfd corresponds to valid, allocated socket */
|
|
|
|
|
|
|
|
if (psock == NULL || psock->s_crefs <= 0)
|
|
|
|
{
|
|
|
|
return -EBADF;
|
|
|
|
}
|
|
|
|
|
2018-03-12 17:59:46 +01:00
|
|
|
/* Handle retrieval of the socket option according to the level at which
|
|
|
|
* option should be applied.
|
|
|
|
*/
|
|
|
|
|
|
|
|
switch (level)
|
|
|
|
{
|
|
|
|
case SOL_SOCKET: /* Socket-level options (see include/sys/socket.h) */
|
|
|
|
ret = psock_socketlevel_option(psock, option, value, value_len);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOL_TCP: /* TCP protocol socket options (see include/netinet/tcp.h) */
|
|
|
|
#ifdef CONFIG_NET_TCPPROTO_OPTIONS
|
|
|
|
ret = tcp_getsockopt(psock, option, value, value_len);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* These levels are defined in sys/socket.h, but are not yet
|
|
|
|
* implemented.
|
|
|
|
*/
|
|
|
|
|
|
|
|
case SOL_IP: /* TCP protocol socket options (see include/netinet/ip.h) */
|
|
|
|
case SOL_IPV6: /* TCP protocol socket options (see include/netinet/ip6.h) */
|
|
|
|
case SOL_UDP: /* TCP protocol socket options (see include/netinit/udp.h) */
|
|
|
|
ret = -ENOSYS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* The provided level is invalid */
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-03-02 20:57:52 +01:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: getsockopt
|
2012-03-02 20:57:52 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2018-03-12 17:59:46 +01:00
|
|
|
* getsockopt() retrieve the value for the option specified by the
|
2012-03-02 20:57:52 +01:00
|
|
|
* 'option' argument for the socket specified by the 'sockfd' argument. If
|
|
|
|
* the size of the option value is greater than 'value_len', the value
|
|
|
|
* stored in the object pointed to by the 'value' argument will be silently
|
|
|
|
* truncated. Otherwise, the length pointed to by the 'value_len' argument
|
2018-03-12 17:59:46 +01:00
|
|
|
* will be modified to indicate the actual length of the 'value'.
|
2012-03-02 20:57:52 +01:00
|
|
|
*
|
|
|
|
* The 'level' argument specifies the protocol level of the option. To
|
|
|
|
* retrieve options at the socket level, specify the level argument as
|
2018-03-12 17:59:46 +01:00
|
|
|
* SOL_SOCKET; to retrieve options at the TCP-protocol level, the level
|
|
|
|
* argument is SOL_CP.
|
2012-03-02 20:57:52 +01:00
|
|
|
*
|
2018-03-12 17:59:46 +01:00
|
|
|
* See <sys/socket.h> a complete list of values for the socket-level
|
|
|
|
* 'option' argument. Protocol-specific options are are protocol specific
|
|
|
|
* header files (such as netinet/tcp.h for the case of the TCP protocol).
|
2012-03-02 20:57:52 +01:00
|
|
|
*
|
2018-03-12 17:59:46 +01:00
|
|
|
* Input Parameters:
|
2012-03-02 20:57:52 +01:00
|
|
|
* sockfd Socket descriptor of socket
|
|
|
|
* level Protocol level to set the option
|
|
|
|
* option identifies the option to get
|
|
|
|
* value Points to the argument value
|
|
|
|
* value_len The length of the argument value
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2018-03-12 17:59:46 +01:00
|
|
|
* Returns zero (OK) on success. On failure, -1 (ERROR) is returned and th
|
|
|
|
* errno variable is set appropriately:
|
2012-03-02 20:57:52 +01:00
|
|
|
*
|
2018-03-12 17:59:46 +01:00
|
|
|
* EBADF
|
|
|
|
* The 'sockfd' argument is not a valid socket descriptor.
|
|
|
|
* EINVAL
|
|
|
|
* The specified option is invalid at the specified socket 'level' or the
|
|
|
|
* socket has been shutdown.
|
|
|
|
* ENOPROTOOPT
|
|
|
|
* The 'option' is not supported by the protocol.
|
|
|
|
* ENOTSOCK
|
|
|
|
* The 'sockfd' argument does not refer to a socket.
|
|
|
|
* ENOBUFS
|
|
|
|
* Insufficient resources are available in the system to complete the
|
|
|
|
* call.
|
2012-03-02 20:57:52 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int getsockopt(int sockfd, int level, int option, void *value, socklen_t *value_len)
|
|
|
|
{
|
|
|
|
FAR struct socket *psock;
|
2017-09-30 16:18:08 +02:00
|
|
|
int ret;
|
2012-03-02 20:57:52 +01:00
|
|
|
|
|
|
|
/* Get the underlying socket structure */
|
|
|
|
|
|
|
|
psock = sockfd_socket(sockfd);
|
|
|
|
|
|
|
|
/* Then let psock_getsockopt() do all of the work */
|
|
|
|
|
2017-09-30 16:18:08 +02:00
|
|
|
ret = psock_getsockopt(psock, level, option, value, value_len);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2020-01-31 10:48:46 +01:00
|
|
|
_SO_SETERRNO(psock, -ret);
|
2017-09-30 16:18:08 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
2012-03-02 20:57:52 +01:00
|
|
|
}
|
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
#endif /* CONFIG_NET && CONFIG_NET_SOCKOPTS */
|