Core networking libraries including LwIP implementation

Dependencies:   DebugLib Socket lwip lwip-sys

Dependents:   EthernetInterface

Fork of NetworkingCoreLib by Donatien Garnier

Committer:
donatien
Date:
Fri Jun 22 16:18:09 2012 +0000
Revision:
15:cf5f669a30bc
Parent:
13:f7d8c8088289
DebugLib up

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 1:240e3322b87a 1 /* IPInterface.cpp */
donatien 13:f7d8c8088289 2 /* Copyright (C) 2012 mbed.org, MIT License
donatien 13:f7d8c8088289 3 *
donatien 13:f7d8c8088289 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
donatien 13:f7d8c8088289 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
donatien 13:f7d8c8088289 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
donatien 13:f7d8c8088289 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
donatien 13:f7d8c8088289 8 * furnished to do so, subject to the following conditions:
donatien 13:f7d8c8088289 9 *
donatien 13:f7d8c8088289 10 * The above copyright notice and this permission notice shall be included in all copies or
donatien 13:f7d8c8088289 11 * substantial portions of the Software.
donatien 13:f7d8c8088289 12 *
donatien 13:f7d8c8088289 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
donatien 13:f7d8c8088289 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
donatien 13:f7d8c8088289 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
donatien 13:f7d8c8088289 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donatien 13:f7d8c8088289 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
donatien 13:f7d8c8088289 18 */
donatien 1:240e3322b87a 19
donatien 1:240e3322b87a 20 #include "core/fwk.h"
donatien 1:240e3322b87a 21
donatien 1:240e3322b87a 22 #include "IPInterface.h"
donatien 1:240e3322b87a 23
donatien 10:14ef6ceb4e75 24 #include <cstring> //For strcpy
donatien 10:14ef6ceb4e75 25
donatien 1:240e3322b87a 26
donatien 1:240e3322b87a 27 IPInterface::IPInterface()
donatien 1:240e3322b87a 28 {
donatien 1:240e3322b87a 29
donatien 1:240e3322b87a 30 }
donatien 1:240e3322b87a 31
donatien 1:240e3322b87a 32 /*virtual*/ IPInterface::~IPInterface()
donatien 1:240e3322b87a 33 {
donatien 1:240e3322b87a 34
donatien 1:240e3322b87a 35 }
donatien 1:240e3322b87a 36
donatien 1:240e3322b87a 37 void IPInterface::registerAsDefaultInterface() //First come, first served
donatien 1:240e3322b87a 38 {
donatien 1:240e3322b87a 39 s_pDefaultInterface = this;
donatien 1:240e3322b87a 40 }
donatien 1:240e3322b87a 41
donatien 1:240e3322b87a 42 void IPInterface::unregisterAsDefaultInterface() //Must be called before inst is destroyed to avoid invalid ptr fault
donatien 1:240e3322b87a 43 {
donatien 1:240e3322b87a 44 s_pDefaultInterface = NULL;
donatien 1:240e3322b87a 45 }
donatien 1:240e3322b87a 46
donatien 1:240e3322b87a 47 /*static*/ IPInterface* IPInterface::getDefaultInterface() //For use by TCP, UDP sockets library
donatien 1:240e3322b87a 48 {
donatien 1:240e3322b87a 49 return s_pDefaultInterface;
donatien 1:240e3322b87a 50 }
donatien 1:240e3322b87a 51
donatien 1:240e3322b87a 52 /*static*/ IPInterface* IPInterface::s_pDefaultInterface = NULL;
donatien 10:14ef6ceb4e75 53
donatien 10:14ef6ceb4e75 54
donatien 10:14ef6ceb4e75 55 char* IPInterface::getIPAddress() //Get IP Address as a string ('a.b.c.d')
donatien 10:14ef6ceb4e75 56 {
donatien 10:14ef6ceb4e75 57 if(isConnected())
donatien 10:14ef6ceb4e75 58 {
donatien 10:14ef6ceb4e75 59 return m_ipAddr;
donatien 10:14ef6ceb4e75 60 }
donatien 10:14ef6ceb4e75 61 else
donatien 10:14ef6ceb4e75 62 {
donatien 10:14ef6ceb4e75 63 return NULL;
donatien 10:14ef6ceb4e75 64 }
donatien 10:14ef6ceb4e75 65 }
donatien 10:14ef6ceb4e75 66
donatien 10:14ef6ceb4e75 67 bool IPInterface::isConnected() //Is the interface connected?
donatien 10:14ef6ceb4e75 68 {
donatien 10:14ef6ceb4e75 69 return m_connected;
donatien 10:14ef6ceb4e75 70 }
donatien 10:14ef6ceb4e75 71
donatien 10:14ef6ceb4e75 72 void IPInterface::setIPAddress(char* ipAddr)
donatien 10:14ef6ceb4e75 73 {
donatien 10:14ef6ceb4e75 74 std::strcpy(m_ipAddr, ipAddr); //Let's trust the derived class not to buffer overflow us
donatien 10:14ef6ceb4e75 75 }
donatien 10:14ef6ceb4e75 76
donatien 10:14ef6ceb4e75 77 void IPInterface::setConnected(bool connected)
donatien 10:14ef6ceb4e75 78 {
donatien 10:14ef6ceb4e75 79 m_connected = connected;
donatien 10:14ef6ceb4e75 80 }
donatien 10:14ef6ceb4e75 81