2
* Copyright (C) 1999-2001 Internet Software Consortium.
4
* Permission to use, copy, modify, and distribute this software for any
5
* purpose with or without fee is hereby granted, provided that the above
6
* copyright notice and this permission notice appear in all copies.
8
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
9
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
10
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
11
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
12
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
13
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
14
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
/* $Id: net.c,v 1.4 2001/11/21 05:07:25 mayer Exp $ */
26
#include <isc/strerror.h>
27
#include <isc/string.h>
30
#if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRANY)
31
const struct in6_addr isc_net_in6addrany = IN6ADDR_ANY_INIT;
34
static isc_boolean_t once = ISC_FALSE;
35
static isc_result_t ipv4_result = ISC_R_NOTFOUND;
36
static isc_result_t ipv6_result = ISC_R_NOTFOUND;
39
try_proto(int domain) {
41
isc_result_t result = ISC_R_SUCCESS;
42
char strbuf[ISC_STRERRORSIZE];
45
s = socket(domain, SOCK_STREAM, 0);
46
if (s == INVALID_SOCKET) {
47
errval = WSAGetLastError();
50
case WSAEPROTONOSUPPORT:
52
return (ISC_R_NOTFOUND);
54
isc__strerror(errval, strbuf, sizeof(strbuf));
55
UNEXPECTED_ERROR(__FILE__, __LINE__,
58
return (ISC_R_UNEXPECTED);
62
#ifdef ISC_PLATFORM_HAVEIPV6
63
#ifdef ISC_PLATFORM_HAVEIN6PKTINFO
64
if (domain == PF_INET6) {
65
struct sockaddr_in6 sin6;
69
* Check to see if IPv6 is broken, as is common on Linux.
72
if (getsockname(s, (struct sockaddr *)&sin6, (void *)&len) < 0)
74
result = ISC_R_NOTFOUND;
76
if (len == sizeof(struct sockaddr_in6))
77
result = ISC_R_SUCCESS;
79
result = ISC_R_NOTFOUND;
92
initialize_action(void) {
93
ipv4_result = try_proto(PF_INET);
94
#ifdef ISC_PLATFORM_HAVEIPV6
95
#ifdef ISC_PLATFORM_HAVEIN6PKTINFO
96
ipv6_result = try_proto(PF_INET6);
103
if(once == ISC_FALSE) {
110
isc_net_probeipv4(void) {
112
return (ipv4_result);
116
isc_net_probeipv6(void) {
118
return (ipv6_result);
121
* Initialize socket services
123
BOOL Win32InitSockets() {
124
WORD wVersionRequested;
128
/* Need Winsock 2.0 or better */
129
wVersionRequested = MAKEWORD(2, 0);
131
err = WSAStartup(wVersionRequested, &wsaData);
133
/* Tell the user that we could not find a usable Winsock DLL */