jdk/src/java.base/windows/native/libnet/net_util_md.h
author alanb
Tue, 23 Feb 2016 17:41:00 +0000
changeset 36115 0676e37a0b9c
parent 25859 3317bb8137f4
child 41210 73593ed418ff
permissions -rw-r--r--
6432031: Add support for SO_REUSEPORT Reviewed-by: alanb, simonis, chegar Contributed-by: yingqi.lu@intel.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 18192
diff changeset
     2
 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5456
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5456
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5456
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5456
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5456
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <winsock2.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <WS2tcpip.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/* typedefs that were defined correctly for the first time
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * in Nov. 2001 SDK, which we need to include here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Specifically, in6_addr and sockaddr_in6 (which is defined but
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * not correctly). When moving to a later SDK remove following
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * code between START and END
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/* --- START --- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/* WIN64 already uses newer SDK */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#ifdef _WIN64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#define SOCKADDR_IN6 sockaddr_in6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#ifdef _MSC_VER
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#define WS2TCPIP_INLINE __inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#define WS2TCPIP_INLINE extern inline /* GNU style */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#if defined(_MSC_VER) && _MSC_VER >= 1310
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#define SOCKADDR_IN6 sockaddr_in6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
    57
/*SO_REUSEPORT is not supported on Windows, define it to 0*/
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
    58
