net.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 1999-2005, 2007-2009, 2011-2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id$ */
#include <config.h>
#include <errno.h>
#include <unistd.h>
#include <isc/strerror.h>
/*%
* Definitions about UDP port range specification. This is a total mess of
* portability variants: some use sysctl (but the sysctl names vary), some use
* system-specific interfaces, some have the same interface for IPv4 and IPv6,
* some separate them, etc...
*/
/*%
* The last resort defaults: use all non well known port space
*/
#ifndef ISC_NET_PORTRANGELOW
#define ISC_NET_PORTRANGELOW 1024
#endif /* ISC_NET_PORTRANGELOW */
#ifndef ISC_NET_PORTRANGEHIGH
#define ISC_NET_PORTRANGEHIGH 65535
#endif /* ISC_NET_PORTRANGEHIGH */
#if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRANY)
#endif
void InitSockets(void);
static isc_result_t
SOCKET s;
char strbuf[ISC_STRERRORSIZE];
int errval;
if (s == INVALID_SOCKET) {
errval = WSAGetLastError();
switch (errval) {
case WSAEAFNOSUPPORT:
case WSAEPROTONOSUPPORT:
case WSAEINVAL:
return (ISC_R_NOTFOUND);
default:
"socket() %s: %s",
"failed"),
strbuf);
return (ISC_R_UNEXPECTED);
}
}
closesocket(s);
return (ISC_R_SUCCESS);
}
static void
initialize_action(void) {
InitSockets();
#ifdef ISC_PLATFORM_HAVEIPV6
#ifdef WANT_IPV6
#ifdef ISC_PLATFORM_HAVEIN6PKTINFO
#endif
#endif
#endif
}
static void
initialize(void) {
}
isc_net_probeipv4(void) {
initialize();
return (ipv4_result);
}
isc_net_probeipv6(void) {
initialize();
return (ipv6_result);
}
isc_net_probeunix(void) {
return (ISC_R_NOTFOUND);
}
#ifdef ISC_PLATFORM_HAVEIPV6
#ifdef WANT_IPV6
static void
try_ipv6only(void) {
#ifdef IPV6_V6ONLY
SOCKET s;
int on;
char strbuf[ISC_STRERRORSIZE];
#endif
result = isc_net_probeipv6();
if (result != ISC_R_SUCCESS) {
return;
}
#ifndef IPV6_V6ONLY
return;
#else
/* check for TCP sockets */
if (s == INVALID_SOCKET) {
"socket() %s: %s",
"failed"),
strbuf);
return;
}
on = 1;
sizeof(on)) < 0) {
goto close;
}
closesocket(s);
/* check for UDP sockets */
if (s == INVALID_SOCKET) {
"socket() %s: %s",
"failed"),
strbuf);
return;
}
on = 1;
sizeof(on)) < 0) {
goto close;
}
closesocket(s);
return;
#endif /* IPV6_V6ONLY */
}
static void
initialize_ipv6only(void) {
try_ipv6only) == ISC_R_SUCCESS);
}
#ifdef __notyet__
/*
* WSASendMsg and WSARecvMsg which are themselves Winsock
* and compiler version dependent.
*/
static void
try_ipv6pktinfo(void) {
SOCKET s;
int on;
char strbuf[ISC_STRERRORSIZE];
int optname;
result = isc_net_probeipv6();
if (result != ISC_R_SUCCESS) {
return;
}
/* we only use this for UDP sockets */
if (s == INVALID_SOCKET) {
"socket() %s: %s",
"failed"),
strbuf);
return;
}
#ifdef IPV6_RECVPKTINFO
#else
#endif
on = 1;
sizeof(on)) < 0) {
goto close;
}
closesocket(s);
return;
}
static void
initialize_ipv6pktinfo(void) {
try_ipv6pktinfo) == ISC_R_SUCCESS);
}
#endif /* __notyet__ */
#endif /* WANT_IPV6 */
#endif /* ISC_PLATFORM_HAVEIPV6 */
isc_net_probe_ipv6only(void) {
#ifdef ISC_PLATFORM_HAVEIPV6
#ifdef WANT_IPV6
#else
#endif
#endif
return (ipv6only_result);
}
isc_net_probe_ipv6pktinfo(void) {
#ifdef __notyet__
#ifdef ISC_PLATFORM_HAVEIPV6
#ifdef WANT_IPV6
#else
#endif
#endif
#endif /* __notyet__ */
return (ipv6pktinfo_result);
}
int result = ISC_R_FAILURE;
if (result != ISC_R_SUCCESS) {
}
return (ISC_R_SUCCESS); /* we currently never fail in this function */
}
void
isc_net_disableipv4(void) {
initialize();
if (ipv4_result == ISC_R_SUCCESS)
}
void
isc_net_disableipv6(void) {
initialize();
if (ipv6_result == ISC_R_SUCCESS)
}
void
isc_net_enableipv4(void) {
initialize();
if (ipv4_result == ISC_R_DISABLED)
}
void
isc_net_enableipv6(void) {
initialize();
if (ipv6_result == ISC_R_DISABLED)
}
unsigned int
isc_net_probedscp(void) {
return (0);
}