1135446Strhodes/*
2254897Serwin * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
3135446Strhodes * Copyright (C) 2000-2002  Internet Software Consortium.
4135446Strhodes *
5193149Sdougb * Permission to use, copy, modify, and/or distribute this software for any
6135446Strhodes * purpose with or without fee is hereby granted, provided that the above
7135446Strhodes * copyright notice and this permission notice appear in all copies.
8135446Strhodes *
9135446Strhodes * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10135446Strhodes * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11135446Strhodes * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12135446Strhodes * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13135446Strhodes * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14135446Strhodes * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15135446Strhodes * PERFORMANCE OF THIS SOFTWARE.
16135446Strhodes */
17135446Strhodes
18254897Serwin/* $Id: net.h,v 1.9 2007/06/19 23:47:23 tbox Exp $ */
19135446Strhodes
20135446Strhodes#ifndef LWRES_NET_H
21135446Strhodes#define LWRES_NET_H 1
22135446Strhodes
23135446Strhodes/*****
24135446Strhodes ***** Module Info
25135446Strhodes *****/
26135446Strhodes
27170222Sdougb/*! \file net.h
28135446Strhodes * This module is responsible for defining the following basic networking
29135446Strhodes * types:
30135446Strhodes *
31170222Sdougb *\li		struct in_addr
32170222Sdougb *\li		struct in6_addr
33170222Sdougb *\li		struct sockaddr
34170222Sdougb *\li		struct sockaddr_in
35170222Sdougb *\li		struct sockaddr_in6
36135446Strhodes *
37135446Strhodes * It ensures that the AF_ and PF_ macros are defined.
38135446Strhodes *
39135446Strhodes * It declares ntoh[sl]() and hton[sl]().
40135446Strhodes *
41135446Strhodes * It declares lwres_net_aton(), lwres_net_ntop(), and lwres_net_pton().
42135446Strhodes *
43170222Sdougb * It ensures that #INADDR_LOOPBACK, #INADDR_ANY and #IN6ADDR_ANY_INIT
44135446Strhodes * are defined.
45135446Strhodes */
46135446Strhodes
47135446Strhodes/***
48135446Strhodes *** Imports.
49135446Strhodes ***/
50135446Strhodes
51135446Strhodes#include <lwres/platform.h>	/* Required for LWRES_PLATFORM_*. */
52135446Strhodes
53135446Strhodes#include <unistd.h>
54135446Strhodes#include <sys/types.h>
55135446Strhodes#include <sys/socket.h>		/* Contractual promise. */
56135446Strhodes#include <sys/ioctl.h>
57135446Strhodes#include <sys/time.h>
58135446Strhodes#include <sys/un.h>
59135446Strhodes
60135446Strhodes#include <netinet/in.h>		/* Contractual promise. */
61135446Strhodes#include <arpa/inet.h>		/* Contractual promise. */
62135446Strhodes#ifdef LWRES_PLATFORM_NEEDNETINETIN6H
63135446Strhodes#include <netinet/in6.h>	/* Required on UnixWare. */
64135446Strhodes#endif
65135446Strhodes#ifdef LWRES_PLATFORM_NEEDNETINET6IN6H
66135446Strhodes#include <netinet6/in6.h>	/* Required on BSD/OS for in6_pktinfo. */
67135446Strhodes#endif
68254897Serwin#include <net/if.h>
69135446Strhodes
70135446Strhodes#include <lwres/lang.h>
71135446Strhodes
72135446Strhodes#ifndef LWRES_PLATFORM_HAVEIPV6
73135446Strhodes#include <lwres/ipv6.h>		/* Contractual promise. */
74135446Strhodes#endif
75135446Strhodes
76135446Strhodes#ifdef LWRES_PLATFORM_HAVEINADDR6
77135446Strhodes#define in6_addr in_addr6	/* Required for pre RFC2133 implementations. */
78135446Strhodes#endif
79135446Strhodes
80170222Sdougb/*!
81135446Strhodes * Required for some pre RFC2133 implementations.
82135446Strhodes * IN6ADDR_ANY_INIT and IN6ADDR_LOOPBACK_INIT were added in
83254897Serwin * draft-ietf-ipngwg-bsd-api-04.txt or draft-ietf-ipngwg-bsd-api-05.txt.
84135446Strhodes * If 's6_addr' is defined then assume that there is a union and three
85135446Strhodes * levels otherwise assume two levels required.
86135446Strhodes */
87135446Strhodes#ifndef IN6ADDR_ANY_INIT
88135446Strhodes#ifdef s6_addr
89135446Strhodes#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
90135446Strhodes#else
91135446Strhodes#define IN6ADDR_ANY_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } }
92135446Strhodes#endif
93135446Strhodes#endif
94135446Strhodes
95170222Sdougb/*!
96170222Sdougb * Initialize address loopback.  See IN6ADDR_ANY_INIT
97170222Sdougb */
98135446Strhodes#ifndef IN6ADDR_LOOPBACK_INIT
99135446Strhodes#ifdef s6_addr
100135446Strhodes#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
101135446Strhodes#else
102135446Strhodes#define IN6ADDR_LOOPBACK_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } }
103135446Strhodes#endif
104135446Strhodes#endif
105135446Strhodes
106170222Sdougb/*% Used by AI_ALL */
107135446Strhodes#ifndef AF_INET6
108135446Strhodes#define AF_INET6 99
109135446Strhodes#endif
110135446Strhodes
111170222Sdougb
112170222Sdougb/*% Used to return IPV6 address types. */
113135446Strhodes#ifndef PF_INET6
114135446Strhodes#define PF_INET6 AF_INET6
115135446Strhodes#endif
116135446Strhodes
117170222Sdougb/*% inaddr Loopback */
118135446Strhodes#ifndef INADDR_LOOPBACK
119135446Strhodes#define INADDR_LOOPBACK 0x7f000001UL
120135446Strhodes#endif
121135446Strhodes
122135446StrhodesLWRES_LANG_BEGINDECLS
123135446Strhodes
124135446Strhodesconst char *
125135446Strhodeslwres_net_ntop(int af, const void *src, char *dst, size_t size);
126135446Strhodes
127135446Strhodesint
128135446Strhodeslwres_net_pton(int af, const char *src, void *dst);
129135446Strhodes
130135446Strhodesint
131135446Strhodeslwres_net_aton(const char *cp, struct in_addr *addr);
132135446Strhodes
133135446StrhodesLWRES_LANG_ENDDECLS
134135446Strhodes
135135446Strhodes#endif /* LWRES_NET_H */
136