mirror of
https://github.com/apache/nuttx.git
synced 2026-08-03 13:19:01 +00:00
Some third-party network libraries use PACKET_ADD_MEMBERSHIP to add MAC addresses to devices, and this patch can add support for this. Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
125 lines
4.1 KiB
C
125 lines
4.1 KiB
C
/****************************************************************************
|
|
* net/pkt/pkt_getsockopt.c
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* 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>
|
|
|
|
#include <sys/time.h>
|
|
#include <stdint.h>
|
|
#include <errno.h>
|
|
#include <assert.h>
|
|
#include <debug.h>
|
|
|
|
#include <nuttx/net/net.h>
|
|
#include <nuttx/net/pkt.h>
|
|
|
|
#include "socket/socket.h"
|
|
#include "utils/utils.h"
|
|
#include "pkt/pkt.h"
|
|
|
|
#ifdef CONFIG_NET_PKTPROTO_OPTIONS
|
|
|
|
/****************************************************************************
|
|
* Public Functions
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Name: pkt_getsockopt
|
|
*
|
|
* Description:
|
|
* pkt_getsockopt() retrieves 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'.
|
|
*
|
|
* 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 nuttx/pkt.h for the case of the PKT protocol).
|
|
*
|
|
* Input Parameters:
|
|
* 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. See psock_getsockopt() for
|
|
* the complete list of appropriate return error codes.
|
|
*
|
|
****************************************************************************/
|
|
|
|
int pkt_getsockopt(FAR struct socket *psock, int level, int option,
|
|
FAR void *value, FAR socklen_t *value_len)
|
|
{
|
|
int ret = OK;
|
|
|
|
DEBUGASSERT(value != NULL && value_len != NULL);
|
|
|
|
if (level != SOL_PACKET)
|
|
{
|
|
return -ENOPROTOOPT;
|
|
}
|
|
|
|
if (psock->s_type != SOCK_RAW)
|
|
{
|
|
nerr("ERROR: Not a RAW PKT socket\n");
|
|
return -ENOTCONN;
|
|
}
|
|
|
|
switch (option)
|
|
{
|
|
#if defined(CONFIG_NET_PKT_WRITE_BUFFERS) && CONFIG_NET_SEND_BUFSIZE > 0
|
|
case SO_SNDBUF:
|
|
{
|
|
FAR struct pkt_conn_s *conn;
|
|
conn = psock->s_conn;
|
|
/* Verify that option is the size of an 'int'. Should also check
|
|
* that 'value' is properly aligned for an 'int'
|
|
*/
|
|
|
|
if (*value_len < sizeof(int))
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
*(FAR int *)value = conn->sndbufs;
|
|
break;
|
|
}
|
|
#endif
|
|
|
|
default:
|
|
nerr("ERROR: Unrecognized RAW PKT socket option: %d\n", option);
|
|
ret = -ENOPROTOOPT;
|
|
break;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
#endif /* CONFIG_NET_PKTPROTO_OPTIONS */
|