xref: /freebsd/include/arpa/inet.h (revision bb28f3c29b4c91af1b0e79e456294bb08735648a)
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 
75de2656d0SMike Barcroft #ifndef	_IN_ADDR_T_DECLARED_
76de2656d0SMike Barcroft typedef	__uint32_t	in_addr_t;
77de2656d0SMike Barcroft #define	_IN_ADDR_T_DECLARED_
78de2656d0SMike Barcroft #endif
79de2656d0SMike Barcroft 
80de2656d0SMike Barcroft #ifndef	_IN_PORT_T_DECLARED_
814f25b0aaSMike Barcroft typedef	__uint16_t	in_port_t;
82de2656d0SMike Barcroft #define	_IN_PORT_T_DECLARED_
83de2656d0SMike Barcroft #endif
84de2656d0SMike Barcroft 
85de2656d0SMike Barcroft #ifndef _POSIX_SOURCE
86de2656d0SMike Barcroft #ifdef	_BSD_SIZE_T_
87de2656d0SMike Barcroft typedef	_BSD_SIZE_T_	size_t;
88de2656d0SMike Barcroft #undef	_BSD_SIZE_T_
89de2656d0SMike Barcroft #endif
90de2656d0SMike Barcroft #endif /* !_POSIX_SOURCE */
91de2656d0SMike Barcroft 
92de2656d0SMike Barcroft /*
936a6230d2SMike Barcroft  * XXX socklen_t is used by a POSIX.1-2001 interface, but not required by
946a6230d2SMike Barcroft  * POSIX.1-2001.
95de2656d0SMike Barcroft  */
96de2656d0SMike Barcroft #ifdef	_BSD_SOCKLEN_T_
97de2656d0SMike Barcroft typedef	_BSD_SOCKLEN_T_	socklen_t;
98de2656d0SMike Barcroft #undef	_BSD_SOCKLEN_T_
99de2656d0SMike Barcroft #endif
100de2656d0SMike Barcroft 
101de2656d0SMike Barcroft #ifndef _STRUCT_IN_ADDR_DECLARED
102de2656d0SMike Barcroft struct in_addr {
103de2656d0SMike Barcroft 	in_addr_t s_addr;
104de2656d0SMike Barcroft };
105de2656d0SMike Barcroft #define	_STRUCT_IN_ADDR_DECLARED
106de2656d0SMike Barcroft #endif
107ffd1512dSGarrett Wollman 
1086a6230d2SMike Barcroft /*
1096a6230d2SMike Barcroft  * XXX missing typedefs for uint16_t and uint32_t.
1106a6230d2SMike Barcroft  */
1116a6230d2SMike Barcroft 
1120160f9c0SPeter Wemm /* XXX all new diversions!! argh!! */
113de2656d0SMike Barcroft #ifndef _POSIX_SOURCE
1140160f9c0SPeter Wemm #define	inet_addr	__inet_addr
1150160f9c0SPeter Wemm #define	inet_aton	__inet_aton
1160160f9c0SPeter Wemm #define	inet_lnaof	__inet_lnaof
1170160f9c0SPeter Wemm #define	inet_makeaddr	__inet_makeaddr
1180160f9c0SPeter Wemm #define	inet_neta	__inet_neta
1190160f9c0SPeter Wemm #define	inet_netof	__inet_netof
1200160f9c0SPeter Wemm #define	inet_network	__inet_network
1210160f9c0SPeter Wemm #define	inet_net_ntop	__inet_net_ntop
1220160f9c0SPeter Wemm #define	inet_net_pton	__inet_net_pton
1230160f9c0SPeter Wemm #define	inet_ntoa	__inet_ntoa
1240160f9c0SPeter Wemm #define	inet_pton	__inet_pton
1250160f9c0SPeter Wemm #define	inet_ntop	__inet_ntop
1260160f9c0SPeter Wemm #define	inet_nsap_addr	__inet_nsap_addr
1270160f9c0SPeter Wemm #define	inet_nsap_ntoa	__inet_nsap_ntoa
128de2656d0SMike Barcroft #endif /* !_POSIX_SOURCE */
1290160f9c0SPeter Wemm 
130d846855dSMike Barcroft __BEGIN_DECLS
131d846855dSMike Barcroft #ifndef _BYTEORDER_PROTOTYPED
132d846855dSMike Barcroft #define	_BYTEORDER_PROTOTYPED
133bb28f3c2SWarner Losh __uint32_t	 htonl(__uint32_t);
134bb28f3c2SWarner Losh __uint16_t	 htons(__uint16_t);
135bb28f3c2SWarner Losh __uint32_t	 ntohl(__uint32_t);
136bb28f3c2SWarner Losh __uint16_t	 ntohs(__uint16_t);
137fd8e4ebcSMike Barcroft #endif
138fd8e4ebcSMike Barcroft 
139bb28f3c2SWarner Losh in_addr_t	 inet_addr(const char *);
140bb28f3c2SWarner Losh char		*inet_ntoa(struct in_addr);
141bb28f3c2SWarner Losh const char	*inet_ntop(int, const void *, char *, socklen_t);
142bb28f3c2SWarner Losh int		 inet_pton(int, const char *, void *);
143de2656d0SMike Barcroft 
144de2656d0SMike Barcroft /* Nonstandard functions. */
145de2656d0SMike Barcroft #ifndef _POSIX_SOURCE
146bb28f3c2SWarner Losh int		 ascii2addr(int, const char *, void *);
147bb28f3c2SWarner Losh char		*addr2ascii(int, const void *, int, char *);
148bb28f3c2SWarner Losh int		 inet_aton(const char *, struct in_addr *);
149bb28f3c2SWarner Losh in_addr_t	 inet_lnaof(struct in_addr);
150bb28f3c2SWarner Losh struct in_addr	 inet_makeaddr(in_addr_t, in_addr_t);
151bb28f3c2SWarner Losh char *		 inet_neta(in_addr_t, char *, size_t);
152bb28f3c2SWarner Losh in_addr_t	 inet_netof(struct in_addr);
153bb28f3c2SWarner Losh in_addr_t	 inet_network(const char *);
154bb28f3c2SWarner Losh char		*inet_net_ntop(int, const void *, int, char *, size_t);
155bb28f3c2SWarner Losh int		 inet_net_pton(int, const char *, void *, size_t);
156bb28f3c2SWarner Losh unsigned	 inet_nsap_addr(const char *, unsigned char *, int);
157bb28f3c2SWarner Losh char		*inet_nsap_ntoa(int, const unsigned char *, char *);
158de2656d0SMike Barcroft #endif /* !_POSIX_SOURCE */
15959deaec5SRodney W. Grimes __END_DECLS
16059deaec5SRodney W. Grimes 
161d846855dSMike Barcroft #ifndef _BYTEORDER_FUNC_DEFINED
162d846855dSMike Barcroft #define	_BYTEORDER_FUNC_DEFINED
163d846855dSMike Barcroft #define	htonl(x)	__htonl(x)
164d846855dSMike Barcroft #define	htons(x)	__htons(x)
165d846855dSMike Barcroft #define	ntohl(x)	__ntohl(x)
166d846855dSMike Barcroft #define	ntohs(x)	__ntohs(x)
167d846855dSMike Barcroft #endif
168d846855dSMike Barcroft 
169de2656d0SMike Barcroft #endif /* !_ARPA_INET_H_ */
170