Core networking libraries including LwIP implementation

Dependencies:   DebugLib Socket lwip lwip-sys

Dependents:   EthernetInterface

Fork of NetworkingCoreLib by Donatien Garnier

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers IPInterface.h Source File

IPInterface.h

00001 /* IPInterface.h */
00002 /* Copyright (C) 2012 mbed.org, MIT License
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00005  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00006  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00007  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00008  * furnished to do so, subject to the following conditions:
00009  *
00010  * The above copyright notice and this permission notice shall be included in all copies or
00011  * substantial portions of the Software.
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00014  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00015  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00016  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00017  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00018  */
00019 
00020 #ifndef IPINTERFACE_H_
00021 #define IPINTERFACE_H_
00022 
00023 #include "core/fwk.h"
00024 
00025 /** Generic IP-based network interface
00026  *
00027  */
00028 class IPInterface
00029 {
00030 public:
00031     IPInterface();
00032     virtual ~IPInterface();
00033 
00034     //int init(); //Initialize interface; no connection should be performed at this stage
00035     virtual int connect() = 0; //Do connect the interface
00036     virtual int disconnect() = 0;
00037     //It is encouraged that the derived class implement a "setup(...)" function to configure the interface before the connection
00038     
00039     char* getIPAddress(); //Get IP Address as a string ('a.b.c.d')
00040     bool isConnected(); //Is the interface connected?
00041 
00042     static IPInterface* getDefaultInterface(); //For use by TCP, UDP sockets library
00043 
00044     //WARN: Implementation will have to be more careful in case of multiple interfaces (or implement a routing protocol based on local IP addresses differentiation)
00045     void registerAsDefaultInterface(); //First come, first served
00046     void unregisterAsDefaultInterface(); //Must be called before inst is destroyed to avoid invalid ptr fault
00047 
00048 protected:
00049     //Must be called by subclasses
00050     void setIPAddress(char* ipAddr);
00051     void setConnected(bool connected);
00052 
00053 private:
00054     char m_ipAddr[16];
00055     bool m_connected;
00056 
00057     static IPInterface* s_pDefaultInterface;
00058 };
00059 
00060 #endif /* IPINTERFACE_H_ */