2017-07-12 23:07:32 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* net/socket/net_sockif.c
|
|
|
|
*
|
2024-09-11 14:39:39 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* 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
|
2017-07-12 23:07:32 +02:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-07-12 23:07:32 +02:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* 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.
|
2017-07-12 23:07:32 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/net/net.h>
|
|
|
|
|
2017-08-06 22:48:19 +02:00
|
|
|
#include "inet/inet.h"
|
2017-07-12 23:07:32 +02:00
|
|
|
#include "local/local.h"
|
2020-11-05 13:30:49 +01:00
|
|
|
#include "rpmsg/rpmsg.h"
|
2020-06-15 10:23:25 +02:00
|
|
|
#include "can/can.h"
|
2018-08-03 21:22:36 +02:00
|
|
|
#include "netlink/netlink.h"
|
2017-07-12 23:07:32 +02:00
|
|
|
#include "pkt/pkt.h"
|
2018-03-31 22:55:03 +02:00
|
|
|
#include "bluetooth/bluetooth.h"
|
2017-08-19 16:48:52 +02:00
|
|
|
#include "ieee802154/ieee802154.h"
|
2017-07-12 23:07:32 +02:00
|
|
|
#include "socket/socket.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: net_sockif
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the socket interface associated with this address family.
|
|
|
|
*
|
2017-10-23 16:45:12 +02:00
|
|
|
* Input Parameters:
|
|
|
|
* family - Socket address family
|
|
|
|
* type - Socket type
|
|
|
|
* protocol - Socket protocol
|
2017-07-12 23:07:32 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-10-23 16:45:12 +02:00
|
|
|
FAR const struct sock_intf_s *
|
2020-01-31 19:09:01 +01:00
|
|
|
net_sockif(sa_family_t family, int type, int protocol)
|
2017-07-12 23:07:32 +02:00
|
|
|
{
|
|
|
|
FAR const struct sock_intf_s *sockif = NULL;
|
|
|
|
|
2018-06-23 14:20:25 +02:00
|
|
|
/* Get the socket interface.
|
|
|
|
*
|
|
|
|
* REVISIT: Should also support PF_UNSPEC which would permit the socket
|
|
|
|
* to be used for anything.
|
|
|
|
*/
|
2017-07-12 23:07:32 +02:00
|
|
|
|
|
|
|
switch (family)
|
|
|
|
{
|
2017-07-14 23:24:18 +02:00
|
|
|
#ifdef HAVE_INET_SOCKETS
|
2022-11-23 14:44:11 +01:00
|
|
|
# ifdef HAVE_PFINET_SOCKETS
|
2017-07-12 23:07:32 +02:00
|
|
|
case PF_INET:
|
2022-11-23 14:44:11 +01:00
|
|
|
# endif
|
|
|
|
# ifdef HAVE_PFINET6_SOCKETS
|
2017-07-12 23:07:32 +02:00
|
|
|
case PF_INET6:
|
2022-11-23 14:44:11 +01:00
|
|
|
# endif
|
2017-10-23 16:45:12 +02:00
|
|
|
sockif = inet_sockif(family, type, protocol);
|
2017-07-12 23:07:32 +02:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_LOCAL
|
|
|
|
case PF_LOCAL:
|
|
|
|
sockif = &g_local_sockif;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2020-06-15 10:23:25 +02:00
|
|
|
#ifdef CONFIG_NET_CAN
|
|
|
|
case PF_CAN:
|
|
|
|
sockif = &g_can_sockif;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2018-08-03 21:22:36 +02:00
|
|
|
#ifdef CONFIG_NET_NETLINK
|
|
|
|
case PF_NETLINK:
|
|
|
|
sockif = &g_netlink_sockif;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2017-07-12 23:07:32 +02:00
|
|
|
#ifdef CONFIG_NET_PKT
|
|
|
|
case PF_PACKET:
|
|
|
|
sockif = &g_pkt_sockif;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
#ifdef CONFIG_NET_BLUETOOTH
|
|
|
|
case PF_BLUETOOTH:
|
|
|
|
sockif = &g_bluetooth_sockif;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2017-08-19 16:48:52 +02:00
|
|
|
#ifdef CONFIG_NET_IEEE802154
|
|
|
|
case PF_IEEE802154:
|
|
|
|
sockif = &g_ieee802154_sockif;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2020-11-05 13:30:49 +01:00
|
|
|
#ifdef CONFIG_NET_RPMSG
|
|
|
|
case PF_RPMSG:
|
|
|
|
sockif = &g_rpmsg_sockif;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2017-07-12 23:07:32 +02:00
|
|
|
default:
|
|
|
|
nerr("ERROR: Address family unsupported: %d\n", family);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sockif;
|
|
|
|
}
|