#define SO_REUSEPORT 0
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
    59
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
/* Retain this code a little longer to support building in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * old environments.  _MSC_VER is defined as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *     1200 for MSVC++ 6.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *     1310 for Vc7
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#define IPPROTO_IPV6    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#define IPV6_MULTICAST_IF 9
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
struct in6_addr {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    union {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        u_char Byte[16];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        u_short Word[8];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    } u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
** Defines to match RFC 2553.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
#define _S6_un     u
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
#define _S6_u8     Byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
#define s6_addr    _S6_un._S6_u8
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
** Defines for our implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
#define s6_bytes   u.Byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
#define s6_words   u.Word
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
/* IPv6 socket address structure, RFC 2553 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
struct SOCKADDR_IN6 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        short   sin6_family;    /* AF_INET6 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        u_short sin6_port;      /* Transport level port number */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        u_long  sin6_flowinfo;  /* IPv6 flow information */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        struct in6_addr sin6_addr; /* IPv6 address */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        u_long sin6_scope_id;  /* set of interfaces for a scope */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
/* Error codes from getaddrinfo() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
#define EAI_AGAIN       WSATRY_AGAIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
#define EAI_BADFLAGS    WSAEINVAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
#define EAI_FAIL        WSANO_RECOVERY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
#define EAI_FAMILY      WSAEAFNOSUPPORT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
#define EAI_MEMORY      WSA_NOT_ENOUGH_MEMORY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
//#define EAI_NODATA      WSANO_DATA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
#define EAI_NONAME      WSAHOST_NOT_FOUND
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
#define EAI_SERVICE     WSATYPE_NOT_FOUND
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
#define EAI_SOCKTYPE    WSAESOCKTNOSUPPORT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
#define EAI_NODATA      EAI_NONAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
/* Structure used in getaddrinfo() call */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
typedef struct addrinfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    int ai_flags;              /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    int ai_family;             /* PF_xxx */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    int ai_socktype;           /* SOCK_xxx */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    int ai_protocol;           /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    size_t ai_addrlen;         /* Length of ai_addr */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    char *ai_canonname;        /* Canonical name for nodename */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    struct sockaddr *ai_addr;  /* Binary address */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    struct addrinfo *ai_next;  /* Next structure in linked list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
} ADDRINFO, FAR * LPADDRINFO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
/* Flags used in "hints" argument to getaddrinfo() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
#define AI_PASSIVE     0x1  /* Socket address will be used in bind() call */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
#define AI_CANONNAME   0x2  /* Return canonical name in first ai_canonname */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
#define AI_NUMERICHOST 0x4  /* Nodename must be a numeric address string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
/* IPv6 Multicasting definitions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
/* Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
typedef struct ipv6_mreq {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    struct in6_addr ipv6mr_multiaddr;  /* IPv6 multicast address */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    unsigned int    ipv6mr_interface;  /* Interface index */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
} IPV6_MREQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
#define IPV6_ADD_MEMBERSHIP     12 /* Add an IP group membership */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
#define IPV6_DROP_MEMBERSHIP    13 /* Drop an IP group membership */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
#define IPV6_MULTICAST_LOOP     11 /* Set/get IP multicast loopback */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
WS2TCPIP_INLINE int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
IN6_IS_ADDR_MULTICAST(const struct in6_addr *a)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    return (a->s6_bytes[0] == 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
WS2TCPIP_INLINE int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
IN6_IS_ADDR_LINKLOCAL(const struct in6_addr *a)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    return (a->s6_bytes[0] == 0xfe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            && a->s6_bytes[1] == 0x80);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
#define NI_MAXHOST  1025  /* Max size of a fully-qualified domain name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
#define NI_MAXSERV    32  /* Max size of a service name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
#define INET_ADDRSTRLEN  16 /* Max size of numeric form of IPv4 address */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
#define INET6_ADDRSTRLEN 46 /* Max size of numeric form of IPv6 address */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
/* Flags for getnameinfo() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
#define NI_NOFQDN       0x01  /* Only return nodename portion for local hosts */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
#define NI_NUMERICHOST  0x02  /* Return numeric form of the host's address */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
#define NI_NAMEREQD     0x04  /* Error if the host's name not in DNS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
#define NI_NUMERICSERV  0x08  /* Return numeric form of the service (port #) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
#define NI_DGRAM        0x10  /* Service is a datagram service */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
#define IN6_IS_ADDR_V4MAPPED(a) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    (((a)->s6_words[0] == 0) && ((a)->s6_words[1] == 0) &&      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    ((a)->s6_words[2] == 0) && ((a)->s6_words[3] == 0) &&       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    ((a)->s6_words[4] == 0) && ((a)->s6_words[5] == 0xffff))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
/* --- END --- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
#endif /* end 'else older build environment' */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
#if !INCL_WINSOCK_API_TYPEDEFS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
typedef
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
(WSAAPI * LPFN_GETADDRINFO)(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    IN const char FAR * nodename,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    IN const char FAR * servname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    IN const struct addrinfo FAR * hints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    OUT struct addrinfo FAR * FAR * res
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
typedef
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
(WSAAPI * LPFN_FREEADDRINFO)(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    IN struct addrinfo FAR * ai
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
typedef
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
(WSAAPI * LPFN_GETNAMEINFO)(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    IN  const struct sockaddr FAR * sa,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    IN  int             salen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    OUT char FAR *      host,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    IN  DWORD           hostlen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    OUT char FAR *      serv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    IN  DWORD           servlen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    IN  int             flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
/* used to disable connection reset messages on Windows XP */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
#ifndef SIO_UDP_CONNRESET
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
#define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
#ifndef IN6_IS_ADDR_ANY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
#define IN6_IS_ADDR_ANY(a)      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    (((a)->s6_words[0] == 0) && ((a)->s6_words[1] == 0) &&      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    ((a)->s6_words[2] == 0) && ((a)->s6_words[3] == 0) &&       \
5456
40ff273941a2 6718504: IN6_IS_ADDR_ANY tests only 12 bytes of 16-byte address
chegar
parents: 1247
diff changeset
   224
    ((a)->s6_words[4] == 0) && ((a)->s6_words[5] == 0) &&       \
40ff273941a2 6718504: IN6_IS_ADDR_ANY tests only 12 bytes of 16-byte address
chegar
parents: 1247
diff changeset
   225
    ((a)->s6_words[6] == 0) && ((a)->s6_words[7] == 0))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
#ifndef IPV6_V6ONLY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
#define IPV6_V6ONLY     27 /* Treat wildcard bind as AF_INET6-only. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
#include "java_io_FileDescriptor.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
#include "java_net_SocketOptions.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
#define MAX_BUFFER_LEN          2048
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
#define MAX_HEAP_BUFFER_LEN     65536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
/* true if SO_RCVTIMEO is supported by underlying provider */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
extern jboolean isRcvTimeoutSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
void NET_ThrowCurrent(JNIEnv *env, char *msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 * Return default Type Of Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
int NET_GetDefaultTOS(void);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
typedef union {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    struct sockaddr     him;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    struct sockaddr_in  him4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    struct SOCKADDR_IN6 him6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
} SOCKETADDRESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 * passed to NET_BindV6. Both ipv4_fd and ipv6_fd must be created and unbound
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 * sockets. On return they may refer to different sockets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
struct ipv6bind {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    SOCKETADDRESS       *addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    SOCKET               ipv4_fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    SOCKET               ipv6_fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
#define SOCKETADDRESS_LEN(X)    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        (((X)->him.sa_family==AF_INET6)? sizeof(struct SOCKADDR_IN6) : \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                         sizeof(struct sockaddr_in))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
#define SOCKETADDRESS_COPY(DST,SRC) {                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    if ((SRC)->sa_family == AF_INET6) {                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        memcpy ((DST), (SRC), sizeof (struct SOCKADDR_IN6));    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    } else {                                                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        memcpy ((DST), (SRC), sizeof (struct sockaddr_in));     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }                                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
#define SET_PORT(X,Y) {                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    if ((X)->him.sa_family == AF_INET) {        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        (X)->him4.sin_port = (Y);               \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    } else {                                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        (X)->him6.sin6_port = (Y);              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
#define GET_PORT(X) ((X)->him.sa_family==AF_INET ?(X)->him4.sin_port: (X)->him6.sin6_port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
#define IS_LOOPBACK_ADDRESS(x) ( \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    ((x)->him.sa_family == AF_INET) ? \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        (ntohl((x)->him4.sin_addr.s_addr)==INADDR_LOOPBACK) : \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        (IN6ADDR_ISLOOPBACK (x)) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
JNIEXPORT int JNICALL NET_SocketClose(int fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
JNIEXPORT int JNICALL NET_Timeout(int fd, long timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
910
1f53246fb014 6729881: Compiler warning in networking native code
chegar
parents: 2
diff changeset
   297
int NET_Socket(int domain, int type, int protocol);
1f53246fb014 6729881: Compiler warning in networking native code
chegar
parents: 2
diff changeset
   298
1f53246fb014 6729881: Compiler warning in networking native code
chegar
parents: 2
diff changeset
   299
void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
1f53246fb014 6729881: Compiler warning in networking native code
chegar
parents: 2
diff changeset
   300
         const char *defaultDetail);
1f53246fb014 6729881: Compiler warning in networking native code
chegar
parents: 2
diff changeset
   301
1f53246fb014 6729881: Compiler warning in networking native code
chegar
parents: 2
diff changeset
   302
void NET_ThrowSocketException(JNIEnv *env, char* msg);
1f53246fb014 6729881: Compiler warning in networking native code
chegar
parents: 2
diff changeset
   303
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 * differs from NET_Timeout() as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
 * If timeout = -1, it blocks forever.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
 * returns 1 or 2 depending if only one or both sockets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
 * fire at same time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
 * *fdret is (one of) the active fds. If both sockets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
 * fire at same time, *fd == fd always.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
JNIEXPORT int JNICALL NET_Timeout2(int fd, int fd1, long timeout, int *fdret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   317
JNIEXPORT int JNICALL NET_BindV6(struct ipv6bind* b, jboolean exclBind);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
#define NET_WAIT_READ   0x01
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
#define NET_WAIT_WRITE  0x02
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
#define NET_WAIT_CONNECT        0x04
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
extern jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   325
JNIEXPORT int JNICALL NET_WinBind(int s, struct sockaddr *him, int len,
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   326
                                   jboolean exclBind);
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   327
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
/* XP versions of the native routines */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    (JNIEnv *env, jclass cls, jstring name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
1097
af4930f761df 6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents: 910
diff changeset
   333
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByIndex0_XP
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
  (JNIEnv *env, jclass cls, jint index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    (JNIEnv *env, jclass cls, jobject iaObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
JNIEXPORT jobjectArray JNICALL Java_java_net_NetworkInterface_getAll_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    (JNIEnv *env, jclass cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_supportsMulticast0_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
(JNIEnv *env, jclass cls, jstring name, jint index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isUp0_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
(JNIEnv *env, jclass cls, jstring name, jint index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isP2P0_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
(JNIEnv *env, jclass cls, jstring name, jint index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
(JNIEnv *env, jclass cls, jstring name, jint index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
(JNIEnv *env, jclass class, jstring name, jint index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isLoopback0_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
(JNIEnv *env, jclass cls, jstring name, jint index);
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
   359