A new object oriented network api that can be used to replace the one provided by the EthernetInterface library.

Dependents:   NetRelais TCP_Client_Example TCP_Server_Example UDP_Server_Example ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers address.hpp Source File

address.hpp

00001 /**
00002  * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com>
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice, this
00009  *    list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright notice,
00011  *    this list of conditions and the following disclaimer in the documentation
00012  *    and/or other materials provided with the distribution.
00013  *
00014  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00015  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00016  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00017  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00018  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00019  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00020  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00021  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00023  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00024  */
00025 
00026 #ifndef _NETWORK_IP_ADDRESS_HPP_
00027 #define _NETWORK_IP_ADDRESS_HPP_
00028 
00029 #include <cstdio>
00030 #include <cstring>
00031 #include <string>
00032 
00033 #include "lwip/sockets.h"
00034 #include "lwip/netdb.h"
00035 
00036 namespace network {
00037 namespace ip {
00038 
00039     class Address
00040     {
00041         public:
00042             static const int Any       = (int)0x00000000;
00043             static const int Loopback  = (int)0x0100007f;
00044             static const int Broadcast = (int)0xffffffff;
00045     
00046         protected:
00047             unsigned char _address[4];
00048             
00049         public:
00050             Address();
00051             explicit Address(const Address &other);
00052             explicit Address(const int address);
00053             explicit Address(const char *address);
00054             explicit Address(const std::string &address);
00055             
00056             int fromString(const char *address);
00057             int fromString(const std::string &address);
00058             std::string toString();
00059             
00060             int fromHostname(const char *hostname);
00061             int fromHostname(const std::string &hostname);
00062             
00063             void fromNative(int address);
00064             int toNative();
00065             
00066             bool isEmpty();
00067             
00068             Address &operator=(const Address &other);
00069             
00070             bool operator==(const Address &other);
00071             bool operator!=(const Address &other);
00072     };
00073 
00074 } // namespace ip
00075 } // namespace network
00076 
00077 #endif // _NETWORK_IP_ADDRESS_HPP_