📄 net_sock.c
字号:
/*
*********************************************************************************************************
* uC/TCP-IP
* The Embedded TCP/IP Suite
*
* (c) Copyright 2003-2007; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/TCP-IP is provided in source form for FREE evaluation, for educational
* use or peaceful research. If you plan on using uC/TCP-IP in a commercial
* product you need to contact Micrium to properly license its use in your
* product. We provide ALL the source code for your convenience and to help
* you experience uC/TCP-IP. The fact that the source code is provided does
* NOT mean that you can use it without paying a licensing fee.
*
* Knowledge of the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* NETWORK SOCKET LAYER
*
* Filename : net_sock.c
* Version : V1.89
* Programmer(s) : ITJ
*********************************************************************************************************
* Note(s) : (1) Supports BSD 4.x Socket Layer with the following restrictions/constraints :
*
* (a) ONLY supports a single address family from the following families :
* (1) IPv4 (AF_INET)
*
* (b) ONLY supports the following socket types :
* (1) Datagram (SOCK_DGRAM)
* (2) Stream (SOCK_STREAM)
*
* (c) ONLY supports a single protocol family from the following families :
* (1) IPv4 (PF_INET)
* (A) ONLY supports the following protocols :
* (1) UDP (IPPROTO_UDP)
* (2) TCP (IPPROTO_TCP)
*
* (d) ONLY supports the following socket options :
* (1) Global options
* #### ( )
* (2) Socket options
* #### ( )
*
*********************************************************************************************************
* Notice(s) : (1) The Institute of Electrical and Electronics Engineers and The Open Group, have given
* us permission to reprint portions of their documentation. Portions of this text are
* reprinted and reproduced in electronic form from the IEEE Std 1003.1, 2004 Edition,
* Standard for Information Technology -- Portable Operating System Interface (POSIX),
* The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute
* of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any
* discrepancy between these versions and the original IEEE and The Open Group Standard,
* the original IEEE and The Open Group Standard is the referee document. The original
* Standard can be obtained online at http://www.opengroup.org/unix/online.html.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#define NET_SOCK_MODULE
#include <net.h>
/*
*********************************************************************************************************
* MODULE
*
* Note(s) : (1) See 'net_sock.h MODULE'.
*********************************************************************************************************
*/
#ifdef NET_SOCK_MODULE_PRESENT
/*$PAGE*/
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
/* ----------- RX FNCTS ----------- */
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
static void NetSock_RxPktValidateBuf (NET_BUF_HDR *pbuf_hdr,
NET_ERR *perr);
#endif
static void NetSock_RxPktDemux (NET_BUF *pbuf,
NET_BUF_HDR *pbuf_hdr,
NET_ERR *perr);
static void NetSock_RxPktDiscard (NET_BUF *pbuf,
NET_ERR *perr);
/* ------ SOCK STATUS FNCTS ------- */
#if (NET_ERR_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)
static CPU_BOOLEAN NetSock_IsValidAddrLocal (NET_SOCK_ADDR *paddr,
NET_SOCK_ADDR_LEN addr_len,
NET_ERR *perr);
static CPU_BOOLEAN NetSock_IsValidAddrRemote (NET_SOCK_ADDR *paddr,
NET_SOCK_ADDR_LEN addr_len,
NET_SOCK *psock,
NET_ERR *perr);
#endif
/* ------ SOCK HANDLER FNCTS ------ */
#if (NET_SOCK_CFG_TYPE_STREAM_EN == DEF_ENABLED)
static NET_SOCK_RTN_CODE NetSock_CloseHandlerStream (NET_SOCK_ID sock_id,
NET_SOCK *psock,
NET_ERR *perr);
#endif
static NET_SOCK_RTN_CODE NetSock_BindHandler (NET_SOCK_ID sock_id,
NET_SOCK_ADDR *paddr_local,
NET_SOCK_ADDR_LEN addr_len,
CPU_BOOLEAN addr_random_reqd,
NET_ERR *perr);
static NET_SOCK_RTN_CODE NetSock_ConnHandlerDatagram (NET_SOCK_ID sock_id,
NET_SOCK *psock,
NET_SOCK_ADDR *paddr_remote,
NET_ERR *perr);
#if (NET_SOCK_CFG_TYPE_STREAM_EN == DEF_ENABLED)
static NET_SOCK_RTN_CODE NetSock_ConnHandlerStream (NET_SOCK_ID sock_id,
NET_SOCK *psock,
NET_SOCK_ADDR *paddr_remote,
NET_ERR *perr);
#endif
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
static void NetSock_ConnHandlerAddrRemoteValidate(NET_SOCK *psock,
NET_SOCK_ADDR *paddr_remote,
NET_ERR *perr);
#endif
static void NetSock_ConnHandlerAddrRemoteSet (NET_SOCK *psock,
NET_SOCK_ADDR *paddr_remote,
CPU_BOOLEAN addr_over_wr,
NET_ERR *perr);
/*$PAGE*/
#if (NET_SOCK_CFG_TYPE_STREAM_EN == DEF_ENABLED)
static void NetSock_ConnAcceptQ_Init (NET_SOCK *psock,
NET_SOCK_Q_SIZE sock_q_size);
static void NetSock_ConnAcceptQ_Clr (NET_SOCK *psock);
static CPU_BOOLEAN NetSock_ConnAcceptQ_IsAvail (NET_SOCK *psock,
NET_ERR *perr);
static void NetSock_ConnAcceptQ_ConnID_Add (NET_SOCK *psock,
NET_CONN_ID conn_id,
NET_ERR *perr);
static NET_CONN_ID NetSock_ConnAcceptQ_ConnID_Get (NET_SOCK *psock,
NET_ERR *perr);
static CPU_BOOLEAN NetSock_ConnAcceptQ_ConnID_Srch (NET_SOCK *psock,
NET_CONN_ID conn_id,
NET_SOCK_Q_SIZE *pconn_ix,
NET_SOCK_Q_SIZE *pconn_nbr);
static CPU_BOOLEAN NetSock_ConnAcceptQ_ConnID_Remove (NET_SOCK *psock,
NET_CONN_ID conn_id);
#endif
static NET_SOCK_RTN_CODE NetSock_RxDataHandler (NET_SOCK_ID sock_id,
void *pdata_buf,
CPU_INT16S data_buf_len,
CPU_INT16S flags,
NET_SOCK_ADDR *paddr_remote,
NET_SOCK_ADDR_LEN *paddr_len,
void *pip_opts_buf,
CPU_INT08U ip_opts_buf_len,
CPU_INT08U *pip_opts_len,
NET_ERR *perr);
static NET_SOCK_RTN_CODE NetSock_RxDataHandlerDatagram (NET_SOCK_ID sock_id,
NET_SOCK *psock,
void *pdata_buf,
CPU_INT16S data_buf_len,
CPU_INT16S flags,
NET_SOCK_ADDR *paddr_remote,
NET_SOCK_ADDR_LEN *paddr_len,
void *pip_opts_buf,
CPU_INT08U ip_opts_buf_len,
CPU_INT08U *pip_opts_len,
NET_ERR *perr);
#if (NET_SOCK_CFG_TYPE_STREAM_EN == DEF_ENABLED)
static NET_SOCK_RTN_CODE NetSock_RxDataHandlerStream (NET_SOCK_ID sock_id,
NET_SOCK *psock,
void *pdata_buf,
CPU_INT16S data_buf_len,
CPU_INT16S flags,
NET_SOCK_ADDR *paddr_remote,
NET_SOCK_ADDR_LEN *paddr_len,
NET_ERR *perr);
#endif
static NET_SOCK_RTN_CODE NetSock_TxDataHandler (NET_SOCK_ID sock_id,
void *p_data,
CPU_INT16S data_len,
CPU_INT16S flags,
NET_SOCK_ADDR *paddr_remote,
NET_SOCK_ADDR_LEN addr_len,
NET_ERR *perr);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -