📄 net_udp.c
字号:
/*
*********************************************************************************************************
* uC/TCP-IP
* The Embedded TCP/IP Suite
*
* (c) Copyright 2003-2006; 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 UDP LAYER
* (USER DATAGRAM PROTOCOL)
*
* Filename : net_udp.c
* Version : V1.87
* Programmer(s) : ITJ
*********************************************************************************************************
* Note(s) : (1) Supports User Datagram Protocol as described in RFC #768.
*
*********************************************************************************************************
* 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_UDP_MODULE
#include <net.h>
/*$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 NetUDP_RxPktValidateBuf (NET_BUF_HDR *pbuf_hdr,
NET_ERR *perr);
#endif
static void NetUDP_RxPktValidate (NET_BUF *pbuf,
NET_BUF_HDR *pbuf_hdr,
NET_UDP_HDR *pudp_hdr,
NET_ERR *perr);
static void NetUDP_RxPktDemuxDatagram(NET_BUF *pbuf,
NET_ERR *perr);
#if ((NET_UDP_CFG_APP_API_SEL == NET_UDP_APP_API_SEL_APP ) || \
(NET_UDP_CFG_APP_API_SEL == NET_UDP_APP_API_SEL_SOCK_APP))
static void NetUDP_RxPktDemuxAppData (NET_BUF *pbuf,
NET_ERR *perr);
#endif
static void NetUDP_RxPktFree (NET_BUF *pbuf);
static void NetUDP_RxPktDiscard (NET_BUF *pbuf,
NET_ERR *perr);
/* --------------- TX FNCTS --------------- */
static void NetUDP_Tx (NET_BUF *pbuf,
NET_IP_ADDR src_addr,
NET_UDP_PORT_NBR src_port,
NET_IP_ADDR dest_addr,
NET_UDP_PORT_NBR dest_port,
NET_IP_TOS TOS,
NET_IP_TTL TTL,
CPU_INT16U flags_udp,
CPU_INT16U flags_ip,
void *popts_ip,
NET_ERR *perr);
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
static void NetUDP_TxPktValidate (NET_BUF *pbuf,
NET_BUF_HDR *pbuf_hdr,
NET_UDP_PORT_NBR src_port,
NET_UDP_PORT_NBR dest_port,
CPU_INT16U flags_udp,
NET_ERR *perr);
#endif
static void NetUDP_TxPktPrepareHdr (NET_BUF *pbuf,
NET_BUF_HDR *pbuf_hdr,
NET_IP_ADDR src_addr,
NET_UDP_PORT_NBR src_port,
NET_IP_ADDR dest_addr,
NET_UDP_PORT_NBR dest_port,
CPU_INT16U flags_udp,
NET_ERR *perr);
static void NetUDP_TxPktFree (NET_BUF *pbuf);
static void NetUDP_TxPktDiscard (NET_BUF *pbuf);
/*
*********************************************************************************************************
* LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* NetUDP_Init()
*
* Description : (1) Initialize User Datagram Protocol Layer :
*
* (a) Initialize UDP statistics & error counters
*
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Net_Init().
*
* This function is an INTERNAL network protocol suite function & MUST NOT be called by
* application function(s).
*
* Note(s) : none.
*********************************************************************************************************
*/
void NetUDP_Init (void)
{
/* ------------- INIT UDP STAT & ERR CTRS ------------- */
#if (NET_CTR_CFG_STAT_EN == DEF_ENABLED)
NetUDP_StatRxPktCtr = 0;
NetUDP_StatRxDatagramProcessedCtr = 0;
NetUDP_StatTxDatagramCtr = 0;
#endif
#if (NET_CTR_CFG_ERR_EN == DEF_ENABLED)
NetUDP_ErrNullPtrCtr = 0;
NetUDP_ErrInvalidFlagsCtr = 0;
NetUDP_ErrRxHdrDatagramLenCtr = 0;
NetUDP_ErrRxHdrPortSrcCtr = 0;
NetUDP_ErrRxHdrPortDestCtr = 0;
NetUDP_ErrRxHdrChkSumCtr = 0;
NetUDP_ErrRxDestCtr = 0;
NetUDP_ErrRxPktDiscardedCtr = 0;
NetUDP_ErrTxPktDiscardedCtr = 0;
#if ((NET_ERR_CFG_ARG_CHK_EXT_EN == DEF_ENABLED) || \
(NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED))
NetUDP_ErrTxInvalidSizeCtr = 0;
#endif
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
NetUDP_ErrRxInvalidBufIxCtr = 0;
NetUDP_ErrRxHdrDataLenCtr = 0;
NetUDP_ErrTxProtocolCtr = 0;
NetUDP_ErrTxInvalidBufIxCtr = 0;
NetUDP_ErrTxHdrDataLenCtr = 0;
NetUDP_ErrTxHdrPortSrcCtr = 0;
NetUDP_ErrTxHdrPortDestCtr = 0;
NetUDP_ErrTxHdrFlagsCtr = 0;
#endif
#endif
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetUDP_Rx()
*
* Description : (1) Process received datagrams & forward to socket or application layer :
*
* (a) Validate UDP packet
* (b) Demultiplex datagram to socket/application connection
* (c) Update receive statistics
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -