modify nuttx bug of lack of files

This commit is contained in:
TangYiwen123
2021-06-11 11:25:07 +08:00
parent 4a7f51a5e9
commit 6d0f2ca39a
6752 changed files with 1528133 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
+44
View File
@@ -0,0 +1,44 @@
############################################################################
# net/inet/Make.defs
#
# 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.
#
############################################################################
# PF_INET/PF_INET6 socket address families
SOCK_CSRCS += inet_txdrain.c
ifeq ($(CONFIG_NET_IPv4),y)
SOCK_CSRCS += inet_sockif.c
SOCK_CSRCS += inet_globals.c
else ifeq ($(CONFIG_NET_IPv6),y)
SOCK_CSRCS += inet_sockif.c
SOCK_CSRCS += inet_globals.c
endif
ifeq ($(CONFIG_NET_IPv4),y)
SOCK_CSRCS += ipv4_setsockopt.c ipv4_getsockname.c ipv4_getpeername.c
endif
ifeq ($(CONFIG_NET_IPv6),y)
SOCK_CSRCS += ipv6_setsockopt.c ipv6_getsockname.c ipv6_getpeername.c
endif
# Include inet build support
DEPPATH += --dep-path inet
VPATH += :inet
+269
View File
@@ -0,0 +1,269 @@
/****************************************************************************
* net/inet/inet.h
*
* 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.
*
****************************************************************************/
#ifndef __NET_INET_INET_H
#define __NET_INET_INET_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <nuttx/net/net.h>
#include <nuttx/net/ip.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration */
#undef HAVE_INET_SOCKETS
#undef HAVE_PFINET_SOCKETS
#undef HAVE_PFINET6_SOCKETS
#if defined(CONFIG_NET_IPv4) || defined(CONFIG_NET_IPv6)
# define HAVE_INET_SOCKETS
# if defined(CONFIG_NET_IPv4)
# define HAVE_PFINET_SOCKETS
# endif
# if defined(CONFIG_NET_IPv6)
# define HAVE_PFINET6_SOCKETS
# endif
#endif
/****************************************************************************
* Public Data
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
#ifdef CONFIG_NET_IPv4
/* Increasing number used for the IP ID field. */
EXTERN uint16_t g_ipid;
#endif /* CONFIG_NET_IPv4 */
/* Well-known IPv6 addresses */
#ifdef CONFIG_NET_IPv6
EXTERN const net_ipv6addr_t g_ipv6_unspecaddr; /* An address of all zeroes */
EXTERN const net_ipv6addr_t g_ipv6_allnodes; /* All link local nodes */
#if defined(CONFIG_NET_ICMPv6_AUTOCONF) || defined(CONFIG_NET_ICMPv6_ROUTER) || \
defined(CONFIG_NET_MLD)
/* IPv6 Multi-cast IP addresses. See RFC 2375 */
EXTERN const net_ipv6addr_t g_ipv6_allrouters; /* All link local routers */
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
EXTERN const net_ipv6addr_t g_ipv6_llnetmask; /* Netmask for local link address */
#endif
#ifdef CONFIG_NET_MLD
EXTERN const net_ipv6addr_t g_ipv6_allmldv2routers; /* All MLDv2 link local routers */
#endif
#ifdef CONFIG_NET_ETHERNET
/* IPv6 Multi-cast Ethernet addresses. Formed from the 16-bit prefix:
*
* 0x33:0x33:xx:xx:xx:xx:
*
* and the last 32-bits of the IPv6 IP address
*/
EXTERN const struct ether_addr g_ipv6_ethallnodes; /* All link local nodes */
EXTERN const struct ether_addr g_ipv6_ethallrouters; /* All link local routers */
#endif /* CONFIG_NET_ETHERNET */
#endif /* CONFIG_NET_ICMPv6_AUTOCONF || CONFIG_NET_ICMPv6_ROUTER || CONFIG_NET_MLD */
#endif /* CONFIG_NET_IPv6 */
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#if defined(CONFIG_NET_TCP) && !defined(CONFIG_NET_TCP_NO_STACK)
struct tcp_conn_s; /* Forward reference */
#endif
struct socket; /* Forward reference */
/****************************************************************************
* Name: inet_sockif
*
* Description:
* Return the socket interface associated with the inet address family.
*
* Input Parameters:
* family - Socket address family
* type - Socket type
* protocol - Socket protocol
*
* Returned Value:
* On success, a non-NULL instance of struct sock_intf_s is returned. NULL
* is returned only if the address family is not supported.
*
****************************************************************************/
FAR const struct sock_intf_s *
inet_sockif(sa_family_t family, int type, int protocol);
/****************************************************************************
* Name: ipv4_setsockopt and ipv6_setsockopt
*
* Description:
* ipv4/6_setsockopt() sets the IPv4- or IPv6-protocol socket option
* specified by the 'option' argument to the value pointed to by the
* 'value' argument for the socket specified by the 'psock' argument.
*
* See <netinet/in.h> for the a complete list of values of IPv4 and IPv6
* protocol socket options.
*
* Input Parameters:
* psock Socket structure of socket to operate on
* option identifies the option to set
* 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_setcockopt() for
* the list of possible error values.
*
****************************************************************************/
#ifdef CONFIG_NET_IPv4
int ipv4_setsockopt(FAR struct socket *psock, int option,
FAR const void *value, socklen_t value_len);
#endif
#ifdef CONFIG_NET_IPv6
int ipv6_setsockopt(FAR struct socket *psock, int option,
FAR const void *value, socklen_t value_len);
#endif
/****************************************************************************
* Name: ipv4_getsockname and ipv6_sockname
*
* Description:
* The ipv4_getsockname() and ipv6_getsockname() function retrieve the
* locally-bound name of the specified INET socket.
*
* Input Parameters:
* psock Point to the socket structure instance [in]
* addr sockaddr structure to receive data [out]
* addrlen Length of sockaddr structure [in/out]
*
* Returned Value:
* On success, 0 is returned, the 'addr' argument points to the address
* of the socket, and the 'addrlen' argument points to the length of the
* address. Otherwise, a negated errno value is returned. See
* getsockname() for the list of returned error values.
*
****************************************************************************/
#ifdef CONFIG_NET_IPv4
int ipv4_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
FAR socklen_t *addrlen);
#endif
#ifdef CONFIG_NET_IPv6
int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
FAR socklen_t *addrlen);
#endif
/****************************************************************************
* Name: ipv4_getpeername and ipv6_peername
*
* Description:
* The ipv4_getpeername() and ipv6_peername() function retrieve the
* remote-connected name of the specified INET socket.
*
* Parameters:
* psock Point to the socket structure instance [in]
* addr sockaddr structure to receive data [out]
* addrlen Length of sockaddr structure [in/out]
*
* Returned Value:
* On success, 0 is returned, the 'addr' argument points to the address
* of the socket, and the 'addrlen' argument points to the length of the
* address. Otherwise, a negated errno value is returned. See
* getpeername() for the list of returned error values.
*
****************************************************************************/
#ifdef CONFIG_NET_IPv4
int ipv4_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
FAR socklen_t *addrlen);
#endif
#ifdef CONFIG_NET_IPv6
int ipv6_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
FAR socklen_t *addrlen);
#endif
/****************************************************************************
* Name: inet_close
*
* Description:
* Performs the close operation on an AF_INET or AF_INET6 socket instance
*
* Input Parameters:
* psock Socket instance
*
* Returned Value:
* 0 on success; -1 on error with errno set appropriately.
*
* Assumptions:
*
****************************************************************************/
int inet_close(FAR struct socket *psock);
/****************************************************************************
* Name: inet_txdrain
*
* Description:
* Wait for any buffered Tx data to be sent from the socket.
*
* Parameters:
* psock - Pointer to the socket structure instance
* timeout - The relative time when the timeout will occur
*
* Returned Value:
* Zero (OK) is returned on success; a negated error value is returned on
* any failure.
*
****************************************************************************/
int inet_txdrain(FAR struct socket *psock, unsigned int timeout);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __NET_INET_INET_H */
@@ -0,0 +1,125 @@
/****************************************************************************
* net/inet/inet_globals.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>
#include <arpa/inet.h>
#include <nuttx/net/ip.h>
#ifdef CONFIG_NET_ETHERNET
# include <net/ethernet.h>
#endif
#include "inet/inet.h"
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef CONFIG_NET_IPv4
/* Increasing number used for the IP ID field. */
uint16_t g_ipid;
#endif /* CONFIG_NET_IPv4 */
#ifdef CONFIG_NET_IPv6
/* Unspecified address (all zero). See RFC 4291 (replaces 3513) */
const net_ipv6addr_t g_ipv6_unspecaddr = /* An address of all zeroes */
{
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
};
/* IPv6 Multi-cast IP addresses. See RFC 2375 */
const net_ipv6addr_t g_ipv6_allnodes = /* All link local nodes */
{
HTONS(0xff02),
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
HTONS(0x0001)
};
#if defined(CONFIG_NET_ICMPv6_AUTOCONF) || defined(CONFIG_NET_ICMPv6_ROUTER) || \
defined(CONFIG_NET_MLD)
const net_ipv6addr_t g_ipv6_allrouters = /* All link local routers */
{
HTONS(0xff02),
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
HTONS(0x0002)
};
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
/* Link-Local Address: Link-local addresses have "1111 1110 10" for the
* first ten bits followed by 54 zeroes and then the 64 bit interface
* identifier (typically derived from the link layer MAC address).
*/
const net_ipv6addr_t g_ipv6_llnetmask = /* Netmask for local link address */
{
0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000
};
#endif /* CONFIG_NET_ICMPv6_AUTOCONF */
#ifdef CONFIG_NET_MLD
/* Version 2 Multicast Listener Reports are sent with an IP destination
* address of FF02:0:0:0:0:0:0:16 on which all MLDv2-capable multicast
* routers listen (RFC 3810)
*/
const net_ipv6addr_t g_ipv6_allmldv2routers = /* All MLDv2 link local routers */
{
HTONS(0xff02),
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
HTONS(0x0016)
};
#endif
#ifdef CONFIG_NET_ETHERNET
/* IPv6 Multi-cast Ethernet addresses. Formed from the 16-bit prefix:
*
* 0x33:0x33:xx:xx:xx:xx:
*
* and the last 32-bits of the IPv6 IP address
*/
const struct ether_addr g_ipv6_ethallnodes = /* All link local nodes */
{
{ 0x33, 0x33, 0x00, 0x00, 0x00, 0x01 }
};
const struct ether_addr g_ipv6_ethallrouters = /* All link local routers */
{
{ 0x33, 0x33, 0x00, 0x00, 0x00, 0x02 }
};
#endif /* CONFIG_NET_ETHERNET */
#endif /* CONFIG_NET_ICMPv6_AUTOCONF || CONFIG_NET_ICMPv6_ROUTER || CONFIG_NET_MLD */
#endif /* CONFIG_NET_IPv6 */
/****************************************************************************
* Public Functions
****************************************************************************/
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,93 @@
/****************************************************************************
* net/inet/inet_txdrain.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>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <nuttx/net/net.h>
#include "udp/udp.h"
#include "tcp/tcp.h"
#include "inet/inet.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: inet_txdrain
*
* Description:
* Wait for any buffered Tx data to be sent from the socket.
*
* Parameters:
* psock - Pointer to the socket structure instance
* timeout - The relative time when the timeout will occur
*
* Returned Value:
* Zero (OK) is returned on success; a negated error value is returned on
* any failure.
*
****************************************************************************/
int inet_txdrain(FAR struct socket *psock, unsigned int timeout)
{
int ret = OK;
DEBUGASSERT(psock != NULL);
/* Draining depends on the socket family */
switch (psock->s_type)
{
#if defined(NET_TCP_HAVE_STACK)
case SOCK_STREAM:
{
ret = tcp_txdrain(psock, timeout);
}
break;
#endif
#if defined(NET_UDP_HAVE_STACK)
case SOCK_DGRAM:
{
ret = udp_txdrain(psock, timeout);
}
break;
#endif
/* Other protocols do no support write buffering */
default:
break;
}
return ret;
}
@@ -0,0 +1,142 @@
/****************************************************************************
* net/inet/ipv4_getpeername.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>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <nuttx/net/net.h>
#include <nuttx/net/netdev.h>
#include "netdev/netdev.h"
#include "socket/socket.h"
#include "udp/udp.h"
#include "tcp/tcp.h"
#include "inet/inet.h"
#ifdef CONFIG_NET_IPv4
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: ipv4_getpeername
*
* Description:
* The ipv4_getpeername() function retrieves the locally-bound name of the
* specified PF_NET socket.
*
* Parameters:
* psock Point to the socket structure instance [in]
* addr sockaddr structure to receive data [out]
* addrlen Length of sockaddr structure [in/out]
*
* Returned Value:
* On success, 0 is returned, the 'addr' argument points to the address
* of the socket, and the 'addrlen' argument points to the length of the
* address. Otherwise, a negated errno value is returned. See
* getpeername() for the list of returned error values.
*
****************************************************************************/
int ipv4_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
FAR socklen_t *addrlen)
{
#if defined(NET_TCP_HAVE_STACK) || defined(NET_UDP_HAVE_STACK)
FAR struct sockaddr_in *outaddr = (FAR struct sockaddr_in *)addr;
in_addr_t ripaddr;
/* Check if enough space has been provided for the full address */
if (*addrlen < sizeof(struct sockaddr_in))
{
/* This function is supposed to return the partial address if
* a smaller buffer has been provided. This support has not
* been implemented.
*/
return -ENOSYS;
}
/* Verify that the socket has been connected */
if (_SS_ISCONNECTED(psock->s_flags) == 0)
{
return -ENOTCONN;
}
/* Set the port number */
switch (psock->s_type)
{
#ifdef NET_TCP_HAVE_STACK
case SOCK_STREAM:
{
FAR struct tcp_conn_s *tcp_conn =
(FAR struct tcp_conn_s *)psock->s_conn;
outaddr->sin_port = tcp_conn->rport; /* Already in network byte order */
ripaddr = tcp_conn->u.ipv4.raddr;
}
break;
#endif
#ifdef NET_UDP_HAVE_STACK
case SOCK_DGRAM:
{
FAR struct udp_conn_s *udp_conn =
(FAR struct udp_conn_s *)psock->s_conn;
outaddr->sin_port = udp_conn->rport; /* Already in network byte order */
ripaddr = udp_conn->u.ipv4.raddr;
}
break;
#endif
default:
return -EOPNOTSUPP;
}
/* Set the address family and the IP address */
outaddr->sin_family = psock->s_domain;
outaddr->sin_addr.s_addr = ripaddr;
memset(outaddr->sin_zero, 0, sizeof(outaddr->sin_zero));
*addrlen = sizeof(struct sockaddr_in);
/* Return success */
return OK;
#else
return -EOPNOTSUPP;
#endif
}
#endif /* CONFIG_NET_IPv4 */
@@ -0,0 +1,171 @@
/****************************************************************************
* net/inet/ipv4_getsockname.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>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <nuttx/net/net.h>
#include <nuttx/net/netdev.h>
#include "netdev/netdev.h"
#include "udp/udp.h"
#include "tcp/tcp.h"
#include "inet/inet.h"
#ifdef CONFIG_NET_IPv4
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: ipv4_getsockname
*
* Description:
* The ipv4_getsockname() function retrieves the locally-bound name of the
* specified PF_NET socket.
*
* Input Parameters:
* psock Point to the socket structure instance [in]
* addr sockaddr structure to receive data [out]
* addrlen Length of sockaddr structure [in/out]
*
* Returned Value:
* On success, 0 is returned, the 'addr' argument points to the address
* of the socket, and the 'addrlen' argument points to the length of the
* address. Otherwise, a negated errno value is returned. See
* getsockname() for the list of returned error values.
*
****************************************************************************/
int ipv4_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
FAR socklen_t *addrlen)
{
#if defined(NET_TCP_HAVE_STACK) || defined(NET_UDP_HAVE_STACK)
FAR struct sockaddr_in *outaddr = (FAR struct sockaddr_in *)addr;
FAR struct net_driver_s *dev;
in_addr_t lipaddr;
in_addr_t ripaddr;
/* Check if enough space has been provided for the full address */
if (*addrlen < sizeof(struct sockaddr_in))
{
/* This function is supposed to return the partial address if
* a smaller buffer has been provided. This support has not
* been implemented.
*/
return -ENOSYS;
}
/* Set the port number */
switch (psock->s_type)
{
#ifdef NET_TCP_HAVE_STACK
case SOCK_STREAM:
{
FAR struct tcp_conn_s *tcp_conn =
(FAR struct tcp_conn_s *)psock->s_conn;
outaddr->sin_port = tcp_conn->lport; /* Already in network byte order */
lipaddr = tcp_conn->u.ipv4.laddr;
ripaddr = tcp_conn->u.ipv4.raddr;
}
break;
#endif
#ifdef NET_UDP_HAVE_STACK
case SOCK_DGRAM:
{
FAR struct udp_conn_s *udp_conn =
(FAR struct udp_conn_s *)psock->s_conn;
outaddr->sin_port = udp_conn->lport; /* Already in network byte order */
lipaddr = udp_conn->u.ipv4.laddr;
ripaddr = udp_conn->u.ipv4.raddr;
}
break;
#endif
default:
return -EOPNOTSUPP;
}
if (lipaddr == 0)
{
outaddr->sin_family = psock->s_domain;
outaddr->sin_addr.s_addr = 0;
memset(outaddr->sin_zero, 0, sizeof(outaddr->sin_zero));
*addrlen = sizeof(struct sockaddr_in);
return OK;
}
net_lock();
/* Find the device matching the IPv4 address in the connection structure.
* NOTE: listening sockets have no ripaddr. Work around is to use the
* lipaddr when ripaddr is not available.
*/
if (ripaddr == 0)
{
ripaddr = lipaddr;
}
dev = netdev_findby_ripv4addr(lipaddr, ripaddr);
if (dev == NULL)
{
net_unlock();
return -EINVAL;
}
/* Set the address family and the IP address */
outaddr->sin_family = psock->s_domain;
outaddr->sin_addr.s_addr = dev->d_ipaddr;
memset(outaddr->sin_zero, 0, sizeof(outaddr->sin_zero));
*addrlen = sizeof(struct sockaddr_in);
net_unlock();
/* Return success */
return OK;
#else
return -EOPNOTSUPP;
#endif
}
#endif /* CONFIG_NET_IPv4 */
@@ -0,0 +1,244 @@
/****************************************************************************
* net/inet/ipv4_setsockopt.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>
#include <sys/types.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/net/net.h>
#include <netinet/in.h>
#include "netdev/netdev.h"
#include "igmp/igmp.h"
#include "inet/inet.h"
#include "udp/udp.h"
#ifdef CONFIG_NET_IPv4
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: ipv4_setsockopt
*
* Description:
* ipv4_setsockopt() sets the IPv4-protocol socket option specified by the
* 'option' argument to the value pointed to by the 'value' argument for
* the socket specified by the 'psock' argument.
*
* See <netinet/in.h> for the a complete list of values of IPv4 protocol
* socket options.
*
* Input Parameters:
* psock Socket structure of socket to operate on
* option identifies the option to set
* 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_setcockopt() for
* the list of possible error values.
*
****************************************************************************/
int ipv4_setsockopt(FAR struct socket *psock, int option,
FAR const void *value, socklen_t value_len)
{
#ifdef CONFIG_NET_IGMP
int ret;
ninfo("option: %d\n", option);
/* With IPv4, the multicast-related socket options are simply an
* alternative way to access IGMP. That IGMP functionality can also be
* accessed via IOCTL commands (see netdev/netdev_ioctl.c)
*
* REVISIT: Clone the logic from netdev_ioctl.c here.
*/
net_lock();
switch (option)
{
case IP_MSFILTER: /* Access advanced, full-state filtering API */
{
#if 0 /* REVISIT: This is not a proper implementation of IP_MSGFILTER */
FAR const struct ip_msfilter *imsf;
FAR struct net_driver_s *dev;
imsf = (FAR const struct ip_msfilter *)value;
if (imsf == NULL || value_len < sizeof(struct ip_msfilter))
{
nerr("ERROR: Bad value or value_len\n");
ret = -EINVAL;
}
else
{
/* Get the device associated with the local interface address */
dev = netdev_findby_lipv4addr(imsf->imsf_interface.s_addr);
if (dev == NULL)
{
nwarn("WARNING: Could not find device\n");
ret = -ENODEV;
}
else if (imsf->imsf_fmode == MCAST_INCLUDE)
{
ret = igmp_joingroup(dev, &imsf->imsf_multiaddr);
}
else
{
DEBUGASSERT(imsf->imsf_fmode == MCAST_EXCLUDE);
ret = igmp_leavegroup(dev, &imsf->imsf_multiaddr);
}
}
#else
ret = -ENOSYS;
#endif
}
break;
case IP_ADD_MEMBERSHIP: /* Join a multicast group */
case IP_DROP_MEMBERSHIP: /* Leave a multicast group */
{
FAR const struct ip_mreq *mrec;
FAR struct net_driver_s *dev;
/* REVISIT: This is not a proper implementation of IP_MSGFILTER */
mrec = (FAR const struct ip_mreq *)value;
if (mrec == NULL || value_len < sizeof(struct ip_mreq))
{
nerr("ERROR: Bad value or value_len\n");
ret = -EINVAL;
}
else
{
/* Use the default network device is imr_interface is
* INADDRY_ANY.
*/
if (mrec->imr_interface.s_addr == INADDR_ANY)
{
dev = netdev_default();
}
else
{
/* Get the device associated with the local interface
* address
*/
dev = netdev_findby_lipv4addr(mrec->imr_interface.s_addr);
}
if (dev == NULL)
{
nwarn("WARNING: Could not find device\n");
ret = -ENODEV;
}
else if (option == IP_ADD_MEMBERSHIP)
{
ret = igmp_joingroup(dev, &mrec->imr_multiaddr);
}
else
{
ret = igmp_leavegroup(dev, &mrec->imr_multiaddr);
}
}
}
break;
case IP_MULTICAST_TTL: /* Set/read the time-to-live value of
* outgoing multicast packets */
{
FAR struct udp_conn_s *conn;
int ttl;
if (psock->s_type != SOCK_DGRAM ||
value == NULL || value_len == 0)
{
ret = -EINVAL;
break;
}
ttl = (value_len >= sizeof(int)) ?
*(FAR int *)value : (int)*(FAR unsigned char *)value;
if (ttl <= 0 || ttl > 255)
{
ret = -EINVAL;
}
else
{
conn = (FAR struct udp_conn_s *)psock->s_conn;
conn->ttl = ttl;
ret = OK;
}
}
break;
/* The following IPv4 socket options are defined, but not implemented */
case IP_MULTICAST_IF: /* Set local device for a multicast
* socket */
case IP_MULTICAST_LOOP: /* Set/read boolean that determines
* whether sent multicast packets
* should be looped back to local
* sockets. */
case IP_UNBLOCK_SOURCE: /* Unblock previously blocked multicast
* source */
case IP_BLOCK_SOURCE: /* Stop receiving multicast data from
* source */
case IP_ADD_SOURCE_MEMBERSHIP: /* Join a multicast group; allow receive
* only from source */
case IP_DROP_SOURCE_MEMBERSHIP: /* Leave a source-specific group. Stop
* receiving data from a given multicast
* group that come from a given source */
case IP_MULTICAST_ALL: /* Modify the delivery policy of
* multicast messages bound to
* INADDR_ANY */
#warning Missing logic
nwarn("WARNING: Unimplemented IPv4 option: %d\n", option);
ret = -ENOSYS;
break;
default:
nerr("ERROR: Unrecognized IPv4 option: %d\n", option);
ret = -ENOPROTOOPT;
break;
}
net_unlock();
return ret;
#else
return -ENOPROTOOPT;
#endif
}
#endif /* CONFIG_NET_IPv4 */
@@ -0,0 +1,137 @@
/****************************************************************************
* net/inet/ipv6_getpeername.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>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <nuttx/net/net.h>
#include <nuttx/net/netdev.h>
#include "netdev/netdev.h"
#include "socket/socket.h"
#include "udp/udp.h"
#include "tcp/tcp.h"
#include "inet/inet.h"
#ifdef CONFIG_NET_IPv6
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: ipv6_getpeername
*
* Description:
* The ipv6_getpeername() function retrieves the locally-bound name of the
* specified PF_NET6 socket.
*
* Parameters:
* psock Point to the socket structure instance [in]
* addr sockaddr structure to receive data [out]
* addrlen Length of sockaddr structure [in/out]
*
* Returned Value:
* On success, 0 is returned, the 'addr' argument points to the address
* of the socket, and the 'addrlen' argument points to the length of the
* address. Otherwise, a negated errno value is returned. See
* getpeername() for the list of returned error values.
*
****************************************************************************/
int ipv6_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
FAR socklen_t *addrlen)
{
FAR struct sockaddr_in6 *outaddr = (FAR struct sockaddr_in6 *)addr;
net_ipv6addr_t *ripaddr;
/* Check if enough space has been provided for the full address */
if (*addrlen < sizeof(struct sockaddr_in6))
{
/* This function is supposed to return the partial address if
* a smaller buffer has been provided. This support has not
* been implemented.
*/
return -ENOSYS;
}
/* Verify that the socket has been connected */
if (_SS_ISCONNECTED(psock->s_flags) == 0)
{
return -ENOTCONN;
}
/* Set the port number */
switch (psock->s_type)
{
#ifdef NET_TCP_HAVE_STACK
case SOCK_STREAM:
{
FAR struct tcp_conn_s *tcp_conn =
(FAR struct tcp_conn_s *)psock->s_conn;
outaddr->sin6_port = tcp_conn->lport; /* Already in network byte order */
ripaddr = &tcp_conn->u.ipv6.raddr;
}
break;
#endif
#ifdef NET_UDP_HAVE_STACK
case SOCK_DGRAM:
{
FAR struct udp_conn_s *udp_conn =
(FAR struct udp_conn_s *)psock->s_conn;
outaddr->sin6_port = udp_conn->lport; /* Already in network byte order */
ripaddr = &udp_conn->u.ipv6.raddr;
}
break;
#endif
default:
return -EOPNOTSUPP;
}
/* Set the address family and the IP address */
outaddr->sin6_family = AF_INET6;
memcpy(outaddr->sin6_addr.in6_u.u6_addr8, ripaddr, 16);
*addrlen = sizeof(struct sockaddr_in6);
/* Return success */
return OK;
}
#endif /* CONFIG_NET_IPv6 */
@@ -0,0 +1,165 @@
/****************************************************************************
* net/inet/ipv6_getsockname.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>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <nuttx/net/net.h>
#include <nuttx/net/netdev.h>
#include "netdev/netdev.h"
#include "udp/udp.h"
#include "tcp/tcp.h"
#include "inet/inet.h"
#ifdef CONFIG_NET_IPv6
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: ipv6_getsockname
*
* Description:
* The ipv6_getsockname() function retrieves the locally-bound name of the
* specified PF_NET6 socket.
*
* Input Parameters:
* psock Point to the socket structure instance [in]
* addr sockaddr structure to receive data [out]
* addrlen Length of sockaddr structure [in/out]
*
* Returned Value:
* On success, 0 is returned, the 'addr' argument points to the address
* of the socket, and the 'addrlen' argument points to the length of the
* address. Otherwise, a negated errno value is returned. See
* getsockname() for the list of returned error values.
*
****************************************************************************/
int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
FAR socklen_t *addrlen)
{
FAR struct sockaddr_in6 *outaddr = (FAR struct sockaddr_in6 *)addr;
FAR struct net_driver_s *dev;
net_ipv6addr_t *lipaddr;
net_ipv6addr_t *ripaddr;
/* Check if enough space has been provided for the full address */
if (*addrlen < sizeof(struct sockaddr_in6))
{
/* This function is supposed to return the partial address if
* a smaller buffer has been provided. This support has not
* been implemented.
*/
return -ENOSYS;
}
/* Set the port number */
switch (psock->s_type)
{
#ifdef NET_TCP_HAVE_STACK
case SOCK_STREAM:
{
FAR struct tcp_conn_s *tcp_conn =
(FAR struct tcp_conn_s *)psock->s_conn;
outaddr->sin6_port = tcp_conn->lport; /* Already in network byte order */
lipaddr = &tcp_conn->u.ipv6.laddr;
ripaddr = &tcp_conn->u.ipv6.raddr;
}
break;
#endif
#ifdef NET_UDP_HAVE_STACK
case SOCK_DGRAM:
{
FAR struct udp_conn_s *udp_conn =
(FAR struct udp_conn_s *)psock->s_conn;
outaddr->sin6_port = udp_conn->lport; /* Already in network byte order */
lipaddr = &udp_conn->u.ipv6.laddr;
ripaddr = &udp_conn->u.ipv6.raddr;
}
break;
#endif
default:
return -EOPNOTSUPP;
}
/* Check if bound to the IPv6 unspecified address */
if (net_ipv6addr_cmp(lipaddr, g_ipv6_unspecaddr))
{
outaddr->sin6_family = AF_INET6;
memcpy(outaddr->sin6_addr.in6_u.u6_addr8, g_ipv6_unspecaddr, 16);
*addrlen = sizeof(struct sockaddr_in6);
return OK;
}
net_lock();
/* Find the device matching the IPv6 address in the connection structure.
* NOTE: listening sockets have no ripaddr. Work around is to use the
* lipaddr when ripaddr is not available.
*/
if (net_ipv6addr_cmp(ripaddr, g_ipv6_unspecaddr))
{
ripaddr = lipaddr;
}
dev = netdev_findby_ripv6addr(*lipaddr, *ripaddr);
if (!dev)
{
net_unlock();
return -EINVAL;
}
/* Set the address family and the IP address */
outaddr->sin6_family = AF_INET6;
memcpy(outaddr->sin6_addr.in6_u.u6_addr8, dev->d_ipv6addr, 16);
*addrlen = sizeof(struct sockaddr_in6);
net_unlock();
/* Return success */
return OK;
}
#endif /* CONFIG_NET_IPv6 */
@@ -0,0 +1,140 @@
/****************************************************************************
* net/inet/ipv6_setsockopt.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>
#include <sys/types.h>
#include <errno.h>
#include <debug.h>
#include <netinet/in.h>
#include <nuttx/net/net.h>
#include "mld/mld.h"
#include "inet/inet.h"
#ifdef CONFIG_NET_IPv6
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: ipv6_setsockopt
*
* Description:
* ipv6_setsockopt() sets the IPv6-protocol socket option specified by the
* 'option' argument to the value pointed to by the 'value' argument for
* the socket specified by the 'psock' argument.
*
* See <netinet/in.h> for the a complete list of values of IPv6 protocol
* socket options.
*
* Input Parameters:
* psock Socket structure of socket to operate on
* option identifies the option to set
* 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_setcockopt() for
* the list of possible error values.
*
****************************************************************************/
int ipv6_setsockopt(FAR struct socket *psock, int option,
FAR const void *value, socklen_t value_len)
{
#ifdef CONFIG_NET_MLD
int ret;
ninfo("option: %d\n", option);
/* Handle MLD-related socket options */
net_lock();
switch (option)
{
case IPV6_JOIN_GROUP: /* Join a multicast group */
{
FAR const struct ipv6_mreq *mrec ;
mrec = (FAR const struct ipv6_mreq *)value;
if (mrec == NULL)
{
ret = -EINVAL;
}
else
{
ret = mld_joingroup(mrec);
}
}
break;
case IPV6_LEAVE_GROUP: /* Quit a multicast group */
{
FAR const struct ipv6_mreq *mrec ;
mrec = (FAR const struct ipv6_mreq *)value;
if (mrec == NULL)
{
ret = -EINVAL;
}
else
{
ret = mld_leavegroup(mrec);
}
}
break;
/* The following IPv6 socket options are defined, but not implemented */
case IPV6_MULTICAST_HOPS: /* Multicast hop limit */
case IPV6_MULTICAST_IF: /* Interface to use for outgoing multicast
* packets */
case IPV6_MULTICAST_LOOP: /* Multicast packets are delivered back to
* the local application */
case IPV6_UNICAST_HOPS: /* Unicast hop limit */
case IPV6_V6ONLY: /* Restrict AF_INET6 socket to IPv6
* communications only */
nwarn("WARNING: Unimplemented IPv6 option: %d\n", option);
ret = -ENOSYS;
break;
default:
nerr("ERROR: Unrecognized IPv6 option: %d\n", option);
ret = -ENOPROTOOPT;
break;
}
net_unlock();
return ret;
#else
return -ENOPROTOOPT;
#endif
}
#endif /* CONFIG_NET_IPv6 */