Free (GPLv2) TCP/IP stack developed by TASS Belgium
Dependents: lpc1768-picotcp-demo ZeroMQ_PicoTCP_Publisher_demo TCPSocket_HelloWorld_PicoTCP Pico_TCP_UDP_Test ... more
UDPSocket.h
00001 /* 00002 * 00003 * PicoTCP Socket interface for mbed. 00004 * Copyright (C) 2013 TASS Belgium NV 00005 * 00006 * Released under GPL v2 00007 * 00008 * Other licensing models might apply at the sole discretion of the copyright holders. 00009 * 00010 * 00011 * This software is based on the mbed.org EthernetInterface implementation: 00012 * Copyright (C) 2012 mbed.org, MIT License 00013 * 00014 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00015 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00016 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00017 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00018 * furnished to do so, subject to the following conditions: 00019 * 00020 * The above copyright notice and this permission notice shall be included in all copies or 00021 * substantial portions of the Software. 00022 * 00023 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00024 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00025 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00026 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00027 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00028 */ 00029 00030 #ifndef UDPSOCKET_H 00031 #define UDPSOCKET_H 00032 00033 #include "Socket/Socket.h" 00034 #include "Socket/Endpoint.h" 00035 #include "EthernetInterface.h" 00036 #include <cstdint> 00037 00038 /** 00039 UDP Socket 00040 */ 00041 class UDPSocket : public Socket { 00042 00043 public: 00044 /** Instantiate an UDP Socket. 00045 */ 00046 UDPSocket(); 00047 00048 /** Init the UDP Client Socket without binding it to any specific port 00049 \return 0 on success, -1 on failure. 00050 */ 00051 int init(void); 00052 00053 /** Bind a UDP Server Socket to a specific port 00054 \param port The port to listen for incoming connections on 00055 \return 0 on success, -1 on failure. 00056 */ 00057 int bind(int port); 00058 00059 /** Join the multicast group at the given address 00060 \param address The address of the multicast group 00061 \return 0 on success, -1 on failure. 00062 */ 00063 int join_multicast_group(EthernetInterface& eth, const char* address); 00064 00065 /** Set the socket in broadcasting mode 00066 \return 0 on success, -1 on failure. 00067 */ 00068 int set_broadcasting(void); 00069 00070 /** Send a packet to a remote endpoint 00071 \param remote The remote endpoint 00072 \param packet The packet to be sent 00073 \param length The length of the packet to be sent 00074 \return the number of written bytes on success (>=0) or -1 on failure 00075 */ 00076 int sendTo(Endpoint &remote, char *packet, int length); 00077 00078 /** Receive a packet from a remote endpoint 00079 \param remote The remote endpoint 00080 \param buffer The buffer for storing the incoming packet data. If a packet 00081 is too long to fit in the supplied buffer, excess bytes are discarded 00082 \param length The length of the buffer 00083 \return the number of received bytes on success (>=0) or -1 on failure 00084 */ 00085 int receiveFrom(Endpoint &remote, char *buffer, int length); 00086 }; 00087 00088 #endif
Generated on Tue Jul 12 2022 15:59:22 by 1.7.2