Tizen RT Libs&Environment  v1.0 D5
inet.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 /****************************************************************************
19  * include/arpa/inet.h
20  *
21  * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
22  * Author: Gregory Nutt <gnutt@nuttx.org>
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  *
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in
32  * the documentation and/or other materials provided with the
33  * distribution.
34  * 3. Neither the name Gregory Nutt nor the names of its contributors may be
35  * used to endorse or promote products derived from this software
36  * without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
42  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
45  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
46  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
48  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49  * POSSIBILITY OF SUCH DAMAGE.
50  *
51  ****************************************************************************/
52 
64 #ifndef __INCLUDE_ARPA_INET_H
65 #define __INCLUDE_ARPA_INET_H
66 
67 /****************************************************************************
68  * Included Files
69  ****************************************************************************/
70 
71 #include <tinyara/config.h>
72 
73 #include <sys/types.h>
74 #include <stdint.h>
75 #include <netinet/in.h>
76 
77 /****************************************************************************
78  * Public Type Definitions
79  ****************************************************************************/
80 /* Length of the string form for IP address (excludes NULL termination) */
81 
82 #define INET_ADDRSTRLEN 16
83 
84 /* Length of the string form for IPv6 address (excludes NULL termination) */
85 
86 #define INET6_ADDRSTRLEN 46
87 
88 /* This macro to convert a 16/32-bit constant values quantity from host byte
89  * order to network byte order. The 16-bit version of this macro is required
90  * for uIP:
91  *
92  * Author Adam Dunkels <adam@dunkels.com>
93  * Copyright (c) 2001-2003, Adam Dunkels.
94  * All rights reserved.
95  */
96 
97 #ifdef CONFIG_ENDIAN_BIG
98 # define HTONS(ns) (ns)
99 # define HTONL(nl) (nl)
100 #else
101 # define HTONS(ns) \
102  (unsigned short) \
103  (((((unsigned short)(ns)) & 0x00ff) << 8) | \
104  ((((unsigned short)(ns)) >> 8) & 0x00ff))
105 # define HTONL(nl) \
106  (unsigned long) \
107  (((((unsigned long)(nl)) & 0x000000ffUL) << 24) | \
108  ((((unsigned long)(nl)) & 0x0000ff00UL) << 8) | \
109  ((((unsigned long)(nl)) & 0x00ff0000UL) >> 8) | \
110  ((((unsigned long)(nl)) & 0xff000000UL) >> 24))
111 #endif
112 
113 #define NTOHS(hs) HTONS(hs)
114 #define NTOHL(hl) HTONL(hl)
115 
116 #ifdef CONFIG_NET_LWIP
117 
118 #ifdef htons
119 #undef htons
120 #endif /* htons */
121 #ifdef htonl
122 #undef htonl
123 #endif /* htonl */
124 #ifdef ntohs
125 #undef ntohs
126 #endif /* ntohs */
127 #ifdef ntohl
128 #undef ntohl
129 #endif /* ntohl */
130 #ifdef inet_aton
131 #undef inet_aton
132 #endif /* inet_aton */
133 #ifdef inet_ntoa
134 #undef inet_ntoa
135 #endif /* inet_ntoa */
136 #ifdef inet_pton
137 #undef inet_pton
138 #endif /* inet_pton */
139 #ifdef inet_ntop
140 #undef inet_ntop
141 #endif /* inet_ntop */
142 #ifdef inet_addr
143 #undef inet_addr
144 #endif /* inet_addr */
145 
146 #endif /*CONFIG_NET_LWIP*/
147 
148 /****************************************************************************
149  * Public Function Prototypes
150  ****************************************************************************/
151 
152 #ifdef __cplusplus
153 #define EXTERN extern "C"
154 extern "C"
155 {
156 #else
157 #define EXTERN extern
158 #endif
159 
160 /* Functions to convert between nost and network byte ordering */
161 
169 uint32_t ntohl(uint32_t nl);
170 
178 uint16_t ntohs(uint16_t ns);
179 
187 uint32_t htonl(uint32_t hl);
188 
196 uint16_t htons(uint16_t hs);
197 
198 /* Functions to manipulate address representations */
207 int inet_aton(FAR const char *cp, FAR struct in_addr *inp);
208 
216 in_addr_t inet_addr(FAR const char *cp);
217 
219 in_addr_t inet_network(FAR const char *cp);
221 
222 #ifdef CONFIG_CAN_PASS_STRUCTS
223 
230 FAR char *inet_ntoa(struct in_addr in);
231 
233 in_addr_t inet_lnaof(struct in_addr in);
234 in_addr_t inet_netof(struct in_addr in);
236 #else
237 FAR char *_inet_ntoa(in_addr_t in);
239 # define inet_ntoa(in) _inet_ntoa(in.s_addr);
240 
241 in_addr_t _inet_lnaof(in_addr_t in);
242 # define inet_lnaof(in) _inet_lnaof(in.s_addr);
243 
244 in_addr_t _inet_netof(in_addr_t in);
245 # define inet_netof(in) _inet_netof(in.s_addr);
246 #endif
248 struct in_addr inet_makeaddr(in_addr_t net, in_addr_t host);
250 
251 int inet_pton(int af, FAR const char *src, FAR void *dst);
252 const char *inet_ntop(int af, FAR const void *src, FAR char *dst, socklen_t size);
254 
255 #undef EXTERN
256 #ifdef __cplusplus
257 }
258 #endif
259 
260 #endif /* __INCLUDE_ARPA_INET_H */
261 // end of SOCKET group
uint16_t ntohs(uint16_t ns)
Convert the unsigned short integer netshort from network byte order to host byte order.
uint16_t htons(uint16_t hs)
Convert the unsigned short integer hostshort from host byte order to network byte order...
uint32_t htonl(uint32_t hl)
Convert the unsigned integer hostlong from host byte order to network byte order. ...
int inet_aton(FAR const char *cp, FAR struct in_addr *inp)
Convert the Internet host address from the IPv4 numbers-and-dots notation into binary form...
in_addr_t inet_addr(FAR const char *cp)
Convert the Internet host address from the IPv4 numbers-and-dots notation into binary data in network...
uint32_t ntohl(uint32_t nl)
Convert the unsigned integer netlong from network byte order to host byte order.