src/java.base/unix/native/libnet/net_util_md.h
author mbaesken
Wed, 26 Sep 2018 14:28:37 +0200
changeset 51878 511a9946f83e
parent 49985 44e581f54d08
child 53422 6f02e036630e
permissions -rw-r--r--
8211146: fix problematic elif-tests after recent gcc warning changes Werror=undef Reviewed-by: stuefe, clanger, dholmes, chegar, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
49985
44e581f54d08 8202181: Correctly specify size of hostname buffer in Unix Inet*AddressImpl_getLocalHostName implementations
clanger
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2018, 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: 4814
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: 4814
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: 4814
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
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
#ifndef NET_UTILS_MD_H
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#define NET_UTILS_MD_H
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
41771
18c9669e76ca 8167481: cleanup of headers and includes for native libnet
clanger
parents: 41380
diff changeset
    29
#include <netdb.h>
46862
cb4b080576fa 8180003: Remove sys/ prefix from poll.h and signal.h includes
mikael
parents: 44921
diff changeset
    30
#include <poll.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <sys/socket.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 40937
diff changeset
    33
/************************************************************************
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 40937
diff changeset
    34
 * Macros and constants
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 40937
diff changeset
    35
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
45061
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
    37
#define NET_NSEC_PER_MSEC 1000000
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
    38
#define NET_NSEC_PER_SEC  1000000000
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
    39
#define NET_NSEC_PER_USEC 1000
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
    40
49985
44e581f54d08 8202181: Correctly specify size of hostname buffer in Unix Inet*AddressImpl_getLocalHostName implementations
clanger
parents: 47216
diff changeset
    41
/* in case NI_MAXHOST is not defined in netdb.h */
44e581f54d08 8202181: Correctly specify size of hostname buffer in Unix Inet*AddressImpl_getLocalHostName implementations
clanger
parents: 47216
diff changeset
    42
#ifndef NI_MAXHOST
44e581f54d08 8202181: Correctly specify size of hostname buffer in Unix Inet*AddressImpl_getLocalHostName implementations
clanger
parents: 47216
diff changeset
    43
#define NI_MAXHOST 1025
44e581f54d08 8202181: Correctly specify size of hostname buffer in Unix Inet*AddressImpl_getLocalHostName implementations
clanger
parents: 47216
diff changeset
    44
#endif
44e581f54d08 8202181: Correctly specify size of hostname buffer in Unix Inet*AddressImpl_getLocalHostName implementations
clanger
parents: 47216
diff changeset
    45
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
    46
/* Defines SO_REUSEPORT */
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
    47
#ifndef SO_REUSEPORT
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
    48
#ifdef __linux__
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
    49
#define SO_REUSEPORT 15
51878
511a9946f83e 8211146: fix problematic elif-tests after recent gcc warning changes Werror=undef
mbaesken
parents: 49985
diff changeset
    50
#elif defined(__solaris__)
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
    51
#define SO_REUSEPORT 0x100e
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
    52
#elif defined(AIX) || defined(MACOSX)
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
    53
#define SO_REUSEPORT 0x0200
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
    54
#else
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
    55
#define SO_REUSEPORT 0
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
    56
#endif
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
    57
#endif
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 25859
diff changeset
    58
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
/*
2938
b3338e271fcb 6807602: Increase MAX_BUFFER_LEN and MAX_HEAP_BUFFER_LEN on 64-bit Solaris and Linux
chegar
parents: 2
diff changeset
    60
 * On 64-bit JDKs we use a much larger stack and heap buffer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
2938
b3338e271fcb 6807602: Increase MAX_BUFFER_LEN and MAX_HEAP_BUFFER_LEN on 64-bit Solaris and Linux
chegar
parents: 2
diff changeset
    62
#ifdef _LP64
b3338e271fcb 6807602: Increase MAX_BUFFER_LEN and MAX_HEAP_BUFFER_LEN on 64-bit Solaris and Linux
chegar
parents: 2
diff changeset
    63
#define MAX_BUFFER_LEN 65536
b3338e271fcb 6807602: Increase MAX_BUFFER_LEN and MAX_HEAP_BUFFER_LEN on 64-bit Solaris and Linux
chegar
parents: 2
diff changeset
    64
#define MAX_HEAP_BUFFER_LEN 131072
b3338e271fcb 6807602: Increase MAX_BUFFER_LEN and MAX_HEAP_BUFFER_LEN on 64-bit Solaris and Linux
chegar
parents: 2
diff changeset
    65
#else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#define MAX_BUFFER_LEN 8192
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#define MAX_HEAP_BUFFER_LEN 65536
2938
b3338e271fcb 6807602: Increase MAX_BUFFER_LEN and MAX_HEAP_BUFFER_LEN on 64-bit Solaris and Linux
chegar
parents: 2
diff changeset
    68
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 40937
diff changeset
    70
typedef union {
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 40937
diff changeset
    71
    struct sockaddr     sa;
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 40937
diff changeset
    72
    struct sockaddr_in  sa4;
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 40937
diff changeset
    73
    struct sockaddr_in6 sa6;
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 40937
diff changeset
    74
} SOCKETADDRESS;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
/************************************************************************
43100
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    77
 * Functions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 */
23033
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
    79
45061
74b09ee3cd55 8179905: Remove the use of gettimeofday in Networking code
vtewari
parents: 44921
diff changeset
    80
int NET_Timeout(JNIEnv *env, int s, long timeout, jlong  nanoTimeStamp);
43100
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    81
int NET_Read(int s, void* buf, size_t len);
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    82
int NET_NonBlockingRead(int s, void* buf, size_t len);
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    83
int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    84
                 struct sockaddr *from, socklen_t *fromlen);
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    85
int NET_ReadV(int s, const struct iovec * vector, int count);
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    86
int NET_Send(int s, void *msg, int len, unsigned int flags);
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    87
int NET_SendTo(int s, const void *msg, int len,  unsigned  int
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    88
               flags, const struct sockaddr *to, int tolen);
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    89
int NET_Writev(int s, const struct iovec * vector, int count);
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    90
int NET_Connect(int s, struct sockaddr *addr, int addrlen);
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    91
int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen);
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    92
int NET_SocketClose(int s);
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    93
int NET_Dup2(int oldfd, int newfd);
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    94
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout);
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    95
int NET_SocketAvailable(int s, jint *pbytes);
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    96
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    97
void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    98
                                               const char* hostname,
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
    99
                                               int gai_error);
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
   100
void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
   101
                                  const char *defaultDetail);
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
   102
void NET_SetTrafficClass(SOCKETADDRESS *sa, int trafficClass);
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41834
diff changeset
   103
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
#ifdef __linux__
23033
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
   105
int kernelIsV24();
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
   106
int getDefaultIPv6Interface(struct in6_addr *target_addr);
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
   107
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
23033
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
   109
#ifdef __solaris__
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
   110
int net_getParam(char *driver, char *param);
0cc7c83fde3c 8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}
simonis
parents: 23028
diff changeset
   111
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
#endif /* NET_UTILS_MD_H */