src/java.base/windows/native/libnet/NetworkInterface_winXP.c
author igerasim
Tue, 03 Oct 2017 23:42:08 -0700
changeset 47309 66774e1fc3a7
parent 47216 71c04702a3d5
child 47317 62e749769358
permissions -rw-r--r--
8187658: Bigger buffer for GetAdaptersAddresses Reviewed-by: rriggs, vtewari
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 29376
diff changeset
     2
 * Copyright (c) 2003, 2016, 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: 4811
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: 4811
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: 4811
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4811
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4811
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
41771
18c9669e76ca 8167481: cleanup of headers and includes for native libnet
clanger
parents: 41602
diff changeset
    25
#include "net_util.h"
18c9669e76ca 8167481: cleanup of headers and includes for native libnet
clanger
parents: 41602
diff changeset
    26
#include "NetworkInterface.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "java_net_NetworkInterface.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Windows implementation of the java.net.NetworkInterface native methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * This module provides the implementations of getAll, getByName, getByIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * and getByAddress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
extern int enumAddresses_win(JNIEnv *env, netif *netifP, netaddr **netaddrPP);
910
1f53246fb014 6729881: Compiler warning in networking native code
chegar
parents: 2
diff changeset
    37
int getAddrsFromAdapter(IP_ADAPTER_ADDRESSES *ptr, netaddr **netaddrPP);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
void printnif (netif *nif) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#ifdef _WIN64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        printf ("nif:0x%I64x name:%s\n", nif,nif->name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        printf ("nif:0x%x name:%s\n", nif,nif->name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        if (nif->dNameIsUnicode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            printf ("dName:%S index:%d ", nif->displayName,nif->index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            printf ("dName:%s index:%d ", nif->displayName,nif->index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        printf ("naddrs:%d\n", nif->naddrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
void printnifs (netif *netifPP, char *str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    netif *nif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    printf ("%s\n", str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    for (nif=netifPP; nif!=NULL; nif=nif->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        printnif (nif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    printf("-----------------\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
47309
66774e1fc3a7 8187658: Bigger buffer for GetAdaptersAddresses
igerasim
parents: 47216
diff changeset
    65
const ULONG BUFF_SIZE = 15360;
66774e1fc3a7 8187658: Bigger buffer for GetAdaptersAddresses
igerasim
parents: 47216
diff changeset
    66
const int MAX_TRIES = 3;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * return an array of IP_ADAPTER_ADDRESSES containing one element
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
    70
 * for each adapter on the system. Returned in *adapters.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * Buffer is malloc'd and must be freed (unless error returned)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
static int getAdapters (JNIEnv *env, IP_ADAPTER_ADDRESSES **adapters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    DWORD ret, flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    IP_ADAPTER_ADDRESSES *adapterInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    ULONG len;
28304
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
    77
    char *error_msg_buf = NULL;
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
    78
    size_t error_msg_buf_size =
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
    79
            strlen("IP Helper Library GetAdaptersAddresses function failed"
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
    80
                   " with error == ") + 10;
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
    81
    int _ret = 0;
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
    82
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
    83
47309
66774e1fc3a7 8187658: Bigger buffer for GetAdaptersAddresses
igerasim
parents: 47216
diff changeset
    84
    adapterInfo = (IP_ADAPTER_ADDRESSES *) malloc(BUFF_SIZE);
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
    85
    if (adapterInfo == NULL) {
28304
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
    86
        JNU_ThrowByName(env, "java/lang/OutOfMemoryError",
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
    87
            "Native heap allocation failure");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
    90
47309
66774e1fc3a7 8187658: Bigger buffer for GetAdaptersAddresses
igerasim
parents: 47216
diff changeset
    91
    len = BUFF_SIZE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    flags = GAA_FLAG_SKIP_DNS_SERVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    flags |= GAA_FLAG_SKIP_MULTICAST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    flags |= GAA_FLAG_INCLUDE_PREFIX;
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 7668
diff changeset
    95
    ret = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapterInfo, &len);
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
    96
47309
66774e1fc3a7 8187658: Bigger buffer for GetAdaptersAddresses
igerasim
parents: 47216
diff changeset
    97
    for (int try = 0; ret == ERROR_BUFFER_OVERFLOW && try < MAX_TRIES; ++try) {
29376
ff7f17f3e2da 8065078: NetworkInterface.getNetworkInterfaces() triggers intermittent test failures
msheppar
parents: 28304
diff changeset
    98
        IP_ADAPTER_ADDRESSES * newAdapterInfo = NULL;
47309
66774e1fc3a7 8187658: Bigger buffer for GetAdaptersAddresses
igerasim
parents: 47216
diff changeset
    99
        if (len < (ULONG_MAX - BUFF_SIZE)) {
66774e1fc3a7 8187658: Bigger buffer for GetAdaptersAddresses
igerasim
parents: 47216
diff changeset
   100
            len += BUFF_SIZE;
29376
ff7f17f3e2da 8065078: NetworkInterface.getNetworkInterfaces() triggers intermittent test failures
msheppar
parents: 28304
diff changeset
   101
        }
ff7f17f3e2da 8065078: NetworkInterface.getNetworkInterfaces() triggers intermittent test failures
msheppar
parents: 28304
diff changeset
   102
        newAdapterInfo =
28304
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   103
            (IP_ADAPTER_ADDRESSES *) realloc (adapterInfo, len);
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   104
        if (newAdapterInfo == NULL) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   105
            free(adapterInfo);
28304
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   106
            JNU_ThrowByName(env, "java/lang/OutOfMemoryError",
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   107
                "Native heap allocation failure");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   110
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   111
        adapterInfo = newAdapterInfo;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   112
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 7668
diff changeset
   113
        ret = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapterInfo, &len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   115
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        free (adapterInfo);
28304
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   118
        if (ret == ERROR_INSUFFICIENT_BUFFER) {
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   119
            JNU_ThrowByName(env, "java/lang/Error",
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   120
                "IP Helper Library GetAdaptersAddresses function failed "
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   121
                "with ERROR_INSUFFICIENT_BUFFER");
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   122
        } else if (ret == ERROR_ADDRESS_NOT_ASSOCIATED ) {
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   123
            JNU_ThrowByName(env, "java/lang/Error",
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   124
                "IP Helper Library GetAdaptersAddresses function failed "
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   125
                "with ERROR_ADDRESS_NOT_ASSOCIATED");
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   126
        } else {
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   127
            error_msg_buf = (char *)malloc(error_msg_buf_size);
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   128
            if (error_msg_buf != NULL) {
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   129
                memset(error_msg_buf, 0, error_msg_buf_size);
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   130
                _ret = _snprintf_s(error_msg_buf, error_msg_buf_size,
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   131
                    _TRUNCATE, "IP Helper Library GetAdaptersAddresses "
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   132
                                "function failed with error == %d", ret);
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   133
                if (_ret != -1) {
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   134
                    JNU_ThrowByName(env, "java/lang/Error", error_msg_buf);
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   135
                } else {
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   136
                    JNU_ThrowByName(env, "java/lang/Error",
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   137
                        "IP Helper Library GetAdaptersAddresses function failure");
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   138
                }
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   139
            } else {
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   140
                JNU_ThrowByName(env, "java/lang/Error",
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   141
                    "IP Helper Library GetAdaptersAddresses function failed");
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   142
            }
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   143
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    *adapters = adapterInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    return ERROR_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * return an array of IP_ADAPTER_ADDRESSES containing one element
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   152
 * for each adapter on the system. Returned in *adapters.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * Buffer is malloc'd and must be freed (unless error returned)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
IP_ADAPTER_ADDRESSES *getAdapter (JNIEnv *env,  jint index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    DWORD flags, val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    IP_ADAPTER_ADDRESSES *adapterInfo, *ptr, *ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    ULONG len;
28304
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   159
    char *error_msg_buf = NULL;
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   160
    size_t error_msg_buf_size =
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   161
        strlen("IP Helper Library GetAdaptersAddresses function failed with error == ") + 10;
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   162
    int _ret = 0;
47309
66774e1fc3a7 8187658: Bigger buffer for GetAdaptersAddresses
igerasim
parents: 47216
diff changeset
   163
    adapterInfo = (IP_ADAPTER_ADDRESSES *) malloc(BUFF_SIZE);
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   164
    if (adapterInfo == NULL) {
28304
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   165
        JNU_ThrowByName(env, "java/lang/OutOfMemoryError",
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   166
            "Native heap allocation failure");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
47309
66774e1fc3a7 8187658: Bigger buffer for GetAdaptersAddresses
igerasim
parents: 47216
diff changeset
   169
    len = BUFF_SIZE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    flags = GAA_FLAG_SKIP_DNS_SERVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    flags |= GAA_FLAG_SKIP_MULTICAST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    flags |= GAA_FLAG_INCLUDE_PREFIX;
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 7668
diff changeset
   173
    val = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapterInfo, &len);
47309
66774e1fc3a7 8187658: Bigger buffer for GetAdaptersAddresses
igerasim
parents: 47216
diff changeset
   174
    for (int try = 0; val == ERROR_BUFFER_OVERFLOW && try < MAX_TRIES; ++try) {
29376
ff7f17f3e2da 8065078: NetworkInterface.getNetworkInterfaces() triggers intermittent test failures
msheppar
parents: 28304
diff changeset
   175
        IP_ADAPTER_ADDRESSES * newAdapterInfo = NULL;
47309
66774e1fc3a7 8187658: Bigger buffer for GetAdaptersAddresses
igerasim
parents: 47216
diff changeset
   176
        if (len < (ULONG_MAX - BUFF_SIZE)) {
66774e1fc3a7 8187658: Bigger buffer for GetAdaptersAddresses
igerasim
parents: 47216
diff changeset
   177
            len += BUFF_SIZE;
29376
ff7f17f3e2da 8065078: NetworkInterface.getNetworkInterfaces() triggers intermittent test failures
msheppar
parents: 28304
diff changeset
   178
        }
ff7f17f3e2da 8065078: NetworkInterface.getNetworkInterfaces() triggers intermittent test failures
msheppar
parents: 28304
diff changeset
   179
        newAdapterInfo =
28304
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   180
                (IP_ADAPTER_ADDRESSES *) realloc (adapterInfo, len);
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   181
        if (newAdapterInfo == NULL) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   182
            free(adapterInfo);
28304
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   183
            JNU_ThrowByName(env, "java/lang/OutOfMemoryError",
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   184
                "Native heap allocation failure");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   187
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   188
        adapterInfo = newAdapterInfo;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   189
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 7668
diff changeset
   190
        val = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapterInfo, &len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   192
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    if (val != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        free (adapterInfo);
28304
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   195
        if (val == ERROR_INSUFFICIENT_BUFFER) {
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   196
            JNU_ThrowByName(env, "java/lang/Error",
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   197
                "IP Helper Library GetAdaptersAddresses function failed "
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   198
                "with ERROR_INSUFFICIENT_BUFFER");
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   199
        } else if (val == ERROR_ADDRESS_NOT_ASSOCIATED ) {
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   200
            JNU_ThrowByName(env, "java/lang/Error",
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   201
                "IP Helper Library GetAdaptersAddresses function failed "
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   202
                "with ERROR_ADDRESS_NOT_ASSOCIATED");
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   203
        } else {
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   204
            error_msg_buf = (char *)malloc(error_msg_buf_size);
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   205
            if (error_msg_buf != NULL) {
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   206
                memset(error_msg_buf, 0, error_msg_buf_size);
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   207
                _ret = _snprintf_s(error_msg_buf, error_msg_buf_size,
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   208
                    _TRUNCATE, "IP Helper Library GetAdaptersAddresses function failed "
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   209
                               "with error == %d", val);
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   210
                if (_ret != -1) {
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   211
                    JNU_ThrowByName(env, "java/lang/Error", error_msg_buf);
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   212
                } else {
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   213
                    JNU_ThrowByName(env, "java/lang/Error",
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   214
                        "IP Helper Library GetAdaptersAddresses function failure");
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   215
                }
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   216
            } else {
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   217
                JNU_ThrowByName(env, "java/lang/Error",
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   218
                    "IP Helper Library GetAdaptersAddresses function failed");
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   219
            }
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   220
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
28304
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   223
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    ptr = adapterInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    ret = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    while (ptr != NULL) {
19827
082c76535c1f 8021372: NetworkInterface.getNetworkInterfaces() returns duplicate hardware address
msheppar
parents: 17206
diff changeset
   227
      // in theory the IPv4 index and the IPv6 index can be the same
082c76535c1f 8021372: NetworkInterface.getNetworkInterfaces() returns duplicate hardware address
msheppar
parents: 17206
diff changeset
   228
      // where an interface is enabled for v4 and v6
082c76535c1f 8021372: NetworkInterface.getNetworkInterfaces() returns duplicate hardware address
msheppar
parents: 17206
diff changeset
   229
      // IfIndex == 0 IPv4 not available on this interface
082c76535c1f 8021372: NetworkInterface.getNetworkInterfaces() returns duplicate hardware address
msheppar
parents: 17206
diff changeset
   230
      // Ipv6IfIndex == 0 IPv6 not available on this interface
082c76535c1f 8021372: NetworkInterface.getNetworkInterfaces() returns duplicate hardware address
msheppar
parents: 17206
diff changeset
   231
      if (((ptr->IfIndex != 0)&&(ptr->IfIndex == index)) ||
082c76535c1f 8021372: NetworkInterface.getNetworkInterfaces() returns duplicate hardware address
msheppar
parents: 17206
diff changeset
   232
          ((ptr->Ipv6IfIndex !=0) && (ptr->Ipv6IfIndex == index))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        ret = (IP_ADAPTER_ADDRESSES *) malloc(sizeof(IP_ADAPTER_ADDRESSES));
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   234
        if (ret == NULL) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   235
            free(adapterInfo);
28304
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   236
            JNU_ThrowByName(env, "java/lang/OutOfMemoryError",
00dea76eda49 8068597: Add error code to to exception condition message resulting from GetAdaptersAddresses function calls
msheppar
parents: 25859
diff changeset
   237
                "Native heap allocation failure");
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   238
            return NULL;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   239
        }
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   240
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   241
        //copy the memory and break out of the while loop.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        memcpy(ret, ptr, sizeof(IP_ADAPTER_ADDRESSES));
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   243
        break;
19827
082c76535c1f 8021372: NetworkInterface.getNetworkInterfaces() returns duplicate hardware address
msheppar
parents: 17206
diff changeset
   244
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
      ptr=ptr->Next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    free(adapterInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
static int ipinflen = 2048;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
int getAllInterfacesAndAddresses (JNIEnv *env, netif **netifPP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
{
910
1f53246fb014 6729881: Compiler warning in networking native code
chegar
parents: 2
diff changeset
   258
    DWORD ret;
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   259
    IP_ADAPTER_ADDRESSES *ptr, *adapters=NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    ULONG len=ipinflen, count=0;
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   261
    netif *nif=NULL, *dup_nif, *last=NULL, *loopif=NULL, *curr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    int tun=0, net=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   264
    *netifPP = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
   /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    * Get the IPv4 interfaces. This information is the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    * as what previous JDK versions would return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 7668
diff changeset
   270
    ret = enumInterfaces(env, netifPP);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    if (ret == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        count = ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /* locate the loopback (and the last) interface */
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   278
    for (nif=*netifPP, last=nif; nif!=NULL; nif=nif->next) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (nif->ifType == MIB_IF_TYPE_LOOPBACK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            loopif = nif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        last = nif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
4811
448740c7f12d 6707289: InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc
chegar
parents: 1247
diff changeset
   285
    // Retrieve IPv4 addresses with the IP Helper API
448740c7f12d 6707289: InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc
chegar
parents: 1247
diff changeset
   286
    curr = *netifPP;
448740c7f12d 6707289: InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc
chegar
parents: 1247
diff changeset
   287
    while (curr != NULL) {
448740c7f12d 6707289: InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc
chegar
parents: 1247
diff changeset
   288
        netaddr *netaddrP;
448740c7f12d 6707289: InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc
chegar
parents: 1247
diff changeset
   289
        ret = enumAddresses_win(env, curr, &netaddrP);
10417
947e9a7bf244 7084560: Crash in net.dll
michaelm
parents: 9003
diff changeset
   290
        if (ret == -1) {
4811
448740c7f12d 6707289: InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc
chegar
parents: 1247
diff changeset
   291
            return -1;
448740c7f12d 6707289: InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc
chegar
parents: 1247
diff changeset
   292
        }
448740c7f12d 6707289: InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc
chegar
parents: 1247
diff changeset
   293
        curr->addrs = netaddrP;
448740c7f12d 6707289: InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc
chegar
parents: 1247
diff changeset
   294
        curr->naddrs += ret;
448740c7f12d 6707289: InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc
chegar
parents: 1247
diff changeset
   295
        curr = curr->next;
448740c7f12d 6707289: InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc
chegar
parents: 1247
diff changeset
   296
    }
448740c7f12d 6707289: InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc
chegar
parents: 1247
diff changeset
   297
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    ret = getAdapters (env, &adapters);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /* Now get the IPv6 information. This includes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *  (a)  IPv6 information associated with interfaces already found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *  (b)  IPv6 information for IPv6 only interfaces (probably tunnels)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * For compatibility with previous releases we use the naming
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 7668
diff changeset
   308
     * information gotten from enumInterfaces() for (a) entries
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * However, the index numbers are taken from the new API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * The procedure is to go through the list of adapters returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * by the new API looking for entries that correspond to IPv4 interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * already found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    ptr = adapters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    while (ptr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        int c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        netif *nif0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (ptr->IfType == IF_TYPE_SOFTWARE_LOOPBACK && (loopif != NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            c = getAddrsFromAdapter(ptr, &loopif->addrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            if (c == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            loopif->naddrs += c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            int index = ptr->IfIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            if (index != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                /* This entry is associated with an IPv4 interface */
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   330
                for (nif=*netifPP; nif!=NULL; nif=nif->next) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    if (nif->index == index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                        /* found the interface entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                         * set the index to the IPv6 index and add the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                         * IPv6 addresses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                         */
19827
082c76535c1f 8021372: NetworkInterface.getNetworkInterfaces() returns duplicate hardware address
msheppar
parents: 17206
diff changeset
   336
                        nif->ipv6Index = ptr->Ipv6IfIndex;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                        c = getAddrsFromAdapter(ptr, &nif->addrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                        nif->naddrs += c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                /* This entry is IPv6 only */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                char newname [128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                int c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                /* Windows allocates duplicate adapter entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                 * for tunnel interfaces when there are multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                 * physical adapters. Need to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                 * if this is a duplicate (ipv6Index is the same)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                dup_nif = 0;
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   353
                for (nif0=*netifPP; nif0!=NULL; nif0=nif0->next) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    if (nif0->hasIpv6Address &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                                ptr->Ipv6IfIndex == nif0->ipv6Index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                        dup_nif = nif0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                if (dup_nif == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    /* new interface */
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   362
                        nif = (netif *) calloc (1, sizeof(netif));
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   363
                        if (nif == 0) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   364
                            goto err;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   365
                        }
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   366
                        if (ptr->IfType == IF_TYPE_TUNNEL) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   367
                                sprintf (newname, "tun%d", tun);
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   368
                                tun ++;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   369
                        } else {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   370
                                sprintf (newname, "net%d", net);
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   371
                                net ++;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   372
                        }
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   373
                        nif->name = malloc (strlen(newname)+1);
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   374
                        nif->displayName = malloc (wcslen(ptr->FriendlyName)*2+2);
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   375
                        if (nif->name == 0 || nif->displayName == 0) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   376
                                goto err;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   377
                        }
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   378
                        strcpy (nif->name, newname);
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   379
                        wcscpy ((PWCHAR)nif->displayName, ptr->FriendlyName);
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   380
                        nif->dNameIsUnicode = TRUE;
19827
082c76535c1f 8021372: NetworkInterface.getNetworkInterfaces() returns duplicate hardware address
msheppar
parents: 17206
diff changeset
   381
082c76535c1f 8021372: NetworkInterface.getNetworkInterfaces() returns duplicate hardware address
msheppar
parents: 17206
diff changeset
   382
                        // the java.net.NetworkInterface abstraction only has index
082c76535c1f 8021372: NetworkInterface.getNetworkInterfaces() returns duplicate hardware address
msheppar
parents: 17206
diff changeset
   383
                        // so the Ipv6IfIndex needs to map onto index
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   384
                        nif->index = ptr->Ipv6IfIndex;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   385
                        nif->ipv6Index = ptr->Ipv6IfIndex;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   386
                        nif->hasIpv6Address = TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   388
                        last->next = nif;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   389
                        last = nif;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   390
                        count++;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   391
                        c = getAddrsFromAdapter(ptr, &nif->addrs);
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   392
                        if (c == -1) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   393
                                goto err;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   394
                        }
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   395
                        nif->naddrs += c;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   396
                 } else {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   397
                        /* add the addresses from this adapter to the
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   398
                         * original (dup_nif)
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   399
                         */
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   400
                        c = getAddrsFromAdapter(ptr, &dup_nif->addrs);
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   401
                        if (c == -1) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   402
                                goto err;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   403
                        }
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   404
                        dup_nif->naddrs += c;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        ptr=ptr->Next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    free (adapters);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
err:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    if (*netifPP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        free_netif (*netifPP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    if (adapters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        free (adapters);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
/* If *netaddrPP is null, then the addresses are allocated and the beginning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
 * of the allocated chain is returned in *netaddrPP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
 * If *netaddrPP is not null, then the addresses allocated here are appended
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
 * to the existing chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
 * Returns count of addresses or -1 on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
static int getAddrsFromAdapter(IP_ADAPTER_ADDRESSES *ptr, netaddr **netaddrPP) {
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   433
        LPSOCKADDR sock;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   434
        int        count = 0;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   435
        netaddr    *curr, *start = NULL, *prev = NULL;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   436
        PIP_ADAPTER_UNICAST_ADDRESS uni_addr;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   437
        PIP_ADAPTER_ANYCAST_ADDRESS any_addr;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   438
        PIP_ADAPTER_PREFIX prefix;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   440
        /* If chain passed in, find end */
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   441
        if (*netaddrPP != NULL) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   442
            for (start=*netaddrPP; start->next!=NULL; start=start->next)
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   443
                ;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   444
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   445
            prev=start;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   448
        prefix = ptr->FirstPrefix;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   449
        /* Unicast */
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   450
        uni_addr = ptr->FirstUnicastAddress;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   451
        while (uni_addr != NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        /* address is only usable if dad state is preferred or deprecated */
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   453
                if (uni_addr->DadState == IpDadStateDeprecated ||
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   454
                                uni_addr->DadState == IpDadStatePreferred) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   455
                        sock = uni_addr->Address.lpSockaddr;
4811
448740c7f12d 6707289: InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc
chegar
parents: 1247
diff changeset
   456
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   457
                        // IPv4 addresses already retrieved with enumAddresses_win
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   458
                        if (sock->sa_family == AF_INET) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   459
                                uni_addr = uni_addr->Next;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   460
                                continue;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   461
                        }
4811
448740c7f12d 6707289: InterfaceAddress.getNetworkPrefixLength() does not conform to Javadoc
chegar
parents: 1247
diff changeset
   462
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            curr = (netaddr *)calloc (1, sizeof (netaddr));
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   464
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   465
            if (curr == NULL)
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   466
                goto freeAllocatedMemory;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   467
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   468
            if (start == NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                start = curr;
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   470
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   471
            if (prev != NULL)
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   472
               prev->next = curr;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   473
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            prev = curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            SOCKETADDRESS_COPY (&curr->addr, sock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            if (prefix != NULL) {
910
1f53246fb014 6729881: Compiler warning in networking native code
chegar
parents: 2
diff changeset
   477
              curr->mask = (short)prefix->PrefixLength;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
              prefix = prefix->Next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            count ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        uni_addr = uni_addr->Next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    /* Anycast */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    any_addr = ptr->FirstAnycastAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    while (any_addr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        curr = (netaddr *)calloc (1, sizeof (netaddr));
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   488
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   489
        if (curr == NULL)
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   490
            goto freeAllocatedMemory;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   491
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   492
        if (start == NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            start = curr;
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   494
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   495
        if (prev != NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            prev->next = curr;
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   497
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        prev = curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        sock = any_addr->Address.lpSockaddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        SOCKETADDRESS_COPY (&curr->addr, sock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        count ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        any_addr = any_addr->Next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    if (*netaddrPP == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        *netaddrPP = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    return count;
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   508
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   509
freeAllocatedMemory:
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   510
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   511
    if (*netaddrPP != NULL) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   512
        //N.B. the variable "start" cannot be NULL at this point because we started with an
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   513
        //existing list.
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   514
        curr=start->next;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   515
        start->next = NULL;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   516
        start = curr;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   517
    }
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   518
    // otherwise, "start" points to the beginning of an incomplete list that we must deallocate.
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   519
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   520
    while (start != NULL) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   521
        curr = start->next;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   522
        free(start);
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   523
        start = curr;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   524
    }
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   525
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   526
    return -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
 * Create a NetworkInterface object, populate the name and index, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
 * populate the InetAddress array based on the IP addresses for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
 * interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    jobject netifObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    jobject name, displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    jobjectArray addrArr, bindsArr, childArr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    netaddr *addrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    jint addr_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    int netaddrCount=ifs->naddrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    netaddr *netaddrP=ifs->addrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    jint bind_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * Create a NetworkInterface object and populate it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    netifObj = (*env)->NewObject(env, ni_class, ni_ctor);
41594
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   549
    if (netifObj == NULL) {
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   550
        return NULL;
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   551
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    name = (*env)->NewStringUTF(env, ifs->name);
41594
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   553
    if (name == NULL) {
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   554
        return NULL;
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   555
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    if (ifs->dNameIsUnicode) {
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 7668
diff changeset
   557
        displayName = (*env)->NewString(env, (PWCHAR)ifs->displayName,
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 7668
diff changeset
   558
                                        (jsize)wcslen ((PWCHAR)ifs->displayName));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        displayName = (*env)->NewStringUTF(env, ifs->displayName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
41594
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   562
    if (displayName == NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    (*env)->SetObjectField(env, netifObj, ni_nameID, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    (*env)->SetObjectField(env, netifObj, ni_displayNameID, displayName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    (*env)->SetIntField(env, netifObj, ni_indexID, ifs->index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * Get the IP addresses for this interface if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * Note that 0 is a valid number of addresses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    if (netaddrCount < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        netaddrCount = enumAddresses_win(env, ifs, &netaddrP);
10417
947e9a7bf244 7084560: Crash in net.dll
michaelm
parents: 9003
diff changeset
   574
        if (netaddrCount == -1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
22646
5fa3669fd35d 8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents: 20851
diff changeset
   579
    addrArr = (*env)->NewObjectArray(env, netaddrCount, ia_class, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    if (addrArr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    bindsArr = (*env)->NewObjectArray(env, netaddrCount, ni_ibcls, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    if (bindsArr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
      free_netaddr(netaddrP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
      return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    addrs = netaddrP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    addr_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    bind_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    while (addrs != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        jobject iaObj, ia2Obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        jobject ibObj = NULL;
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 29376
diff changeset
   596
        if (addrs->addr.sa.sa_family == AF_INET) {
22646
5fa3669fd35d 8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents: 20851
diff changeset
   597
            iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            if (iaObj == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            /* default ctor will set family to AF_INET */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 29376
diff changeset
   603
            setInetAddress_addr(env, iaObj, ntohl(addrs->addr.sa4.sin_addr.s_addr));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            if (ibObj == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
              free_netaddr(netaddrP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
              return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
22646
5fa3669fd35d 8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents: 20851
diff changeset
   611
            ia2Obj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            if (ia2Obj == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
              free_netaddr(netaddrP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
              return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            }
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 29376
diff changeset
   616
            setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.sa4.sin_addr.s_addr));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            (*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        } else /* AF_INET6 */ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            int scope;
41602
56443be12e8e 8168471: Non ANSI C declaration of block local variable in NetworkInterface_winXP.c
simonis
parents: 41594
diff changeset
   622
            jboolean ret;
22646
5fa3669fd35d 8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents: 20851
diff changeset
   623
            iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
41594
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   624
            if (iaObj == NULL) {
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   625
                return NULL;
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   626
            }
41602
56443be12e8e 8168471: Non ANSI C declaration of block local variable in NetworkInterface_winXP.c
simonis
parents: 41594
diff changeset
   627
            ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.sa6.sin6_addr.s6_addr));
41594
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   628
            if (ret == JNI_FALSE) {
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   629
                return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            }
41594
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   631
            scope = addrs->addr.sa6.sin6_scope_id;
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   632
            if (scope != 0) { /* zero is default value, no need to set */
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   633
                setInet6Address_scopeid(env, iaObj, scope);
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   634
                setInet6Address_scopeifname(env, iaObj, netifObj);
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   635
            }
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   636
            ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   637
            if (ibObj == NULL) {
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   638
              free_netaddr(netaddrP);
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   639
              return NULL;
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   640
            }
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   641
            (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   642
            (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
e54e81e9be7b 8168405: Pending exceptions in java.base/windows/native
prappo
parents: 41380
diff changeset
   643
            (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        (*env)->SetObjectArrayElement(env, addrArr, addr_index, iaObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        addrs = addrs->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        addr_index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    (*env)->SetObjectField(env, netifObj, ni_addrsID, addrArr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    (*env)->SetObjectField(env, netifObj, ni_bindsID, bindsArr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * Windows doesn't have virtual interfaces, so child array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * is always empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    childArr = (*env)->NewObjectArray(env, 0, ni_class, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    if (childArr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
      return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    (*env)->SetObjectField(env, netifObj, ni_childsID, childArr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    /* return the NetworkInterface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    return netifObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    (JNIEnv *env, jclass cls, jstring name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    netif *ifList, *curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    jboolean isCopy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    const char *name_utf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    jobject netifObj = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    if (getAllInterfacesAndAddresses (env, &ifList) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    /* get the name as a C string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    /* Search by name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    curr = ifList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    while (curr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        if (strcmp(name_utf, curr->name) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        curr = curr->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    /* if found create a NetworkInterface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    if (curr != NULL) {;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        netifObj = createNetworkInterfaceXP(env, curr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    /* release the UTF string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    (*env)->ReleaseStringUTFChars(env, name, name_utf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /* release the interface list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    free_netif(ifList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    return netifObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
 * Class:     NetworkInterface
1097
af4930f761df 6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents: 910
diff changeset
   706
 * Method:    getByIndex0_XP
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
 * Signature: (I)LNetworkInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
 */
1097
af4930f761df 6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents: 910
diff changeset
   709
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByIndex0_XP
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
  (JNIEnv *env, jclass cls, jint index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    netif *ifList, *curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    jobject netifObj = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    if (getAllInterfacesAndAddresses (env, &ifList) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    /* search by index */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    curr = ifList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    while (curr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        if (index == curr->index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        curr = curr->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    /* if found create a NetworkInterface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    if (curr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        netifObj = createNetworkInterfaceXP(env, curr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    /* release the interface list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    free_netif(ifList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    return netifObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
 * Method:    getByInetAddress0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
 * Signature: (Ljava/net/InetAddress;)Ljava/net/NetworkInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    (JNIEnv *env, jclass cls, jobject iaObj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    netif *ifList, *curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    jobject netifObj = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    /* get the list of interfaces */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    if (getAllInterfacesAndAddresses (env, &ifList) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * Enumerate the addresses on each interface until we find a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * matching address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    curr = ifList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    while (curr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        netaddr *addrList = curr->addrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        netaddr *addrP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        /* iterate through each address */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        addrP = addrList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        while (addrP != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            if (NET_SockaddrEqualsInetAddress(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                                (struct sockaddr*)&addrP->addr, iaObj)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            addrP = addrP->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
         * Address matched so create NetworkInterface for this interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
         * and address list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        if (addrP != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            netifObj = createNetworkInterfaceXP(env, curr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        /* on next interface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        curr = curr->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    /* release the interface list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    free_netif(ifList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    return netifObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
 * Method:    getAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
 * Signature: ()[Ljava/net/NetworkInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
JNIEXPORT jobjectArray JNICALL Java_java_net_NetworkInterface_getAll_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    netif *ifList, *curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    jobjectArray netIFArr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    jint arr_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * Get list of interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    count = getAllInterfacesAndAddresses (env, &ifList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    if (count < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    /* allocate a NetworkInterface array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    netIFArr = (*env)->NewObjectArray(env, count, cls, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    if (netIFArr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * Iterate through the interfaces, create a NetworkInterface instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * for each array element and populate the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    curr = ifList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    arr_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    while (curr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        jobject netifObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        netifObj = createNetworkInterfaceXP(env, curr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        if (netifObj == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        /* put the NetworkInterface into the array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        (*env)->SetObjectArrayElement(env, netIFArr, arr_index++, netifObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        curr = curr->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    /* release the interface list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    free_netif(ifList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    return netIFArr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
 * Method:    supportsMulticast0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
 * Signature: (Ljava/lang/String;I)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_supportsMulticast0_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    (JNIEnv *env, jclass cls, jstring name, jint index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
      IP_ADAPTER_ADDRESSES *ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
      jboolean val = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
      ptr = getAdapter(env, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
      if (ptr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        val = ptr->Flags & IP_ADAPTER_NO_MULTICAST ? JNI_FALSE : JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        free(ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
      return val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
 * Method:    isUp0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
 * Signature: (Ljava/lang/String;I)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isUp0_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    (JNIEnv *env, jclass cls, jstring name, jint index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
      IP_ADAPTER_ADDRESSES *ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
      jboolean val = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
      ptr = getAdapter(env, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
      if (ptr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        val = ptr->OperStatus == IfOperStatusUp ? JNI_TRUE : JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        free(ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
      return val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
 * Method:    getMacAddr0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
 * Signature: (Ljava/lang/String;I)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    (JNIEnv *env, jclass cls, jstring name, jint index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
      IP_ADAPTER_ADDRESSES *ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
      jbyteArray ret = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
      int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
      ptr = getAdapter(env, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
      if (ptr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        len = ptr->PhysicalAddressLength;
17206
3dfa000764e9 6594296: NetworkInterface.getHardwareAddress returns zero length byte array
chegar
parents: 17193
diff changeset
   896
        if (len > 0) {
3dfa000764e9 6594296: NetworkInterface.getHardwareAddress returns zero length byte array
chegar
parents: 17193
diff changeset
   897
          ret = (*env)->NewByteArray(env, len);
3dfa000764e9 6594296: NetworkInterface.getHardwareAddress returns zero length byte array
chegar
parents: 17193
diff changeset
   898
          if (!IS_NULL(ret)) {
3dfa000764e9 6594296: NetworkInterface.getHardwareAddress returns zero length byte array
chegar
parents: 17193
diff changeset
   899
            (*env)->SetByteArrayRegion(env, ret, 0, len,
3dfa000764e9 6594296: NetworkInterface.getHardwareAddress returns zero length byte array
chegar
parents: 17193
diff changeset
   900
                                       (jbyte*) ptr->PhysicalAddress);
3dfa000764e9 6594296: NetworkInterface.getHardwareAddress returns zero length byte array
chegar
parents: 17193
diff changeset
   901
          }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        free(ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
      return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
 * Class:       java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
 * Method:      getMTU0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
 * Signature:   ([bLjava/lang/String;I)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    (JNIEnv *env, jclass cls, jstring name, jint index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
      IP_ADAPTER_ADDRESSES *ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
      jint ret = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
      ptr = getAdapter(env, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
      if (ptr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        ret = ptr->Mtu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        free(ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
      return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
 * Method:    isLoopback0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
 * Signature: (Ljava/lang/String;I)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isLoopback0_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    (JNIEnv *env, jclass cls, jstring name, jint index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
      IP_ADAPTER_ADDRESSES *ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
      jboolean val = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
      ptr = getAdapter(env, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
      if (ptr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        val = ptr->IfType == IF_TYPE_SOFTWARE_LOOPBACK ? JNI_TRUE : JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        free(ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
      return val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
 * Method:    isP2P0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
 * Signature: (Ljava/lang/String;I)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isP2P0_XP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    (JNIEnv *env, jclass cls, jstring name, jint index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
      IP_ADAPTER_ADDRESSES *ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
      jboolean val = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
      ptr = getAdapter(env, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
      if (ptr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        if (ptr->IfType == IF_TYPE_PPP || ptr->IfType == IF_TYPE_SLIP ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
           ptr->IfType == IF_TYPE_TUNNEL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
          val = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        free(ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
      return val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
}