The Pedigree Project  0.1
inet.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
28 /*
29  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
30  * All rights reserved.
31  *
32  * Redistribution and use in source and binary forms, with or without modification,
33  * are permitted provided that the following conditions are met:
34  *
35  * 1. Redistributions of source code must retain the above copyright notice,
36  * this list of conditions and the following disclaimer.
37  * 2. Redistributions in binary form must reproduce the above copyright notice,
38  * this list of conditions and the following disclaimer in the documentation
39  * and/or other materials provided with the distribution.
40  * 3. The name of the author may not be used to endorse or promote products
41  * derived from this software without specific prior written permission.
42  *
43  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
44  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
45  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
46  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
47  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
48  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
49  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
50  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
51  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
52  * OF SUCH DAMAGE.
53  *
54  * This file is part of the lwIP TCP/IP stack.
55  *
56  * Author: Adam Dunkels <adam@sics.se>
57  *
58  */
59 #ifndef LWIP_HDR_INET_H
60 #define LWIP_HDR_INET_H
61 
62 #include "lwip/opt.h"
63 #include "lwip/def.h"
64 #include "lwip/ip_addr.h"
65 #include "lwip/ip6_addr.h"
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
71 /* If your port already typedef's in_addr_t, define IN_ADDR_T_DEFINED
72  to prevent this code from redefining it. */
73 #if !defined(in_addr_t) && !defined(IN_ADDR_T_DEFINED)
74 typedef u32_t in_addr_t;
75 #endif
76 
77 struct in_addr {
78  in_addr_t s_addr;
79 };
80 
81 struct in6_addr {
82  union {
83  u32_t u32_addr[4];
84  u8_t u8_addr[16];
85  } un;
86 #define s6_addr un.u8_addr
87 };
88 
90 #define INADDR_NONE IPADDR_NONE
91 
92 #define INADDR_LOOPBACK IPADDR_LOOPBACK
93 
94 #define INADDR_ANY IPADDR_ANY
95 
96 #define INADDR_BROADCAST IPADDR_BROADCAST
97 
100 #define IN6ADDR_ANY_INIT {{{0,0,0,0}}}
101 
103 #define IN6ADDR_LOOPBACK_INIT {{{0,0,0,PP_HTONL(1)}}}
104 
105 extern const struct in6_addr in6addr_any;
106 
107 /* Definitions of the bits in an (IPv4) Internet address integer.
108 
109  On subnets, host and network parts are found according to
110  the subnet mask, not these masks. */
111 #define IN_CLASSA(a) IP_CLASSA(a)
112 #define IN_CLASSA_NET IP_CLASSA_NET
113 #define IN_CLASSA_NSHIFT IP_CLASSA_NSHIFT
114 #define IN_CLASSA_HOST IP_CLASSA_HOST
115 #define IN_CLASSA_MAX IP_CLASSA_MAX
116 
117 #define IN_CLASSB(b) IP_CLASSB(b)
118 #define IN_CLASSB_NET IP_CLASSB_NET
119 #define IN_CLASSB_NSHIFT IP_CLASSB_NSHIFT
120 #define IN_CLASSB_HOST IP_CLASSB_HOST
121 #define IN_CLASSB_MAX IP_CLASSB_MAX
122 
123 #define IN_CLASSC(c) IP_CLASSC(c)
124 #define IN_CLASSC_NET IP_CLASSC_NET
125 #define IN_CLASSC_NSHIFT IP_CLASSC_NSHIFT
126 #define IN_CLASSC_HOST IP_CLASSC_HOST
127 #define IN_CLASSC_MAX IP_CLASSC_MAX
128 
129 #define IN_CLASSD(d) IP_CLASSD(d)
130 #define IN_CLASSD_NET IP_CLASSD_NET /* These ones aren't really */
131 #define IN_CLASSD_NSHIFT IP_CLASSD_NSHIFT /* net and host fields, but */
132 #define IN_CLASSD_HOST IP_CLASSD_HOST /* routing needn't know. */
133 #define IN_CLASSD_MAX IP_CLASSD_MAX
134 
135 #define IN_MULTICAST(a) IP_MULTICAST(a)
136 
137 #define IN_EXPERIMENTAL(a) IP_EXPERIMENTAL(a)
138 #define IN_BADCLASS(a) IP_BADCLASS(a)
139 
140 #define IN_LOOPBACKNET IP_LOOPBACKNET
141 
142 
143 #ifndef INET_ADDRSTRLEN
144 #define INET_ADDRSTRLEN IP4ADDR_STRLEN_MAX
145 #endif
146 #if LWIP_IPV6
147 #ifndef INET6_ADDRSTRLEN
148 #define INET6_ADDRSTRLEN IP6ADDR_STRLEN_MAX
149 #endif
150 #endif
151 
152 #if LWIP_IPV4
153 
154 #define inet_addr_from_ip4addr(target_inaddr, source_ipaddr) ((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr))
155 #define inet_addr_to_ip4addr(target_ipaddr, source_inaddr) (ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr))
156 /* ATTENTION: the next define only works because both s_addr and ip4_addr_t are an u32_t effectively! */
157 #define inet_addr_to_ip4addr_p(target_ip4addr_p, source_inaddr) ((target_ip4addr_p) = (ip4_addr_t*)&((source_inaddr)->s_addr))
158 
159 /* directly map this to the lwip internal functions */
160 #define inet_addr(cp) ipaddr_addr(cp)
161 #define inet_aton(cp, addr) ip4addr_aton(cp, (ip4_addr_t*)addr)
162 #define inet_ntoa(addr) ip4addr_ntoa((const ip4_addr_t*)&(addr))
163 #define inet_ntoa_r(addr, buf, buflen) ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen)
164 
165 #endif /* LWIP_IPV4 */
166 
167 #if LWIP_IPV6
168 #define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) {(target_in6addr)->un.u32_addr[0] = (source_ip6addr)->addr[0]; \
169  (target_in6addr)->un.u32_addr[1] = (source_ip6addr)->addr[1]; \
170  (target_in6addr)->un.u32_addr[2] = (source_ip6addr)->addr[2]; \
171  (target_in6addr)->un.u32_addr[3] = (source_ip6addr)->addr[3];}
172 #define inet6_addr_to_ip6addr(target_ip6addr, source_in6addr) {(target_ip6addr)->addr[0] = (source_in6addr)->un.u32_addr[0]; \
173  (target_ip6addr)->addr[1] = (source_in6addr)->un.u32_addr[1]; \
174  (target_ip6addr)->addr[2] = (source_in6addr)->un.u32_addr[2]; \
175  (target_ip6addr)->addr[3] = (source_in6addr)->un.u32_addr[3];}
176 /* ATTENTION: the next define only works because both in6_addr and ip6_addr_t are an u32_t[4] effectively! */
177 #define inet6_addr_to_ip6addr_p(target_ip6addr_p, source_in6addr) ((target_ip6addr_p) = (ip6_addr_t*)(source_in6addr))
178 
179 /* directly map this to the lwip internal functions */
180 #define inet6_aton(cp, addr) ip6addr_aton(cp, (ip6_addr_t*)addr)
181 #define inet6_ntoa(addr) ip6addr_ntoa((const ip6_addr_t*)&(addr))
182 #define inet6_ntoa_r(addr, buf, buflen) ip6addr_ntoa_r((const ip6_addr_t*)&(addr), buf, buflen)
183 
184 #endif /* LWIP_IPV6 */
185 
186 
187 #ifdef __cplusplus
188 }
189 #endif
190 
191 #endif /* LWIP_HDR_INET_H */
Definition: inet.h:81
Definition: inet.h:77
const struct in6_addr in6addr_any
Definition: glue.c:123