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.
IPInterface.cpp
00001 /* IPInterface.cpp */ 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 #include "core/fwk.h" 00021 00022 #include "IPInterface.h" 00023 00024 #include <cstring> //For strcpy 00025 00026 00027 IPInterface::IPInterface() : m_connected(false) 00028 { 00029 00030 } 00031 00032 /*virtual*/ IPInterface::~IPInterface() 00033 { 00034 00035 } 00036 00037 void IPInterface::registerAsDefaultInterface() //First come, first served 00038 { 00039 s_pDefaultInterface = this; 00040 } 00041 00042 void IPInterface::unregisterAsDefaultInterface() //Must be called before inst is destroyed to avoid invalid ptr fault 00043 { 00044 s_pDefaultInterface = NULL; 00045 } 00046 00047 /*static*/ IPInterface* IPInterface::getDefaultInterface() //For use by TCP, UDP sockets library 00048 { 00049 return s_pDefaultInterface; 00050 } 00051 00052 /*static*/ IPInterface* IPInterface::s_pDefaultInterface = NULL; 00053 00054 00055 char* IPInterface::getIPAddress() //Get IP Address as a string ('a.b.c.d') 00056 { 00057 if(isConnected()) 00058 { 00059 return m_ipAddr; 00060 } 00061 else 00062 { 00063 return NULL; 00064 } 00065 } 00066 00067 bool IPInterface::isConnected() //Is the interface connected? 00068 { 00069 return m_connected; 00070 } 00071 00072 void IPInterface::setIPAddress(char* ipAddr) 00073 { 00074 std::strcpy(m_ipAddr, ipAddr); //Let's trust the derived class not to buffer overflow us 00075 } 00076 00077 void IPInterface::setConnected(bool connected) 00078 { 00079 m_connected = connected; 00080 } 00081
Generated on Tue Jul 12 2022 17:34:44 by
1.7.2