TizenRT Libs&Environment  v2.0 M2
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 
117 /****************************************************************************
118  * Public Function Prototypes
119  ****************************************************************************/
120 
121 #ifdef __cplusplus
122 #define EXTERN extern "C"
123 extern "C"
124 {
125 #else
126 #define EXTERN extern
127 #endif
128 
129 /* Functions to convert between nost and network byte ordering */
130 
140 uint32_t ntohl(uint32_t nl);
141 
151 uint16_t ntohs(uint16_t ns);
152 
162 uint32_t htonl(uint32_t hl);
163 
173 uint16_t htons(uint16_t hs);
174 
175 /* Functions to manipulate address representations */
185 int inet_aton(FAR const char *cp, FAR struct in_addr *inp);
186 
196 in_addr_t inet_addr(FAR const char *cp);
197 
199 in_addr_t inet_network(FAR const char *cp);
201 
202 #ifdef CONFIG_CAN_PASS_STRUCTS
203 
212 FAR char *inet_ntoa(struct in_addr in);
213 
215 in_addr_t inet_lnaof(struct in_addr in);
216 in_addr_t inet_netof(struct in_addr in);
218 #else
219 FAR char *_inet_ntoa(in_addr_t in);
221 # define inet_ntoa(in) _inet_ntoa(in.s_addr);
222 
223 in_addr_t _inet_lnaof(in_addr_t in);
224 # define inet_lnaof(in) _inet_lnaof(in.s_addr);
225 
226 in_addr_t _inet_netof(in_addr_t in);
227 # define inet_netof(in) _inet_netof(in.s_addr);
228 #endif
230 struct in_addr inet_makeaddr(in_addr_t net, in_addr_t host);
232 
233 int inet_pton(int af, FAR const char *src, FAR void *dst);
234 const char *inet_ntop(int af, FAR const void *src, FAR char *dst, socklen_t size);
236 
237 #undef EXTERN
238 #ifdef __cplusplus
239 }
240 #endif
241 
242 #endif /* __INCLUDE_ARPA_INET_H */
243 // 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...
FAR char * inet_ntoa(struct in_addr in)
Convert the Internet host address to a string in IPv4 dotted-decimal notation.
uint32_t ntohl(uint32_t nl)
Convert the unsigned integer netlong from network byte order to host byte order.