jdk/src/solaris/native/java/net/net_util_md.h
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 2938 b3338e271fcb
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <sys/socket.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <netdb.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <netinet/in.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <unistd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#ifndef USE_SELECT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <sys/poll.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
extern int NET_Timeout(int s, long timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
extern int NET_Read(int s, void* buf, size_t len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
extern int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
       struct sockaddr *from, int *fromlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
extern int NET_ReadV(int s, const struct iovec * vector, int count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
extern int NET_Send(int s, void *msg, int len, unsigned int flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
extern int NET_SendTo(int s, const void *msg, int len,  unsigned  int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
       flags, const struct sockaddr *to, int tolen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
extern int NET_Writev(int s, const struct iovec * vector, int count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
extern int NET_Connect(int s, struct sockaddr *addr, int addrlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
extern int NET_Accept(int s, struct sockaddr *addr, int *addrlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
extern int NET_SocketClose(int s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
extern int NET_Dup2(int oldfd, int newfd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#ifdef USE_SELECT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
extern int NET_Select(int s, fd_set *readfds, fd_set *writefds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
               fd_set *exceptfds, struct timeval *timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
extern int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#define NET_Timeout     JVM_Timeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#define NET_Read        JVM_Read
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#define NET_RecvFrom    JVM_RecvFrom
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#define NET_ReadV       readv
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#define NET_Send        JVM_Send
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#define NET_SendTo      JVM_SendTo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#define NET_WriteV      writev
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#define NET_Connect     JVM_Connect
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
#define NET_Accept      JVM_Accept
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
#define NET_SocketClose JVM_SocketClose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
#define NET_Dup2        dup2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
#define NET_Select      select
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
#define NET_Poll        poll
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
#if defined(__linux__) && defined(AF_INET6)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
int getDefaultIPv6Interface(struct in6_addr *target_addr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
/* needed from libsocket on Solaris 8 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
typedef int (*getaddrinfo_f)(const char *nodename, const char  *servname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     const struct addrinfo *hints, struct addrinfo **res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
typedef void (*freeaddrinfo_f)(struct addrinfo *);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
typedef int (*getnameinfo_f)(const struct sockaddr *, size_t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    char *, size_t, char *, size_t, int);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
extern getaddrinfo_f getaddrinfo_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
extern freeaddrinfo_f freeaddrinfo_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
extern getnameinfo_f getnameinfo_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
/* do we have address translation support */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
extern jboolean NET_addrtransAvailable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
#define NET_WAIT_READ   0x01
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
#define NET_WAIT_WRITE  0x02
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
#define NET_WAIT_CONNECT        0x04
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
extern jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * Macros and constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * Its safe to increase the buffer to 8K, this gives a 5-20%
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * performance boost on volano and overall socket performance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
#define MAX_BUFFER_LEN 8192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
#define MAX_HEAP_BUFFER_LEN 65536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
#ifdef AF_INET6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
#define SOCKADDR        union { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                            struct sockaddr_in him4; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                            struct sockaddr_in6 him6; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
#define SOCKADDR_LEN    (ipv6_available() ? sizeof(SOCKADDR) : \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                         sizeof(struct sockaddr_in))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
#define SOCKADDR        union { struct sockaddr_in him4 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
#define SOCKADDR_LEN    sizeof(SOCKADDR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 *  Utilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
extern int kernelIsV22();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
extern int kernelIsV24();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                   const char *defaultDetail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
#endif /* NET_UTILS_MD_H */