mn_basic_ip_address.hpp
Go to the documentation of this file.
1 /*
2 *This file is part of the Mini Thread Library (https://github.com/RoseLeBlood/MiniThread ).
3 *Copyright (c) 2018 Amber-Sophia Schroeck
4 *
5 *The Mini Thread Library is free software; you can redistribute it and/or modify
6 *it under the terms of the GNU Lesser General Public License as published by
7 *the Free Software Foundation, version 3, or (at your option) any later version.
8 
9 *The Mini Thread Library is distributed in the hope that it will be useful, but
10 *WITHOUT ANY WARRANTY; without even the implied warranty of
11 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 *General Public License for more details.
13 *
14 *You should have received a copy of the GNU Lesser General Public
15 *License along with the Mini Thread Library; if not, see
16 *<https://www.gnu.org/licenses/>.
17 */
18 #ifndef _MINLIB_BASIC_IP_ADDRESS_HPP_
19 #define _MINLIB_BASIC_IP_ADDRESS_HPP_
20 
21 #include "../mn_config.hpp"
22 
23 #include <string.h>
24 
25 #include "freertos/FreeRTOS.h"
26 #include "freertos/task.h"
27 #include "freertos/event_groups.h"
28 #include "esp_system.h"
29 #include "esp_wifi.h"
30 #include "esp_event.h"
31 #include "esp_log.h"
32 #include "nvs_flash.h"
33 #include "lwip/err.h"
34 #include "lwip/sockets.h"
35 
36 #include <array>
37 
38 #include "mn_algorithm.hpp"
39 #include "mn_net_types.hpp"
40 
41 
42 #define MNNET_IS_CLASSA(ipa) IP_CLASSA( ((uint32_t)ipa) )
43 #define MNNET_IS_CLASSB(ipa) IP_CLASSB( ((uint32_t)ipa) )
44 #define MNNET_IS_CLASSC(ipa) IP_CLASSC( ((uint32_t)ipa) )
45 #define MNNET_IS_CLASSD(ipa) IP_CLASSD( ((uint32_t)ipa) )
46 #define MNNET_IP_MULTICAST(ipa) MNNET_IS_CLASSD(ipa)
47 #define MNNET_IP_EXPERIMENTAL(ipa) IP_EXPERIMENTAL( ((uint32_t)ipa) )
48 #define MNNET_IP_BADCLASS(ipa) IP_BADCLASS( ((uint32_t)ipa) )
49 
50 
51 
52 namespace mn {
53  namespace net {
54 
66  public:
71 
77  virtual const char* to_string() = 0;
83  virtual uint8_t* get_bytes() = 0;
89  virtual bool is_loopback() = 0;
95  virtual bool is_broadcast() = 0;
100  virtual address_family get_family() { return m_aFamily; }
101 
106  virtual int length() const = 0;
107 
108  virtual void swap(basic_ip_address& rhs) noexcept {
109  mn::swap<address_family>(m_aFamily, rhs.m_aFamily);
110  }
111  protected:
116  };
117  }
118 }
119 
120 #endif // BASIC_IP_ADDRESS_HPP
Wrapper class around lwip implementation of a ip address.
Definition: mn_basic_ip_address.hpp:65
basic_ip_address(address_family fam)
Constructor.
Definition: mn_basic_ip_address.hpp:70
virtual uint8_t * get_bytes()=0
Get the ip address as byte array.
virtual bool is_broadcast()=0
Is the this address a broadcast address?
virtual const char * to_string()=0
Returns a string containing a representation of the address in presentation format.
virtual int length() const =0
Returns the length in bytes of the ip address.
virtual bool is_loopback()=0
Is the this address a loopback address?
address_family m_aFamily
A saved / cached copy of the address family type of this socket.
Definition: mn_basic_ip_address.hpp:115
virtual void swap(basic_ip_address &rhs) noexcept
Definition: mn_basic_ip_address.hpp:108
virtual address_family get_family()
Get the address family (AF_INET or AF_INET6) of the address.
Definition: mn_basic_ip_address.hpp:100
Basic algorithmens This file is part of the Mini Thread Library (https://github.com/RoseLeBlood/MiniT...
address_family
Defines socket address types for creating.
Definition: mn_net_types.hpp:41
Definition: mn_allocator_typetraits.hpp:25