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