Mistake on this page?
Report an issue in GitHub or email us
lwip/inet.h
Go to the documentation of this file.
1 /**
2  * @file
3  * This file (together with sockets.h) aims to provide structs and functions from
4  * - arpa/inet.h
5  * - netinet/in.h
6  *
7  */
8 
9 /*
10  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
11  * All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without modification,
14  * are permitted provided that the following conditions are met:
15  *
16  * 1. Redistributions of source code must retain the above copyright notice,
17  * this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright notice,
19  * this list of conditions and the following disclaimer in the documentation
20  * and/or other materials provided with the distribution.
21  * 3. The name of the author may not be used to endorse or promote products
22  * derived from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33  * OF SUCH DAMAGE.
34  *
35  * This file is part of the lwIP TCP/IP stack.
36  *
37  * Author: Adam Dunkels <adam@sics.se>
38  *
39  */
40 #ifndef LWIP_HDR_INET_H
41 #define LWIP_HDR_INET_H
42 
43 #include "lwip/opt.h"
44 #include "lwip/def.h"
45 #include "lwip/ip_addr.h"
46 #include "lwip/ip6_addr.h"
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 /* If your port already typedef's in_addr_t, define IN_ADDR_T_DEFINED
53  to prevent this code from redefining it. */
54 #if !defined(in_addr_t) && !defined(IN_ADDR_T_DEFINED)
55 typedef u32_t in_addr_t;
56 #endif
57 
58 struct in_addr {
59  in_addr_t s_addr;
60 };
61 
62 struct in6_addr {
63  union {
64  u32_t u32_addr[4];
65  u8_t u8_addr[16];
66  } un;
67 #define s6_addr un.u8_addr
68 };
69 
70 /** 255.255.255.255 */
71 #define INADDR_NONE IPADDR_NONE
72 /** 127.0.0.1 */
73 #define INADDR_LOOPBACK IPADDR_LOOPBACK
74 /** 0.0.0.0 */
75 #define INADDR_ANY IPADDR_ANY
76 /** 255.255.255.255 */
77 #define INADDR_BROADCAST IPADDR_BROADCAST
78 
79 /** This macro can be used to initialize a variable of type struct in6_addr
80  to the IPv6 wildcard address. */
81 #define IN6ADDR_ANY_INIT {{{0,0,0,0}}}
82 /** This macro can be used to initialize a variable of type struct in6_addr
83  to the IPv6 loopback address. */
84 #define IN6ADDR_LOOPBACK_INIT {{{0,0,0,PP_HTONL(1)}}}
85 /** This variable is initialized by the system to contain the wildcard IPv6 address. */
86 extern const struct in6_addr in6addr_any;
87 
88 /* Definitions of the bits in an (IPv4) Internet address integer.
89 
90  On subnets, host and network parts are found according to
91  the subnet mask, not these masks. */
92 #define IN_CLASSA(a) IP_CLASSA(a)
93 #define IN_CLASSA_NET IP_CLASSA_NET
94 #define IN_CLASSA_NSHIFT IP_CLASSA_NSHIFT
95 #define IN_CLASSA_HOST IP_CLASSA_HOST
96 #define IN_CLASSA_MAX IP_CLASSA_MAX
97 
98 #define IN_CLASSB(b) IP_CLASSB(b)
99 #define IN_CLASSB_NET IP_CLASSB_NET
100 #define IN_CLASSB_NSHIFT IP_CLASSB_NSHIFT
101 #define IN_CLASSB_HOST IP_CLASSB_HOST
102 #define IN_CLASSB_MAX IP_CLASSB_MAX
103 
104 #define IN_CLASSC(c) IP_CLASSC(c)
105 #define IN_CLASSC_NET IP_CLASSC_NET
106 #define IN_CLASSC_NSHIFT IP_CLASSC_NSHIFT
107 #define IN_CLASSC_HOST IP_CLASSC_HOST
108 #define IN_CLASSC_MAX IP_CLASSC_MAX
109 
110 #define IN_CLASSD(d) IP_CLASSD(d)
111 #define IN_CLASSD_NET IP_CLASSD_NET /* These ones aren't really */
112 #define IN_CLASSD_NSHIFT IP_CLASSD_NSHIFT /* net and host fields, but */
113 #define IN_CLASSD_HOST IP_CLASSD_HOST /* routing needn't know. */
114 #define IN_CLASSD_MAX IP_CLASSD_MAX
115 
116 #define IN_MULTICAST(a) IP_MULTICAST(a)
117 
118 #define IN_EXPERIMENTAL(a) IP_EXPERIMENTAL(a)
119 #define IN_BADCLASS(a) IP_BADCLASS(a)
120 
121 #define IN_LOOPBACKNET IP_LOOPBACKNET
122 
123 
124 #ifndef INET_ADDRSTRLEN
125 #define INET_ADDRSTRLEN IP4ADDR_STRLEN_MAX
126 #endif
127 #if LWIP_IPV6
128 #ifndef INET6_ADDRSTRLEN
129 #define INET6_ADDRSTRLEN IP6ADDR_STRLEN_MAX
130 #endif
131 #endif
132 
133 #if LWIP_IPV4
134 
135 #define inet_addr_from_ip4addr(target_inaddr, source_ipaddr) ((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr))
136 #define inet_addr_to_ip4addr(target_ipaddr, source_inaddr) (ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr))
137 
138 /* directly map this to the lwip internal functions */
139 #define inet_addr(cp) ipaddr_addr(cp)
140 #define inet_aton(cp, addr) ip4addr_aton(cp, (ip4_addr_t*)addr)
141 #define inet_ntoa(addr) ip4addr_ntoa((const ip4_addr_t*)&(addr))
142 #define inet_ntoa_r(addr, buf, buflen) ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen)
143 
144 #endif /* LWIP_IPV4 */
145 
146 #if LWIP_IPV6
147 #define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) {(target_in6addr)->un.u32_addr[0] = (source_ip6addr)->addr[0]; \
148  (target_in6addr)->un.u32_addr[1] = (source_ip6addr)->addr[1]; \
149  (target_in6addr)->un.u32_addr[2] = (source_ip6addr)->addr[2]; \
150  (target_in6addr)->un.u32_addr[3] = (source_ip6addr)->addr[3];}
151 #define inet6_addr_to_ip6addr(target_ip6addr, source_in6addr) {(target_ip6addr)->addr[0] = (source_in6addr)->un.u32_addr[0]; \
152  (target_ip6addr)->addr[1] = (source_in6addr)->un.u32_addr[1]; \
153  (target_ip6addr)->addr[2] = (source_in6addr)->un.u32_addr[2]; \
154  (target_ip6addr)->addr[3] = (source_in6addr)->un.u32_addr[3]; \
155  ip6_addr_clear_zone(target_ip6addr);}
156 
157 /* directly map this to the lwip internal functions */
158 #define inet6_aton(cp, addr) ip6addr_aton(cp, (ip6_addr_t*)addr)
159 #define inet6_ntoa(addr) ip6addr_ntoa((const ip6_addr_t*)&(addr))
160 #define inet6_ntoa_r(addr, buf, buflen) ip6addr_ntoa_r((const ip6_addr_t*)&(addr), buf, buflen)
161 
162 #endif /* LWIP_IPV6 */
163 
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif /* LWIP_HDR_INET_H */
various utility macros
lwIP Options Configuration
IPv6 addresses.
socket address(IPV6 net format)
Definition: mx_wifi.h:760
socket address(net format)
Definition: mx_wifi.h:740
const struct in6_addr in6addr_any
This variable is initialized by the system to contain the wildcard IPv6 address.
IP address API (common IPv4 and IPv6)
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.