"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/isc/win32/include/isc/net.h" (4 Sep 2020, 10455 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "net.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 #ifndef ISC_NET_H
   13 #define ISC_NET_H 1
   14 
   15 /*****
   16 ***** Module Info
   17 *****/
   18 
   19 /*
   20  * Basic Networking Types
   21  *
   22  * This module is responsible for defining the following basic networking
   23  * types:
   24  *
   25  *      struct in_addr
   26  *      struct in6_addr
   27  *      struct in6_pktinfo
   28  *      struct sockaddr
   29  *      struct sockaddr_in
   30  *      struct sockaddr_in6
   31  *      in_port_t
   32  *
   33  * It ensures that the AF_ and PF_ macros are defined.
   34  *
   35  * It declares ntoh[sl]() and hton[sl]().
   36  *
   37  * It declares inet_ntop(), and inet_pton().
   38  *
   39  * It ensures that INADDR_ANY, IN6ADDR_ANY_INIT, in6addr_any, and
   40  * in6addr_loopback are available.
   41  *
   42  * It ensures that IN_MULTICAST() is available to check for multicast
   43  * addresses.
   44  *
   45  * MP:
   46  *  No impact.
   47  *
   48  * Reliability:
   49  *  No anticipated impact.
   50  *
   51  * Resources:
   52  *  N/A.
   53  *
   54  * Security:
   55  *  No anticipated impact.
   56  *
   57  * Standards:
   58  *  BSD Socket API
   59  *  RFC2553
   60  */
   61 
   62 /***
   63  *** Imports.
   64  ***/
   65 #include <inttypes.h>
   66 
   67 #include <isc/platform.h>
   68 
   69 /*
   70  * Because of some sort of problem in the MS header files, this cannot
   71  * be simple "#include <winsock2.h>", because winsock2.h tries to include
   72  * windows.h, which then generates an error out of mswsock.h.  _You_
   73  * figure it out.
   74  */
   75 #ifndef _WINSOCKAPI_
   76 #define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */
   77 #endif           /* ifndef _WINSOCKAPI_ */
   78 
   79 #include <winsock2.h>
   80 #include <ws2tcpip.h>
   81 
   82 #include <isc/ipv6.h>
   83 #include <isc/lang.h>
   84 #include <isc/types.h>
   85 
   86 #include <sys/types.h>
   87 
   88 /*
   89  * This is here because named client, interfacemgr.c, etc. use the name as
   90  * a variable
   91  */
   92 #undef interface
   93 
   94 #ifndef INADDR_ANY
   95 #define INADDR_ANY 0x00000000UL
   96 #endif /* ifndef INADDR_ANY */
   97 
   98 #ifndef INADDR_LOOPBACK
   99 #define INADDR_LOOPBACK 0x7f000001UL
  100 #endif /* ifndef INADDR_LOOPBACK */
  101 
  102 #if _MSC_VER < 1300
  103 #define in6addr_any  isc_in6addr_any
  104 #define in6addr_loopback isc_in6addr_loopback
  105 #endif /* if _MSC_VER < 1300 */
  106 
  107 /*
  108  * Ensure type in_port_t is defined.
  109  */
  110 typedef uint16_t in_port_t;
  111 
  112 /*
  113  * If this system does not have MSG_TRUNC (as returned from recvmsg())
  114  * ISC_PLATFORM_RECVOVERFLOW will be defined.  This will enable the MSG_TRUNC
  115  * faking code in socket.c.
  116  */
  117 #ifndef MSG_TRUNC
  118 #define ISC_PLATFORM_RECVOVERFLOW
  119 #endif /* ifndef MSG_TRUNC */
  120 
  121 #define ISC__IPADDR(x) ((uint32_t)htonl((uint32_t)(x)))
  122 
  123 #define ISC_IPADDR_ISMULTICAST(i) \
  124     (((uint32_t)(i)&ISC__IPADDR(0xf0000000)) == ISC__IPADDR(0xe0000000))
  125 
  126 #define ISC_IPADDR_ISEXPERIMENTAL(i) \
  127     (((uint32_t)(i)&ISC__IPADDR(0xf0000000)) == ISC__IPADDR(0xf0000000))
  128 
  129 /*
  130  * Fix the FD_SET and FD_CLR Macros to properly cast
  131  */
  132 #undef FD_CLR
  133 #define FD_CLR(fd, set)                                                        \
  134     do {                                                                   \
  135         u_int __i;                                                     \
  136         for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count; __i++) {  \
  137             if (((fd_set FAR *)(set))->fd_array[__i] ==            \
  138                 (SOCKET)fd) {                                      \
  139                 while (__i <                                   \
  140                        ((fd_set FAR *)(set))->fd_count - 1) {  \
  141                     ((fd_set FAR *)(set))->fd_array[__i] = \
  142                         ((fd_set FAR *)(set))          \
  143                             ->fd_array[__i + 1];   \
  144                     __i++;                                 \
  145                 }                                              \
  146                 ((fd_set FAR *)(set))->fd_count--;             \
  147                 break;                                         \
  148             }                                                      \
  149         }                                                              \
  150     } while (0)
  151 
  152 #undef FD_SET
  153 #define FD_SET(fd, set)                                                       \
  154     do {                                                                  \
  155         u_int __i;                                                    \
  156         for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count; __i++) { \
  157             if (((fd_set FAR *)(set))->fd_array[__i] ==           \
  158                 (SOCKET)(fd)) {                                   \
  159                 break;                                        \
  160             }                                                     \
  161         }                                                             \
  162         if (__i == ((fd_set FAR *)(set))->fd_count) {                 \
  163             if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) {   \
  164                 ((fd_set FAR *)(set))->fd_array[__i] =        \
  165                     (SOCKET)(fd);                         \
  166                 ((fd_set FAR *)(set))->fd_count++;            \
  167             }                                                     \
  168         }                                                             \
  169     } while (0)
  170 
  171 /*
  172  * Windows Sockets errors redefined as regular Berkeley error constants.
  173  * These are usually commented out in Windows NT to avoid conflicts with
  174  * errno.h. Use the WSA constants instead.
  175  */
  176 
  177 #include <errno.h>
  178 
  179 #ifndef EWOULDBLOCK
  180 #define EWOULDBLOCK WSAEWOULDBLOCK
  181 #endif /* ifndef EWOULDBLOCK */
  182 #ifndef EINPROGRESS
  183 #define EINPROGRESS WSAEINPROGRESS
  184 #endif /* ifndef EINPROGRESS */
  185 #ifndef EALREADY
  186 #define EALREADY WSAEALREADY
  187 #endif /* ifndef EALREADY */
  188 #ifndef ENOTSOCK
  189 #define ENOTSOCK WSAENOTSOCK
  190 #endif /* ifndef ENOTSOCK */
  191 #ifndef EDESTADDRREQ
  192 #define EDESTADDRREQ WSAEDESTADDRREQ
  193 #endif /* ifndef EDESTADDRREQ */
  194 #ifndef EMSGSIZE
  195 #define EMSGSIZE WSAEMSGSIZE
  196 #endif /* ifndef EMSGSIZE */
  197 #ifndef EPROTOTYPE
  198 #define EPROTOTYPE WSAEPROTOTYPE
  199 #endif /* ifndef EPROTOTYPE */
  200 #ifndef ENOPROTOOPT
  201 #define ENOPROTOOPT WSAENOPROTOOPT
  202 #endif /* ifndef ENOPROTOOPT */
  203 #ifndef EPROTONOSUPPORT
  204 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
  205 #endif /* ifndef EPROTONOSUPPORT */
  206 #ifndef ESOCKTNOSUPPORT
  207 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
  208 #endif /* ifndef ESOCKTNOSUPPORT */
  209 #ifndef EOPNOTSUPP
  210 #define EOPNOTSUPP WSAEOPNOTSUPP
  211 #endif /* ifndef EOPNOTSUPP */
  212 #ifndef EPFNOSUPPORT
  213 #define EPFNOSUPPORT WSAEPFNOSUPPORT
  214 #endif /* ifndef EPFNOSUPPORT */
  215 #ifndef EAFNOSUPPORT
  216 #define EAFNOSUPPORT WSAEAFNOSUPPORT
  217 #endif /* ifndef EAFNOSUPPORT */
  218 #ifndef EADDRINUSE
  219 #define EADDRINUSE WSAEADDRINUSE
  220 #endif /* ifndef EADDRINUSE */
  221 #ifndef EADDRNOTAVAIL
  222 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
  223 #endif /* ifndef EADDRNOTAVAIL */
  224 #ifndef ENETDOWN
  225 #define ENETDOWN WSAENETDOWN
  226 #endif /* ifndef ENETDOWN */
  227 #ifndef ENETUNREACH
  228 #define ENETUNREACH WSAENETUNREACH
  229 #endif /* ifndef ENETUNREACH */
  230 #ifndef ENETRESET
  231 #define ENETRESET WSAENETRESET
  232 #endif /* ifndef ENETRESET */
  233 #ifndef ECONNABORTED
  234 #define ECONNABORTED WSAECONNABORTED
  235 #endif /* ifndef ECONNABORTED */
  236 #ifndef ECONNRESET
  237 #define ECONNRESET WSAECONNRESET
  238 #endif /* ifndef ECONNRESET */
  239 #ifndef ENOBUFS
  240 #define ENOBUFS WSAENOBUFS
  241 #endif /* ifndef ENOBUFS */
  242 #ifndef EISCONN
  243 #define EISCONN WSAEISCONN
  244 #endif /* ifndef EISCONN */
  245 #ifndef ENOTCONN
  246 #define ENOTCONN WSAENOTCONN
  247 #endif /* ifndef ENOTCONN */
  248 #ifndef ESHUTDOWN
  249 #define ESHUTDOWN WSAESHUTDOWN
  250 #endif /* ifndef ESHUTDOWN */
  251 #ifndef ETOOMANYREFS
  252 #define ETOOMANYREFS WSAETOOMANYREFS
  253 #endif /* ifndef ETOOMANYREFS */
  254 #ifndef ETIMEDOUT
  255 #define ETIMEDOUT WSAETIMEDOUT
  256 #endif /* ifndef ETIMEDOUT */
  257 #ifndef ECONNREFUSED
  258 #define ECONNREFUSED WSAECONNREFUSED
  259 #endif /* ifndef ECONNREFUSED */
  260 #ifndef ELOOP
  261 #define ELOOP WSAELOOP
  262 #endif /* ifndef ELOOP */
  263 #ifndef EHOSTDOWN
  264 #define EHOSTDOWN WSAEHOSTDOWN
  265 #endif /* ifndef EHOSTDOWN */
  266 #ifndef EHOSTUNREACH
  267 #define EHOSTUNREACH WSAEHOSTUNREACH
  268 #endif /* ifndef EHOSTUNREACH */
  269 #ifndef EPROCLIM
  270 #define EPROCLIM WSAEPROCLIM
  271 #endif /* ifndef EPROCLIM */
  272 #ifndef EUSERS
  273 #define EUSERS WSAEUSERS
  274 #endif /* ifndef EUSERS */
  275 #ifndef EDQUOT
  276 #define EDQUOT WSAEDQUOT
  277 #endif /* ifndef EDQUOT */
  278 #ifndef ESTALE
  279 #define ESTALE WSAESTALE
  280 #endif /* ifndef ESTALE */
  281 #ifndef EREMOTE
  282 #define EREMOTE WSAEREMOTE
  283 #endif /* ifndef EREMOTE */
  284 
  285 /***
  286  *** Functions.
  287  ***/
  288 
  289 ISC_LANG_BEGINDECLS
  290 
  291 isc_result_t
  292 isc_net_probeipv4(void);
  293 /*
  294  * Check if the system's kernel supports IPv4.
  295  *
  296  * Returns:
  297  *
  298  *  ISC_R_SUCCESS       IPv4 is supported.
  299  *  ISC_R_NOTFOUND      IPv4 is not supported.
  300  *  ISC_R_DISABLED      IPv4 is disabled.
  301  *  ISC_R_UNEXPECTED
  302  */
  303 
  304 isc_result_t
  305 isc_net_probeipv6(void);
  306 /*
  307  * Check if the system's kernel supports IPv6.
  308  *
  309  * Returns:
  310  *
  311  *  ISC_R_SUCCESS       IPv6 is supported.
  312  *  ISC_R_NOTFOUND      IPv6 is not supported.
  313  *  ISC_R_DISABLED      IPv6 is disabled.
  314  *  ISC_R_UNEXPECTED
  315  */
  316 
  317 isc_result_t
  318 isc_net_probeunix(void);
  319 /*
  320  * Check if UNIX domain sockets are supported.
  321  *
  322  * Returns:
  323  *
  324  *  ISC_R_SUCCESS
  325  *  ISC_R_NOTFOUND
  326  */
  327 
  328 #define ISC_NET_DSCPRECVV4 0x01 /* Can receive sent DSCP value IPv4 */
  329 #define ISC_NET_DSCPRECVV6 0x02 /* Can receive sent DSCP value IPv6 */
  330 #define ISC_NET_DSCPSETV4  0x04 /* Can set DSCP on socket IPv4 */
  331 #define ISC_NET_DSCPSETV6  0x08 /* Can set DSCP on socket IPv6 */
  332 #define ISC_NET_DSCPPKTV4  0x10 /* Can set DSCP on per packet IPv4 */
  333 #define ISC_NET_DSCPPKTV6  0x20 /* Can set DSCP on per packet IPv6 */
  334 #define ISC_NET_DSCPALL    0x3f /* All valid flags */
  335 
  336 unsigned int
  337 isc_net_probedscp(void);
  338 /*%<
  339  * Probe the level of DSCP support.
  340  */
  341 
  342 isc_result_t
  343 isc_net_probe_ipv6only(void);
  344 /*
  345  * Check if the system's kernel supports the IPV6_V6ONLY socket option.
  346  *
  347  * Returns:
  348  *
  349  *  ISC_R_SUCCESS       the option is supported for both TCP and UDP.
  350  *  ISC_R_NOTFOUND      IPv6 itself or the option is not supported.
  351  *  ISC_R_UNEXPECTED
  352  */
  353 
  354 isc_result_t
  355 isc_net_probe_ipv6pktinfo(void);
  356 /*
  357  * Check if the system's kernel supports the IPV6_(RECV)PKTINFO socket option
  358  * for UDP sockets.
  359  *
  360  * Returns:
  361  *
  362  *  ISC_R_SUCCESS       the option is supported.
  363  *  ISC_R_NOTFOUND      IPv6 itself or the option is not supported.
  364  *  ISC_R_UNEXPECTED
  365  */
  366 
  367 void
  368 isc_net_disableipv4(void);
  369 
  370 void
  371 isc_net_disableipv6(void);
  372 
  373 void
  374 isc_net_enableipv4(void);
  375 
  376 void
  377 isc_net_enableipv6(void);
  378 
  379 isc_result_t
  380 isc_net_getudpportrange(int af, in_port_t *low, in_port_t *high);
  381 /*%<
  382  * Returns system's default range of ephemeral UDP ports, if defined.
  383  * If the range is not available or unknown, ISC_NET_PORTRANGELOW and
  384  * ISC_NET_PORTRANGEHIGH will be returned.
  385  *
  386  * Requires:
  387  *
  388  *\li   'low' and 'high' must be non NULL.
  389  *
  390  * Returns:
  391  *
  392  *\li   *low and *high will be the ports specifying the low and high ends of
  393  *  the range.
  394  */
  395 
  396 ISC_LANG_ENDDECLS
  397 
  398 #endif /* ISC_NET_H */