Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
udp.h
00001 /** 00002 * @file udp.h 00003 * @brief UDP (User Datagram Protocol) 00004 * 00005 * @section License 00006 * 00007 * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. 00008 * 00009 * This file is part of CycloneTCP Open. 00010 * 00011 * This program is free software; you can redistribute it and/or 00012 * modify it under the terms of the GNU General Public License 00013 * as published by the Free Software Foundation; either version 2 00014 * of the License, or (at your option) any later version. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software Foundation, 00023 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00024 * 00025 * @author Oryx Embedded SARL (www.oryx-embedded.com) 00026 * @version 1.7.6 00027 **/ 00028 00029 #ifndef _UDP_H 00030 #define _UDP_H 00031 00032 //Dependencies 00033 #include "core/net.h" 00034 #include "core/tcp.h" 00035 00036 //UDP support 00037 #ifndef UDP_SUPPORT 00038 #define UDP_SUPPORT ENABLED 00039 #elif (UDP_SUPPORT != ENABLED && UDP_SUPPORT != DISABLED) 00040 #error UDP_SUPPORT parameter is not valid 00041 #endif 00042 00043 //Maximum number of callback functions that can be registered 00044 //to process incoming UDP datagrams 00045 #ifndef UDP_CALLBACK_TABLE_SIZE 00046 #define UDP_CALLBACK_TABLE_SIZE 10 00047 #elif (UDP_CALLBACK_TABLE_SIZE < 1) 00048 #error UDP_CALLBACK_TABLE_SIZE parameter is not valid 00049 #endif 00050 00051 //Receive queue depth for connectionless sockets 00052 #ifndef UDP_RX_QUEUE_SIZE 00053 #define UDP_RX_QUEUE_SIZE 4 00054 #elif (UDP_RX_QUEUE_SIZE < 1) 00055 #error UDP_RX_QUEUE_SIZE parameter is not valid 00056 #endif 00057 00058 00059 //CodeWarrior or Win32 compiler? 00060 #if defined(__CWCC__) || defined(_WIN32) 00061 #pragma pack(push, 1) 00062 #endif 00063 00064 00065 /** 00066 * @brief UDP header 00067 **/ 00068 00069 typedef __start_packed struct 00070 { 00071 uint16_t srcPort; //0-1 00072 uint16_t destPort; //2-3 00073 uint16_t length; //4-5 00074 uint16_t checksum; //6-7 00075 uint8_t data[]; //8 00076 } __end_packed UdpHeader; 00077 00078 00079 //CodeWarrior or Win32 compiler? 00080 #if defined(__CWCC__) || defined(_WIN32) 00081 #pragma pack(pop) 00082 #endif 00083 00084 00085 /** 00086 * @brief Data received callback 00087 **/ 00088 00089 typedef void (*UdpRxCallback)(NetInterface *interface, const IpPseudoHeader *pseudoHeader, 00090 const UdpHeader *header, const NetBuffer *buffer, size_t offset, void *params); 00091 00092 00093 /** 00094 * @brief Entry describing a user callback 00095 **/ 00096 00097 typedef struct 00098 { 00099 NetInterface *interface; 00100 uint16_t port; 00101 UdpRxCallback callback; 00102 void *params; 00103 } UdpRxCallbackDesc; 00104 00105 00106 //Global variables 00107 extern OsMutex udpCallbackMutex; 00108 extern UdpRxCallbackDesc udpCallbackTable[UDP_CALLBACK_TABLE_SIZE]; 00109 00110 //UDP related functions 00111 error_t udpInit(void); 00112 uint16_t udpGetDynamicPort(void); 00113 00114 error_t udpProcessDatagram(NetInterface *interface, 00115 IpPseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset); 00116 00117 error_t udpSendDatagram(Socket *socket, const IpAddr *destIpAddr, 00118 uint16_t destPort, const void *data, size_t length, size_t *written); 00119 00120 error_t udpSendDatagramEx(NetInterface *interface, uint16_t srcPort, const IpAddr *destIpAddr, 00121 uint16_t destPort, NetBuffer *buffer, size_t offset, uint8_t ttl); 00122 00123 error_t udpReceiveDatagram(Socket *socket, IpAddr *srcIpAddr, uint16_t *srcPort, 00124 IpAddr *destIpAddr, void *data, size_t size, size_t *received, uint_t flags); 00125 00126 NetBuffer *udpAllocBuffer(size_t length, size_t *offset); 00127 00128 void udpUpdateEvents(Socket *socket); 00129 00130 error_t udpAttachRxCallback(NetInterface *interface, 00131 uint16_t port, UdpRxCallback callback, void *params); 00132 00133 error_t udpDetachRxCallback(NetInterface *interface, uint16_t port); 00134 00135 error_t udpInvokeRxCallback(NetInterface *interface, const IpPseudoHeader *pseudoHeader, 00136 const UdpHeader *header, const NetBuffer *buffer, size_t offset); 00137 00138 void udpDumpHeader(const UdpHeader *datagram); 00139 00140 #endif 00141
Generated on Tue Jul 12 2022 17:10:17 by
