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.
Dependents: NetRelais TCP_Client_Example TCP_Server_Example UDP_Server_Example ... more
ip/address.hpp@3:d30db8752485, 2012-07-18 (annotated)
- Committer:
- NegativeBlack
- Date:
- Wed Jul 18 11:22:37 2012 +0000
- Revision:
- 3:d30db8752485
- Parent:
- 2:e283a0062097
- Child:
- 8:cdee0f2b6ff0
Implemented UDP and TCP socket. UDP is fully tested, TCP still needs to be tested.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
NegativeBlack | 0:00d5bc4b46e1 | 1 | /** |
NegativeBlack | 0:00d5bc4b46e1 | 2 | * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com> |
NegativeBlack | 0:00d5bc4b46e1 | 3 | * All rights reserved. |
NegativeBlack | 0:00d5bc4b46e1 | 4 | * |
NegativeBlack | 0:00d5bc4b46e1 | 5 | * Redistribution and use in source and binary forms, with or without |
NegativeBlack | 0:00d5bc4b46e1 | 6 | * modification, are permitted provided that the following conditions are met: |
NegativeBlack | 0:00d5bc4b46e1 | 7 | * |
NegativeBlack | 0:00d5bc4b46e1 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this |
NegativeBlack | 0:00d5bc4b46e1 | 9 | * list of conditions and the following disclaimer. |
NegativeBlack | 0:00d5bc4b46e1 | 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
NegativeBlack | 0:00d5bc4b46e1 | 11 | * this list of conditions and the following disclaimer in the documentation |
NegativeBlack | 0:00d5bc4b46e1 | 12 | * and/or other materials provided with the distribution. |
NegativeBlack | 0:00d5bc4b46e1 | 13 | * |
NegativeBlack | 0:00d5bc4b46e1 | 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
NegativeBlack | 0:00d5bc4b46e1 | 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
NegativeBlack | 0:00d5bc4b46e1 | 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
NegativeBlack | 0:00d5bc4b46e1 | 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
NegativeBlack | 0:00d5bc4b46e1 | 18 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
NegativeBlack | 0:00d5bc4b46e1 | 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
NegativeBlack | 0:00d5bc4b46e1 | 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
NegativeBlack | 0:00d5bc4b46e1 | 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
NegativeBlack | 0:00d5bc4b46e1 | 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
NegativeBlack | 0:00d5bc4b46e1 | 23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
NegativeBlack | 0:00d5bc4b46e1 | 24 | */ |
NegativeBlack | 0:00d5bc4b46e1 | 25 | |
NegativeBlack | 0:00d5bc4b46e1 | 26 | #ifndef _NETWORK_IP_ADDRESS_HPP_ |
NegativeBlack | 0:00d5bc4b46e1 | 27 | #define _NETWORK_IP_ADDRESS_HPP_ |
NegativeBlack | 0:00d5bc4b46e1 | 28 | |
NegativeBlack | 0:00d5bc4b46e1 | 29 | #include <cstdio> |
NegativeBlack | 0:00d5bc4b46e1 | 30 | #include <cstring> |
NegativeBlack | 0:00d5bc4b46e1 | 31 | #include <string> |
NegativeBlack | 0:00d5bc4b46e1 | 32 | |
NegativeBlack | 0:00d5bc4b46e1 | 33 | #include "bsd_socket.h" |
NegativeBlack | 0:00d5bc4b46e1 | 34 | |
NegativeBlack | 0:00d5bc4b46e1 | 35 | namespace network { |
NegativeBlack | 0:00d5bc4b46e1 | 36 | namespace ip { |
NegativeBlack | 0:00d5bc4b46e1 | 37 | |
NegativeBlack | 0:00d5bc4b46e1 | 38 | class Address |
NegativeBlack | 0:00d5bc4b46e1 | 39 | { |
NegativeBlack | 0:00d5bc4b46e1 | 40 | public: |
NegativeBlack | 0:00d5bc4b46e1 | 41 | static const int Any = (int)0x00000000; |
NegativeBlack | 3:d30db8752485 | 42 | static const int Loopback = (int)0x0100007f; |
NegativeBlack | 0:00d5bc4b46e1 | 43 | static const int Broadcast = (int)0xffffffff; |
NegativeBlack | 0:00d5bc4b46e1 | 44 | |
NegativeBlack | 0:00d5bc4b46e1 | 45 | protected: |
NegativeBlack | 0:00d5bc4b46e1 | 46 | unsigned char _address[4]; |
NegativeBlack | 0:00d5bc4b46e1 | 47 | |
NegativeBlack | 0:00d5bc4b46e1 | 48 | public: |
NegativeBlack | 0:00d5bc4b46e1 | 49 | Address(); |
NegativeBlack | 0:00d5bc4b46e1 | 50 | explicit Address(const Address &other); |
NegativeBlack | 0:00d5bc4b46e1 | 51 | explicit Address(const int address); |
NegativeBlack | 0:00d5bc4b46e1 | 52 | explicit Address(const char *address); |
NegativeBlack | 0:00d5bc4b46e1 | 53 | explicit Address(const std::string &address); |
NegativeBlack | 0:00d5bc4b46e1 | 54 | |
NegativeBlack | 2:e283a0062097 | 55 | int fromString(const char *address); |
NegativeBlack | 0:00d5bc4b46e1 | 56 | int fromString(const std::string &address); |
NegativeBlack | 0:00d5bc4b46e1 | 57 | std::string toString(); |
NegativeBlack | 0:00d5bc4b46e1 | 58 | |
NegativeBlack | 0:00d5bc4b46e1 | 59 | int fromHostname(const char *hostname); |
NegativeBlack | 2:e283a0062097 | 60 | int fromHostname(const std::string &hostname); |
NegativeBlack | 0:00d5bc4b46e1 | 61 | |
NegativeBlack | 3:d30db8752485 | 62 | void fromNative(int address); |
NegativeBlack | 0:00d5bc4b46e1 | 63 | int toNative(); |
NegativeBlack | 0:00d5bc4b46e1 | 64 | |
NegativeBlack | 3:d30db8752485 | 65 | bool isEmpty(); |
NegativeBlack | 3:d30db8752485 | 66 | |
NegativeBlack | 0:00d5bc4b46e1 | 67 | Address &operator=(const Address &other); |
NegativeBlack | 0:00d5bc4b46e1 | 68 | |
NegativeBlack | 0:00d5bc4b46e1 | 69 | bool operator==(const Address &other); |
NegativeBlack | 0:00d5bc4b46e1 | 70 | bool operator!=(const Address &other); |
NegativeBlack | 0:00d5bc4b46e1 | 71 | }; |
NegativeBlack | 0:00d5bc4b46e1 | 72 | |
NegativeBlack | 0:00d5bc4b46e1 | 73 | } // namespace ip |
NegativeBlack | 0:00d5bc4b46e1 | 74 | } // namespace network |
NegativeBlack | 0:00d5bc4b46e1 | 75 | |
NegativeBlack | 0:00d5bc4b46e1 | 76 | #endif // _NETWORK_IP_ADDRESS_HPP_ |