Fork of NetServicesMin with some warnings removed

Dependencies:   lwip-sys lwip

Fork of NetServicesMin by Hendrik Lipka

Committer:
uci1
Date:
Sat Nov 24 20:20:45 2012 +0000
Revision:
4:c8b2f969c8dd
Parent:
0:8b387bed54c2
Remove debugging printouts

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:8b387bed54c2 1
hlipka 0:8b387bed54c2 2 /*
hlipka 0:8b387bed54c2 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
hlipka 0:8b387bed54c2 4
hlipka 0:8b387bed54c2 5 Permission is hereby granted, free of charge, to any person obtaining a copy
hlipka 0:8b387bed54c2 6 of this software and associated documentation files (the "Software"), to deal
hlipka 0:8b387bed54c2 7 in the Software without restriction, including without limitation the rights
hlipka 0:8b387bed54c2 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hlipka 0:8b387bed54c2 9 copies of the Software, and to permit persons to whom the Software is
hlipka 0:8b387bed54c2 10 furnished to do so, subject to the following conditions:
hlipka 0:8b387bed54c2 11
hlipka 0:8b387bed54c2 12 The above copyright notice and this permission notice shall be included in
hlipka 0:8b387bed54c2 13 all copies or substantial portions of the Software.
hlipka 0:8b387bed54c2 14
hlipka 0:8b387bed54c2 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hlipka 0:8b387bed54c2 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hlipka 0:8b387bed54c2 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hlipka 0:8b387bed54c2 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hlipka 0:8b387bed54c2 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hlipka 0:8b387bed54c2 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hlipka 0:8b387bed54c2 21 THE SOFTWARE.
hlipka 0:8b387bed54c2 22 */
hlipka 0:8b387bed54c2 23
hlipka 0:8b387bed54c2 24 #include "ipaddr.h"
hlipka 0:8b387bed54c2 25
hlipka 0:8b387bed54c2 26 #include "netCfg.h"
hlipka 0:8b387bed54c2 27 #if NET_LWIP_STACK
hlipka 0:8b387bed54c2 28 #include "lwip/ip_addr.h"
hlipka 0:8b387bed54c2 29 #endif
hlipka 0:8b387bed54c2 30
hlipka 0:8b387bed54c2 31
hlipka 0:8b387bed54c2 32 #if NET_LWIP_STACK
hlipka 0:8b387bed54c2 33 IpAddr::IpAddr(ip_addr_t* pIp)
hlipka 0:8b387bed54c2 34 {
hlipka 0:8b387bed54c2 35 *((uint32_t*)m_ip) = pIp->addr;
hlipka 0:8b387bed54c2 36 }
hlipka 0:8b387bed54c2 37 #endif
hlipka 0:8b387bed54c2 38
hlipka 0:8b387bed54c2 39 ///Initializes IP address with provided values
hlipka 0:8b387bed54c2 40 IpAddr::IpAddr(uint8_t ip0, uint8_t ip1, uint8_t ip2, uint8_t ip3)
hlipka 0:8b387bed54c2 41 {
hlipka 0:8b387bed54c2 42 //We are in LE
hlipka 0:8b387bed54c2 43 m_ip[0] = ip0;
hlipka 0:8b387bed54c2 44 m_ip[1] = ip1;
hlipka 0:8b387bed54c2 45 m_ip[2] = ip2;
hlipka 0:8b387bed54c2 46 m_ip[3] = ip3;
hlipka 0:8b387bed54c2 47 }
hlipka 0:8b387bed54c2 48
hlipka 0:8b387bed54c2 49 ///Initializes IP address with null values
hlipka 0:8b387bed54c2 50 IpAddr::IpAddr()
hlipka 0:8b387bed54c2 51 {
hlipka 0:8b387bed54c2 52 m_ip[0] = 0;
hlipka 0:8b387bed54c2 53 m_ip[1] = 0;
hlipka 0:8b387bed54c2 54 m_ip[2] = 0;
hlipka 0:8b387bed54c2 55 m_ip[3] = 0;
hlipka 0:8b387bed54c2 56 }
hlipka 0:8b387bed54c2 57
hlipka 0:8b387bed54c2 58
hlipka 0:8b387bed54c2 59 #if NET_LWIP_STACK
hlipka 0:8b387bed54c2 60 ip_addr_t IpAddr::getStruct() const
hlipka 0:8b387bed54c2 61 {
hlipka 0:8b387bed54c2 62 ip_addr_t ip_struct;
hlipka 0:8b387bed54c2 63 ip_struct.addr = *((uint32_t*)m_ip);
hlipka 0:8b387bed54c2 64 return ip_struct;
hlipka 0:8b387bed54c2 65 }
hlipka 0:8b387bed54c2 66 #endif
hlipka 0:8b387bed54c2 67
hlipka 0:8b387bed54c2 68 uint8_t IpAddr::operator[](unsigned int i) const
hlipka 0:8b387bed54c2 69 {
hlipka 0:8b387bed54c2 70 uint8_t null = 0;
hlipka 0:8b387bed54c2 71 if( i > 3 )
hlipka 0:8b387bed54c2 72 return null;
hlipka 0:8b387bed54c2 73 return m_ip[i];
hlipka 0:8b387bed54c2 74 }
hlipka 0:8b387bed54c2 75
hlipka 0:8b387bed54c2 76 bool IpAddr::isEq(const IpAddr& b) const
hlipka 0:8b387bed54c2 77 {
hlipka 0:8b387bed54c2 78 return (*((uint32_t*)m_ip) == *((uint32_t*)(b.m_ip)));
hlipka 0:8b387bed54c2 79 }
hlipka 0:8b387bed54c2 80
hlipka 0:8b387bed54c2 81 bool IpAddr::operator==(const IpAddr& b) const
hlipka 0:8b387bed54c2 82 {
hlipka 0:8b387bed54c2 83 return isEq(b);
hlipka 0:8b387bed54c2 84 }
hlipka 0:8b387bed54c2 85
hlipka 0:8b387bed54c2 86 bool IpAddr::operator!=(const IpAddr& b) const
hlipka 0:8b387bed54c2 87 {
hlipka 0:8b387bed54c2 88 return !(operator==(b));
hlipka 0:8b387bed54c2 89 }
hlipka 0:8b387bed54c2 90
hlipka 0:8b387bed54c2 91 bool IpAddr::isNull() const
hlipka 0:8b387bed54c2 92 {
hlipka 0:8b387bed54c2 93 return (*((uint32_t*)m_ip) == 0);
hlipka 0:8b387bed54c2 94 }
hlipka 0:8b387bed54c2 95
hlipka 0:8b387bed54c2 96 bool IpAddr::isBroadcast() const
hlipka 0:8b387bed54c2 97 {
hlipka 0:8b387bed54c2 98 return (*((uint32_t*)m_ip) == 0xFFFFFFFF);
hlipka 0:8b387bed54c2 99 }
hlipka 0:8b387bed54c2 100
hlipka 0:8b387bed54c2 101 bool IpAddr::isMulticast() const
hlipka 0:8b387bed54c2 102 {
hlipka 0:8b387bed54c2 103 return ((m_ip[0] & 0xF0) == 0xE0);
hlipka 0:8b387bed54c2 104 }