Darran Shepherd
/
AutoIpNetStack
Net stack with AutoIP enabled
Embed:
(wiki syntax)
Show/hide line numbers
lwipNetUdpSocket.h
00001 00002 /* 00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) 00004 00005 Permission is hereby granted, free of charge, to any person obtaining a copy 00006 of this software and associated documentation files (the "Software"), to deal 00007 in the Software without restriction, including without limitation the rights 00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 copies of the Software, and to permit persons to whom the Software is 00010 furnished to do so, subject to the following conditions: 00011 00012 The above copyright notice and this permission notice shall be included in 00013 all copies or substantial portions of the Software. 00014 00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 THE SOFTWARE. 00022 */ 00023 00024 #ifndef LWIPNETUDPSOCKET_H 00025 #define LWIPNETUDPSOCKET_H 00026 00027 #define NET_LWIP_STACK 1 00028 #include "lwip/ip_addr.h" 00029 #include "if/net/net.h" 00030 #include "LwipNetIf.h" 00031 00032 #include <list> 00033 using std::list; 00034 00035 //Implements NetUdpSockets over lwIP raw API 00036 00037 struct udp_pcb; //Represents a Udp Connection, "Protocol Control Block", see rawapi.txt & udp.h 00038 struct pbuf; //Lwip Buffer Container 00039 00040 typedef signed char err_t; 00041 00042 class LwipNetUdpSocket: public NetUdpSocket 00043 { 00044 public: 00045 LwipNetUdpSocket(udp_pcb* pPcb = NULL); //Passes a pcb if already created (by an accept req for instance), in that case transfers ownership 00046 virtual ~LwipNetUdpSocket(); 00047 00048 virtual NetUdpSocketErr bind(const Host& me); 00049 00050 virtual int /*if < 0 : NetUdpSocketErr*/ sendto(const char* buf, int len, Host* pHost); 00051 virtual int /*if < 0 : NetUdpSocketErr*/ recvfrom(char* buf, int len, Host* pHost); 00052 00053 virtual NetUdpSocketErr close(); 00054 00055 virtual NetUdpSocketErr poll(); 00056 00057 protected: 00058 volatile udp_pcb* m_pPcb; 00059 00060 //Event callback from lwIp 00061 void recvCb(udp_pcb* pcb, struct pbuf* p, ip_addr_t* addr, u16_t port); 00062 00063 private: 00064 void cleanUp(); //Flush input buffer 00065 struct InPacket 00066 { 00067 volatile pbuf* pBuf; 00068 ip_addr_t addr; 00069 u16_t port; 00070 }; 00071 00072 list<InPacket> m_lInPkt; 00073 00074 //Static callback : Transforms into a C++ callback 00075 static void sRecvCb(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t port); 00076 00077 }; 00078 00079 #endif
Generated on Tue Jul 12 2022 15:37:04 by 1.7.2