1/* $NetBSD: net.h,v 1.2.6.1 2012/06/05 21:15:52 bouyer Exp $ */ 2 3/* 4 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC") 5 * Copyright (C) 2000-2002 Internet Software Consortium. 6 * 7 * Permission to use, copy, modify, and/or distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20/* Id: net.h,v 1.9 2007/06/19 23:47:23 tbox Exp */ 21 22#ifndef LWRES_NET_H 23#define LWRES_NET_H 1 24 25/***** 26 ***** Module Info 27 *****/ 28 29/*! \file net.h 30 * This module is responsible for defining the following basic networking 31 * types: 32 * 33 *\li struct in_addr 34 *\li struct in6_addr 35 *\li struct sockaddr 36 *\li struct sockaddr_in 37 *\li struct sockaddr_in6 38 * 39 * It ensures that the AF_ and PF_ macros are defined. 40 * 41 * It declares ntoh[sl]() and hton[sl](). 42 * 43 * It declares lwres_net_aton(), lwres_net_ntop(), and lwres_net_pton(). 44 * 45 * It ensures that #INADDR_LOOPBACK, #INADDR_ANY and #IN6ADDR_ANY_INIT 46 * are defined. 47 */ 48 49/*** 50 *** Imports. 51 ***/ 52 53#include <lwres/platform.h> /* Required for LWRES_PLATFORM_*. */ 54 55#include <unistd.h> 56#include <sys/types.h> 57#include <sys/socket.h> /* Contractual promise. */ 58#include <sys/ioctl.h> 59#include <sys/time.h> 60#include <sys/un.h> 61 62#include <netinet/in.h> /* Contractual promise. */ 63#include <arpa/inet.h> /* Contractual promise. */ 64#ifdef LWRES_PLATFORM_NEEDNETINETIN6H 65#include <netinet/in6.h> /* Required on UnixWare. */ 66#endif 67#ifdef LWRES_PLATFORM_NEEDNETINET6IN6H 68#include <netinet6/in6.h> /* Required on BSD/OS for in6_pktinfo. */ 69#endif 70#include <net/if.h> 71 72#include <lwres/lang.h> 73 74#ifndef LWRES_PLATFORM_HAVEIPV6 75#include <lwres/ipv6.h> /* Contractual promise. */ 76#endif 77 78#ifdef LWRES_PLATFORM_HAVEINADDR6 79#define in6_addr in_addr6 /* Required for pre RFC2133 implementations. */ 80#endif 81 82/*! 83 * Required for some pre RFC2133 implementations. 84 * IN6ADDR_ANY_INIT and IN6ADDR_LOOPBACK_INIT were added in 85 * draft-ietf-ipngwg-bsd-api-04.txt or draft-ietf-ipngwg-bsd-api-05.txt. 86 * If 's6_addr' is defined then assume that there is a union and three 87 * levels otherwise assume two levels required. 88 */ 89#ifndef IN6ADDR_ANY_INIT 90#ifdef s6_addr 91#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } } 92#else 93#define IN6ADDR_ANY_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } 94#endif 95#endif 96 97/*! 98 * Initialize address loopback. See IN6ADDR_ANY_INIT 99 */ 100#ifndef IN6ADDR_LOOPBACK_INIT 101#ifdef s6_addr 102#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } } 103#else 104#define IN6ADDR_LOOPBACK_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } 105#endif 106#endif 107 108/*% Used by AI_ALL */ 109#ifndef AF_INET6 110#define AF_INET6 99 111#endif 112 113 114/*% Used to return IPV6 address types. */ 115#ifndef PF_INET6 116#define PF_INET6 AF_INET6 117#endif 118 119/*% inaddr Loopback */ 120#ifndef INADDR_LOOPBACK 121#define INADDR_LOOPBACK 0x7f000001UL 122#endif 123 124LWRES_LANG_BEGINDECLS 125 126const char * 127lwres_net_ntop(int af, const void *src, char *dst, size_t size); 128 129int 130lwres_net_pton(int af, const char *src, void *dst); 131 132int 133lwres_net_aton(const char *cp, struct in_addr *addr); 134 135LWRES_LANG_ENDDECLS 136 137#endif /* LWRES_NET_H */ 138