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