xref: /freebsd/include/arpa/inet.h (revision 8822d3fb831579a7ebabfce63f469078db325e44)
159deaec5SRodney W. Grimes /*
259deaec5SRodney W. Grimes  * Copyright (c) 1983, 1993
359deaec5SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
459deaec5SRodney W. Grimes  *
559deaec5SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
659deaec5SRodney W. Grimes  * modification, are permitted provided that the following conditions
759deaec5SRodney W. Grimes  * are met:
859deaec5SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
959deaec5SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
1059deaec5SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
1159deaec5SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
1259deaec5SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
1359deaec5SRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
1459deaec5SRodney W. Grimes  *    must display the following acknowledgement:
1559deaec5SRodney W. Grimes  *	This product includes software developed by the University of
1659deaec5SRodney W. Grimes  *	California, Berkeley and its contributors.
1759deaec5SRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
1859deaec5SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
1959deaec5SRodney W. Grimes  *    without specific prior written permission.
2059deaec5SRodney W. Grimes  *
2159deaec5SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2259deaec5SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2359deaec5SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2459deaec5SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2559deaec5SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2659deaec5SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2759deaec5SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2859deaec5SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2959deaec5SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3059deaec5SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3159deaec5SRodney W. Grimes  * SUCH DAMAGE.
32f3f42e96SPeter Wemm  * -
33f3f42e96SPeter Wemm  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
34f3f42e96SPeter Wemm  *
35f3f42e96SPeter Wemm  * Permission to use, copy, modify, and distribute this software for any
36f3f42e96SPeter Wemm  * purpose with or without fee is hereby granted, provided that the above
37f3f42e96SPeter Wemm  * copyright notice and this permission notice appear in all copies, and that
38f3f42e96SPeter Wemm  * the name of Digital Equipment Corporation not be used in advertising or
39f3f42e96SPeter Wemm  * publicity pertaining to distribution of the document or software without
40f3f42e96SPeter Wemm  * specific, written prior permission.
41f3f42e96SPeter Wemm  *
42f3f42e96SPeter Wemm  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
43f3f42e96SPeter Wemm  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
44f3f42e96SPeter Wemm  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
45f3f42e96SPeter Wemm  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
46f3f42e96SPeter Wemm  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
47f3f42e96SPeter Wemm  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
48f3f42e96SPeter Wemm  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
49f3f42e96SPeter Wemm  * SOFTWARE.
50fd8e4ebcSMike Barcroft  *
5159deaec5SRodney W. Grimes  *	@(#)inet.h	8.1 (Berkeley) 6/2/93
520160f9c0SPeter Wemm  *	From: Id: inet.h,v 8.5 1997/01/29 08:48:09 vixie Exp $
53a4add9a9SPeter Wemm  * $FreeBSD$
5459deaec5SRodney W. Grimes  */
5559deaec5SRodney W. Grimes 
56385e380aSPaul Richards #ifndef _ARPA_INET_H_
57385e380aSPaul Richards #define	_ARPA_INET_H_
5859deaec5SRodney W. Grimes 
59ffd1512dSGarrett Wollman /* External definitions for functions in inet(3), addr2ascii(3) */
6059deaec5SRodney W. Grimes 
6159deaec5SRodney W. Grimes #include <sys/cdefs.h>
62de2656d0SMike Barcroft #include <machine/ansi.h>
6359deaec5SRodney W. Grimes 
64fd8e4ebcSMike Barcroft /* Required for byteorder(3) functions. */
65fd8e4ebcSMike Barcroft #include <machine/endian.h>
66fd8e4ebcSMike Barcroft 
676a6230d2SMike Barcroft #ifndef INET_ADDRSTRLEN
686a6230d2SMike Barcroft #define	INET_ADDRSTRLEN		16
696a6230d2SMike Barcroft #endif
706a6230d2SMike Barcroft 
716a6230d2SMike Barcroft #ifndef INET6_ADDRSTRLEN
726a6230d2SMike Barcroft #define	INET6_ADDRSTRLEN	46
736a6230d2SMike Barcroft #endif
746a6230d2SMike Barcroft 
758822d3fbSMike Barcroft #ifndef _UINT16_T_DECLARED
768822d3fbSMike Barcroft typedef	__uint16_t	uint16_t;
778822d3fbSMike Barcroft #define	_UINT16_T_DECLARED
78de2656d0SMike Barcroft #endif
79de2656d0SMike Barcroft 
808822d3fbSMike Barcroft #ifndef _UINT32_T_DECLARED
818822d3fbSMike Barcroft typedef	__uint32_t	uint32_t;
828822d3fbSMike Barcroft #define	_UINT32_T_DECLARED
838822d3fbSMike Barcroft #endif
848822d3fbSMike Barcroft 
858822d3fbSMike Barcroft #ifndef	_IN_ADDR_T_DECLARED
868822d3fbSMike Barcroft typedef	uint32_t	in_addr_t;
878822d3fbSMike Barcroft #define	_IN_ADDR_T_DECLARED
888822d3fbSMike Barcroft #endif
898822d3fbSMike Barcroft 
908822d3fbSMike Barcroft #ifndef	_IN_PORT_T_DECLARED
918822d3fbSMike Barcroft typedef	uint16_t	in_port_t;
928822d3fbSMike Barcroft #define	_IN_PORT_T_DECLARED
93de2656d0SMike Barcroft #endif
94de2656d0SMike Barcroft 
95de2656d0SMike Barcroft #ifndef _POSIX_SOURCE
96de2656d0SMike Barcroft #ifdef	_BSD_SIZE_T_
97de2656d0SMike Barcroft typedef	_BSD_SIZE_T_	size_t;
98de2656d0SMike Barcroft #undef	_BSD_SIZE_T_
99de2656d0SMike Barcroft #endif
100de2656d0SMike Barcroft #endif /* !_POSIX_SOURCE */
101de2656d0SMike Barcroft 
102de2656d0SMike Barcroft /*
1036a6230d2SMike Barcroft  * XXX socklen_t is used by a POSIX.1-2001 interface, but not required by
1046a6230d2SMike Barcroft  * POSIX.1-2001.
105de2656d0SMike Barcroft  */
106de2656d0SMike Barcroft #ifdef	_BSD_SOCKLEN_T_
107de2656d0SMike Barcroft typedef	_BSD_SOCKLEN_T_	socklen_t;
108de2656d0SMike Barcroft #undef	_BSD_SOCKLEN_T_
109de2656d0SMike Barcroft #endif
110de2656d0SMike Barcroft 
111de2656d0SMike Barcroft #ifndef _STRUCT_IN_ADDR_DECLARED
112de2656d0SMike Barcroft struct in_addr {
113de2656d0SMike Barcroft 	in_addr_t s_addr;
114de2656d0SMike Barcroft };
115de2656d0SMike Barcroft #define	_STRUCT_IN_ADDR_DECLARED
116de2656d0SMike Barcroft #endif
117ffd1512dSGarrett Wollman 
1180160f9c0SPeter Wemm /* XXX all new diversions!! argh!! */
119de2656d0SMike Barcroft #ifndef _POSIX_SOURCE
1200160f9c0SPeter Wemm #define	inet_addr	__inet_addr
1210160f9c0SPeter Wemm #define	inet_aton	__inet_aton
1220160f9c0SPeter Wemm #define	inet_lnaof	__inet_lnaof
1230160f9c0SPeter Wemm #define	inet_makeaddr	__inet_makeaddr
1240160f9c0SPeter Wemm #define	inet_neta	__inet_neta
1250160f9c0SPeter Wemm #define	inet_netof	__inet_netof
1260160f9c0SPeter Wemm #define	inet_network	__inet_network
1270160f9c0SPeter Wemm #define	inet_net_ntop	__inet_net_ntop
1280160f9c0SPeter Wemm #define	inet_net_pton	__inet_net_pton
1290160f9c0SPeter Wemm #define	inet_ntoa	__inet_ntoa
1300160f9c0SPeter Wemm #define	inet_pton	__inet_pton
1310160f9c0SPeter Wemm #define	inet_ntop	__inet_ntop
1320160f9c0SPeter Wemm #define	inet_nsap_addr	__inet_nsap_addr
1330160f9c0SPeter Wemm #define	inet_nsap_ntoa	__inet_nsap_ntoa
134de2656d0SMike Barcroft #endif /* !_POSIX_SOURCE */
1350160f9c0SPeter Wemm 
136d846855dSMike Barcroft __BEGIN_DECLS
137d846855dSMike Barcroft #ifndef _BYTEORDER_PROTOTYPED
138d846855dSMike Barcroft #define	_BYTEORDER_PROTOTYPED
1398822d3fbSMike Barcroft uint32_t	 htonl(uint32_t);
1408822d3fbSMike Barcroft uint16_t	 htons(uint16_t);
1418822d3fbSMike Barcroft uint32_t	 ntohl(uint32_t);
1428822d3fbSMike Barcroft uint16_t	 ntohs(uint16_t);
143fd8e4ebcSMike Barcroft #endif
144fd8e4ebcSMike Barcroft 
145bb28f3c2SWarner Losh in_addr_t	 inet_addr(const char *);
146bb28f3c2SWarner Losh char		*inet_ntoa(struct in_addr);
147bb28f3c2SWarner Losh const char	*inet_ntop(int, const void *, char *, socklen_t);
148bb28f3c2SWarner Losh int		 inet_pton(int, const char *, void *);
149de2656d0SMike Barcroft 
150de2656d0SMike Barcroft /* Nonstandard functions. */
151de2656d0SMike Barcroft #ifndef _POSIX_SOURCE
152bb28f3c2SWarner Losh int		 ascii2addr(int, const char *, void *);
153bb28f3c2SWarner Losh char		*addr2ascii(int, const void *, int, char *);
154bb28f3c2SWarner Losh int		 inet_aton(const char *, struct in_addr *);
155bb28f3c2SWarner Losh in_addr_t	 inet_lnaof(struct in_addr);
156bb28f3c2SWarner Losh struct in_addr	 inet_makeaddr(in_addr_t, in_addr_t);
157bb28f3c2SWarner Losh char *		 inet_neta(in_addr_t, char *, size_t);
158bb28f3c2SWarner Losh in_addr_t	 inet_netof(struct in_addr);
159bb28f3c2SWarner Losh in_addr_t	 inet_network(const char *);
160bb28f3c2SWarner Losh char		*inet_net_ntop(int, const void *, int, char *, size_t);
161bb28f3c2SWarner Losh int		 inet_net_pton(int, const char *, void *, size_t);
162bb28f3c2SWarner Losh unsigned	 inet_nsap_addr(const char *, unsigned char *, int);
163bb28f3c2SWarner Losh char		*inet_nsap_ntoa(int, const unsigned char *, char *);
164de2656d0SMike Barcroft #endif /* !_POSIX_SOURCE */
16559deaec5SRodney W. Grimes __END_DECLS
16659deaec5SRodney W. Grimes 
167d846855dSMike Barcroft #ifndef _BYTEORDER_FUNC_DEFINED
168d846855dSMike Barcroft #define	_BYTEORDER_FUNC_DEFINED
169d846855dSMike Barcroft #define	htonl(x)	__htonl(x)
170d846855dSMike Barcroft #define	htons(x)	__htons(x)
171d846855dSMike Barcroft #define	ntohl(x)	__ntohl(x)
172d846855dSMike Barcroft #define	ntohs(x)	__ntohs(x)
173d846855dSMike Barcroft #endif
174d846855dSMike Barcroft 
175de2656d0SMike Barcroft #endif /* !_ARPA_INET_H_ */
176