Clément BENOIT / Pyrn3GModem

Dependents:   PYRN

Committer:
clemounet
Date:
Fri Feb 20 17:15:55 2015 +0000
Revision:
1:fbf17fb09581
Add PPP networking

Who changed what in which revision?

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