MeterLogger
ip_addr.h
Go to the documentation of this file.
1 /*
2  * ESPRSSIF MIT License
3  *
4  * Copyright (c) 2016 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
5  *
6  * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
7  * it is free of charge, to any person obtaining a copy of this software and associated
8  * documentation files (the "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11  * to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or
14  * substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  *
23  */
24 
25 #ifndef __IP_ADDR_H__
26 #define __IP_ADDR_H__
27 
28 #include "c_types.h"
29 
30 struct ip_addr {
32 };
33 
34 typedef struct ip_addr ip_addr_t;
35 
36 struct ip_info {
37  struct ip_addr ip;
38  struct ip_addr netmask;
39  struct ip_addr gw;
40 };
41 
42 /**
43  * Determine if two address are on the same network.
44  *
45  * @arg addr1 IP address 1
46  * @arg addr2 IP address 2
47  * @arg mask network identifier mask
48  * @return !0 if the network identifiers of both address match
49  */
50 #define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
51  (mask)->addr) == \
52  ((addr2)->addr & \
53  (mask)->addr))
54 
55 /** Set an IP address given by the four byte-parts.
56  Little-endian version that prevents the use of htonl. */
57 #define IP4_ADDR(ipaddr, a,b,c,d) \
58  (ipaddr)->addr = ((uint32)((d) & 0xff) << 24) | \
59  ((uint32)((c) & 0xff) << 16) | \
60  ((uint32)((b) & 0xff) << 8) | \
61  (uint32)((a) & 0xff)
62 
63 #define ip4_addr1(ipaddr) (((uint8*)(ipaddr))[0])
64 #define ip4_addr2(ipaddr) (((uint8*)(ipaddr))[1])
65 #define ip4_addr3(ipaddr) (((uint8*)(ipaddr))[2])
66 #define ip4_addr4(ipaddr) (((uint8*)(ipaddr))[3])
67 
68 #define ip4_addr1_16(ipaddr) ((uint16)ip4_addr1(ipaddr))
69 #define ip4_addr2_16(ipaddr) ((uint16)ip4_addr2(ipaddr))
70 #define ip4_addr3_16(ipaddr) ((uint16)ip4_addr3(ipaddr))
71 #define ip4_addr4_16(ipaddr) ((uint16)ip4_addr4(ipaddr))
72 
73 
74 /** 255.255.255.255 */
75 #define IPADDR_NONE ((uint32)0xffffffffUL)
76 /** 0.0.0.0 */
77 #define IPADDR_ANY ((uint32)0x00000000UL)
78 uint32 ipaddr_addr(const char *cp);
79 
80 #define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \
81  ip4_addr2_16(ipaddr), \
82  ip4_addr3_16(ipaddr), \
83  ip4_addr4_16(ipaddr)
84 
85 #define IPSTR "%d.%d.%d.%d"
86 
87 #endif /* __IP_ADDR_H__ */
uint32 addr
Definition: ip_addr.h:31
typedefPACK_STRUCT_END struct ip_addr ip_addr_t
Definition: ip_addr.h:64
unsigned int uint32
Definition: c_types.h:54
u32_t ipaddr_addr(const char *cp) ICACHE_FLASH_ATTR
Definition: ip_addr.c:130