mbed OS5
Fork of UIPEthernet by
utility/IPAddress.cpp@1:01c2344f98a3, 2014-11-20 (annotated)
- Committer:
- hudakz
- Date:
- Thu Nov 20 21:26:54 2014 +0000
- Revision:
- 1:01c2344f98a3
- Parent:
- uitility/IPAddress.cpp@0:5350a66d5279
rev. 01
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 0:5350a66d5279 | 1 | /* |
hudakz | 0:5350a66d5279 | 2 | IPAddress.cpp - Base class that provides IPAddress |
hudakz | 0:5350a66d5279 | 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. |
hudakz | 0:5350a66d5279 | 4 | |
hudakz | 0:5350a66d5279 | 5 | Modified (ported to mbed) by Zoltan Hudak <hudakz@inbox.com> |
hudakz | 0:5350a66d5279 | 6 | |
hudakz | 0:5350a66d5279 | 7 | This library is free software; you can redistribute it and/or |
hudakz | 0:5350a66d5279 | 8 | modify it under the terms of the GNU Lesser General Public |
hudakz | 0:5350a66d5279 | 9 | License as published by the Free Software Foundation; either |
hudakz | 0:5350a66d5279 | 10 | version 2.1 of the License, or (at your option) any later version. |
hudakz | 0:5350a66d5279 | 11 | |
hudakz | 0:5350a66d5279 | 12 | This library is distributed in the hope that it will be useful, |
hudakz | 0:5350a66d5279 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
hudakz | 0:5350a66d5279 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
hudakz | 0:5350a66d5279 | 15 | Lesser General Public License for more details. |
hudakz | 0:5350a66d5279 | 16 | |
hudakz | 0:5350a66d5279 | 17 | You should have received a copy of the GNU Lesser General Public |
hudakz | 0:5350a66d5279 | 18 | License along with this library; if not, write to the Free Software |
hudakz | 0:5350a66d5279 | 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
hudakz | 0:5350a66d5279 | 20 | */ |
hudakz | 0:5350a66d5279 | 21 | #include <mbed.h> |
hudakz | 0:5350a66d5279 | 22 | #include <IPAddress.h> |
hudakz | 0:5350a66d5279 | 23 | |
hudakz | 0:5350a66d5279 | 24 | /** |
hudakz | 0:5350a66d5279 | 25 | * @brief |
hudakz | 0:5350a66d5279 | 26 | * @note |
hudakz | 0:5350a66d5279 | 27 | * @param |
hudakz | 0:5350a66d5279 | 28 | * @retval |
hudakz | 0:5350a66d5279 | 29 | */ |
hudakz | 0:5350a66d5279 | 30 | IPAddress::IPAddress(void) { |
hudakz | 0:5350a66d5279 | 31 | memset(_address, 0, sizeof(_address)); |
hudakz | 0:5350a66d5279 | 32 | } |
hudakz | 0:5350a66d5279 | 33 | |
hudakz | 0:5350a66d5279 | 34 | /** |
hudakz | 0:5350a66d5279 | 35 | * @brief |
hudakz | 0:5350a66d5279 | 36 | * @note |
hudakz | 0:5350a66d5279 | 37 | * @param |
hudakz | 0:5350a66d5279 | 38 | * @retval |
hudakz | 0:5350a66d5279 | 39 | */ |
hudakz | 0:5350a66d5279 | 40 | IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) { |
hudakz | 0:5350a66d5279 | 41 | _address[0] = first_octet; |
hudakz | 0:5350a66d5279 | 42 | _address[1] = second_octet; |
hudakz | 0:5350a66d5279 | 43 | _address[2] = third_octet; |
hudakz | 0:5350a66d5279 | 44 | _address[3] = fourth_octet; |
hudakz | 0:5350a66d5279 | 45 | } |
hudakz | 0:5350a66d5279 | 46 | |
hudakz | 0:5350a66d5279 | 47 | /** |
hudakz | 0:5350a66d5279 | 48 | * @brief |
hudakz | 0:5350a66d5279 | 49 | * @note |
hudakz | 0:5350a66d5279 | 50 | * @param |
hudakz | 0:5350a66d5279 | 51 | * @retval |
hudakz | 0:5350a66d5279 | 52 | */ |
hudakz | 0:5350a66d5279 | 53 | IPAddress::IPAddress(uint32_t address) { |
hudakz | 0:5350a66d5279 | 54 | memcpy(_address, &address, sizeof(_address)); |
hudakz | 0:5350a66d5279 | 55 | } |
hudakz | 0:5350a66d5279 | 56 | |
hudakz | 0:5350a66d5279 | 57 | /** |
hudakz | 0:5350a66d5279 | 58 | * @brief |
hudakz | 0:5350a66d5279 | 59 | * @note |
hudakz | 0:5350a66d5279 | 60 | * @param |
hudakz | 0:5350a66d5279 | 61 | * @retval |
hudakz | 0:5350a66d5279 | 62 | */ |
hudakz | 0:5350a66d5279 | 63 | IPAddress::IPAddress(const uint8_t* address) { |
hudakz | 0:5350a66d5279 | 64 | memcpy(_address, address, sizeof(_address)); |
hudakz | 0:5350a66d5279 | 65 | } |
hudakz | 0:5350a66d5279 | 66 | |
hudakz | 0:5350a66d5279 | 67 | /** |
hudakz | 0:5350a66d5279 | 68 | * @brief |
hudakz | 0:5350a66d5279 | 69 | * @note |
hudakz | 0:5350a66d5279 | 70 | * @param |
hudakz | 0:5350a66d5279 | 71 | * @retval |
hudakz | 0:5350a66d5279 | 72 | */ |
hudakz | 0:5350a66d5279 | 73 | IPAddress &IPAddress::operator=(const uint8_t* address) { |
hudakz | 0:5350a66d5279 | 74 | memcpy(_address, address, sizeof(_address)); |
hudakz | 0:5350a66d5279 | 75 | return *this; |
hudakz | 0:5350a66d5279 | 76 | } |
hudakz | 0:5350a66d5279 | 77 | |
hudakz | 0:5350a66d5279 | 78 | /** |
hudakz | 0:5350a66d5279 | 79 | * @brief |
hudakz | 0:5350a66d5279 | 80 | * @note |
hudakz | 0:5350a66d5279 | 81 | * @param |
hudakz | 0:5350a66d5279 | 82 | * @retval |
hudakz | 0:5350a66d5279 | 83 | */ |
hudakz | 0:5350a66d5279 | 84 | IPAddress &IPAddress::operator=(uint32_t address) { |
hudakz | 0:5350a66d5279 | 85 | memcpy(_address, (const uint8_t*) &address, sizeof(_address)); |
hudakz | 0:5350a66d5279 | 86 | return *this; |
hudakz | 0:5350a66d5279 | 87 | } |
hudakz | 0:5350a66d5279 | 88 | |
hudakz | 0:5350a66d5279 | 89 | /** |
hudakz | 0:5350a66d5279 | 90 | * @brief |
hudakz | 0:5350a66d5279 | 91 | * @note |
hudakz | 0:5350a66d5279 | 92 | * @param |
hudakz | 0:5350a66d5279 | 93 | * @retval |
hudakz | 0:5350a66d5279 | 94 | */ |
hudakz | 0:5350a66d5279 | 95 | bool IPAddress::operator==(const uint8_t* addr) const |
hudakz | 0:5350a66d5279 | 96 | { |
hudakz | 0:5350a66d5279 | 97 | return memcmp(addr, _address, sizeof(_address)) == 0; |
hudakz | 0:5350a66d5279 | 98 | } |
hudakz | 0:5350a66d5279 | 99 | |
hudakz | 0:5350a66d5279 | 100 | //size_t IPAddress::printTo(Print& p) const |
hudakz | 0:5350a66d5279 | 101 | //{ |
hudakz | 0:5350a66d5279 | 102 | // size_t n = 0; |
hudakz | 0:5350a66d5279 | 103 | // for (int i =0; i < 3; i++) |
hudakz | 0:5350a66d5279 | 104 | // { |
hudakz | 0:5350a66d5279 | 105 | // n += p.print(_address[i], DEC); |
hudakz | 0:5350a66d5279 | 106 | // n += p.print('.'); |
hudakz | 0:5350a66d5279 | 107 | // } |
hudakz | 0:5350a66d5279 | 108 | // n += p.print(_address[3], DEC); |
hudakz | 0:5350a66d5279 | 109 | // return n; |
hudakz | 0:5350a66d5279 | 110 | //} |
hudakz | 0:5350a66d5279 | 111 | // |
hudakz | 0:5350a66d5279 | 112 |