2007-09-01 20:06:15 +02:00
|
|
|
/****************************************************************************
|
2014-06-29 01:25:18 +02:00
|
|
|
* net/socket/socket.h
|
2007-09-01 20:06:15 +02:00
|
|
|
*
|
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
|
2007-09-01 20:06:15 +02:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-09-01 20:06:15 +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.
|
2007-09-01 20:06:15 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-01-15 03:44:35 +01:00
|
|
|
#ifndef __NET_SOCKET_SOCKET_H
|
|
|
|
#define __NET_SOCKET_SOCKET_H
|
2007-09-01 20:06:15 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#ifdef CONFIG_NET
|
|
|
|
|
2009-12-15 16:57:25 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdint.h>
|
2007-09-09 13:58:50 +02:00
|
|
|
#include <time.h>
|
2009-12-15 16:57:25 +01:00
|
|
|
|
2016-01-21 18:54:26 +01:00
|
|
|
#include <nuttx/clock.h>
|
2012-03-04 00:18:34 +01:00
|
|
|
#include <nuttx/net/net.h>
|
2007-09-01 20:06:15 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2014-05-30 20:32:20 +02:00
|
|
|
* Pre-processor Definitions
|
2007-09-01 20:06:15 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
/* This macro converts a socket option value into a bit setting */
|
2007-09-07 02:10:10 +02:00
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
#define _SO_BIT(o) (1 << (o))
|
2007-09-07 02:10:10 +02:00
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
/* These define bit positions for each socket option (see sys/socket.h) */
|
2007-09-07 02:10:10 +02:00
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
#define _SO_ACCEPTCONN _SO_BIT(SO_ACCEPTCONN)
|
|
|
|
#define _SO_BROADCAST _SO_BIT(SO_BROADCAST)
|
2017-11-12 15:17:46 +01:00
|
|
|
#define _SO_DEBUG _SO_BIT(SO_DEBUG)
|
|
|
|
#define _SO_DONTROUTE _SO_BIT(SO_DONTROUTE)
|
|
|
|
#define _SO_ERROR _SO_BIT(SO_ERROR)
|
2007-09-08 21:50:59 +02:00
|
|
|
#define _SO_KEEPALIVE _SO_BIT(SO_KEEPALIVE)
|
|
|
|
#define _SO_LINGER _SO_BIT(SO_LINGER)
|
|
|
|
#define _SO_OOBINLINE _SO_BIT(SO_OOBINLINE)
|
|
|
|
#define _SO_RCVBUF _SO_BIT(SO_RCVBUF)
|
|
|
|
#define _SO_RCVLOWAT _SO_BIT(SO_RCVLOWAT)
|
|
|
|
#define _SO_RCVTIMEO _SO_BIT(SO_RCVTIMEO)
|
2017-11-12 15:17:46 +01:00
|
|
|
#define _SO_REUSEADDR _SO_BIT(SO_REUSEADDR)
|
|
|
|
#define _SO_SNDBUF _SO_BIT(SO_SNDBUF)
|
2007-09-08 21:50:59 +02:00
|
|
|
#define _SO_SNDLOWAT _SO_BIT(SO_SNDLOWAT)
|
|
|
|
#define _SO_SNDTIMEO _SO_BIT(SO_SNDTIMEO)
|
2017-11-12 15:17:46 +01:00
|
|
|
#define _SO_TYPE _SO_BIT(SO_TYPE)
|
2022-08-24 04:30:01 +02:00
|
|
|
#define _SO_TIMESTAMP _SO_BIT(SO_TIMESTAMP)
|
|
|
|
#define _SO_BINDTODEVICE _SO_BIT(SO_BINDTODEVICE)
|
2007-09-08 21:50:59 +02:00
|
|
|
|
2017-11-12 15:17:46 +01:00
|
|
|
/* This is the largest option value. REVISIT: belongs in sys/socket.h */
|
2007-09-08 21:50:59 +02:00
|
|
|
|
2022-08-24 04:30:01 +02:00
|
|
|
#define _SO_MAXOPT (18)
|
2007-09-08 21:50:59 +02:00
|
|
|
|
|
|
|
/* Macros to set, test, clear options */
|
|
|
|
|
|
|
|
#define _SO_SETOPT(s,o) ((s) |= _SO_BIT(o))
|
|
|
|
#define _SO_CLROPT(s,o) ((s) &= ~_SO_BIT(o))
|
|
|
|
#define _SO_GETOPT(s,o) (((s) & _SO_BIT(o)) != 0)
|
|
|
|
|
|
|
|
/* These are macros that can be used to determine if socket option code is
|
|
|
|
* valid (in range) and supported by API.
|
2007-09-07 02:10:10 +02:00
|
|
|
*/
|
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
#define _SO_GETONLYSET (_SO_ACCEPTCONN|_SO_ERROR|_SO_TYPE)
|
|
|
|
#define _SO_GETONLY(o) ((_SO_BIT(o) & _SO_GETONLYSET) != 0)
|
|
|
|
#define _SO_GETVALID(o) (((unsigned int)(o)) <= _SO_MAXOPT)
|
|
|
|
#define _SO_SETVALID(o) ((((unsigned int)(o)) <= _SO_MAXOPT) && !_SO_GETONLY(o))
|
2007-09-07 02:10:10 +02:00
|
|
|
|
2020-01-04 11:37:46 +01:00
|
|
|
/* Macros to convert timeout value */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_SOCKOPTS
|
2020-01-31 19:09:01 +01:00
|
|
|
# define _SO_TIMEOUT(t) ((t) ? (t) * MSEC_PER_DSEC : UINT_MAX)
|
2020-01-04 11:37:46 +01:00
|
|
|
#else
|
2020-01-31 19:09:01 +01:00
|
|
|
# define _SO_TIMEOUT(t) (UINT_MAX)
|
2020-01-04 11:37:46 +01:00
|
|
|
#endif /* CONFIG_NET_SOCKOPTS */
|
|
|
|
|
2019-12-24 15:09:55 +01:00
|
|
|
/* Macro to set socket errors */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_SOCKOPTS
|
|
|
|
# define _SO_SETERRNO(s,e) \
|
|
|
|
do \
|
|
|
|
{ \
|
2022-02-08 04:04:52 +01:00
|
|
|
if (s != NULL && (s)->s_conn != NULL) \
|
2019-12-24 15:09:55 +01:00
|
|
|
{ \
|
2022-02-08 04:04:52 +01:00
|
|
|
FAR struct socket_conn_s *_conn = (s)->s_conn; \
|
|
|
|
_conn->s_error = (int16_t)e; \
|
2019-12-24 15:09:55 +01:00
|
|
|
} \
|
|
|
|
set_errno(e); \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
#else
|
|
|
|
# define _SO_SETERRNO(s,e) set_errno(e)
|
|
|
|
#endif /* CONFIG_NET_SOCKOPTS */
|
|
|
|
|
2007-09-01 20:06:15 +02:00
|
|
|
/****************************************************************************
|
2015-10-03 00:30:35 +02:00
|
|
|
* Public Data
|
2007-09-01 20:06:15 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2013-01-20 18:21:42 +01:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2007-09-01 20:06:15 +02:00
|
|
|
/****************************************************************************
|
2008-08-02 19:22:22 +02:00
|
|
|
* Public Function Prototypes
|
2007-09-01 20:06:15 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-07-12 23:07:32 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* 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
|
|
|
|
2015-05-28 15:26:03 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: net_timeo
|
2015-05-28 15:26:03 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check if a timeout has elapsed. This can be called from a socket poll
|
|
|
|
* function to determine if a timeout has occurred.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2015-05-28 15:26:03 +02:00
|
|
|
* start_time Timeout start time in system clock ticks
|
|
|
|
* timeout Timeout value in deciseconds.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 (FALSE) if not timeout; 1 (TRUE) if timeout
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2007-09-08 21:50:59 +02:00
|
|
|
|
2014-08-07 20:35:24 +02:00
|
|
|
#ifdef CONFIG_NET_SOCKOPTS
|
2018-06-16 20:16:13 +02:00
|
|
|
int net_timeo(clock_t start_time, socktimeo_t timeo);
|
2007-09-08 21:50:59 +02:00
|
|
|
#endif
|
|
|
|
|
2021-02-23 11:04:13 +01:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-09-01 20:06:15 +02:00
|
|
|
#endif /* CONFIG_NET */
|
2022-01-15 03:44:35 +01:00
|
|
|
#endif /* __NET_SOCKET_SOCKET_H */
|