src/java.base/windows/native/libnet/NetworkInterface.c
author vtewari
Thu, 18 Jan 2018 13:55:26 +0530
changeset 51151 d6b131d2bc8b
parent 47216 71c04702a3d5
child 51562 1b1bca603244
permissions -rw-r--r--
8193419: Better Internet address support Reviewed-by: chegar, rriggs, igerasim, skoivu, rhalade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
51151
d6b131d2bc8b 8193419: Better Internet address support
vtewari
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
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: 1247
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: 1247
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
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: 41380
diff changeset
    25
#include "net_util.h"
18c9669e76ca 8167481: cleanup of headers and includes for native libnet
clanger
parents: 41380
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
 * Interfaces and addresses are enumerated using the IP helper routines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * GetIfTable, GetIfAddrTable resp. These routines are available on Windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * 98, NT SP+4, 2000, and XP. They are also available on Windows 95 if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * IE is upgraded to 5.x.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Windows does not have any standard for device names so we are forced
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * to use our own convention which is based on the normal Unix naming
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * convention ("lo" for the loopback, eth0, eth1, .. for ethernet devices,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * tr0, tr1, .. for token ring, and so on). This convention gives us
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * consistency across multiple Windows editions and also consistency with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Solaris/Linux device names. Note that we always enumerate in index
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * order and this ensures consistent device number across invocations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
/* various JNI ids */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
jclass ni_class;            /* NetworkInterface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
jmethodID ni_ctor;          /* NetworkInterface() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
jfieldID ni_indexID;        /* NetworkInterface.index */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
jfieldID ni_addrsID;        /* NetworkInterface.addrs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
jfieldID ni_bindsID;        /* NetworkInterface.bindings */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
jfieldID ni_nameID;         /* NetworkInterface.name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
jfieldID ni_displayNameID;  /* NetworkInterface.displayName */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
jfieldID ni_childsID;       /* NetworkInterface.childs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
jclass ni_ibcls;            /* InterfaceAddress */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
jmethodID ni_ibctrID;       /* InterfaceAddress() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
jfieldID ni_ibaddressID;        /* InterfaceAddress.address */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
jfieldID ni_ibbroadcastID;      /* InterfaceAddress.broadcast */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
jfieldID ni_ibmaskID;           /* InterfaceAddress.maskLength */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * Support routines to free netif and netaddr lists
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
void free_netif(netif *netifP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    netif *curr = netifP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    while (curr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        if (curr->name != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            free(curr->name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        if (curr->displayName != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            free(curr->displayName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if (curr->addrs != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            free_netaddr (curr->addrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        netifP = netifP->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        free(curr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        curr = netifP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
void free_netaddr(netaddr *netaddrP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    netaddr *curr = netaddrP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    while (curr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        netaddrP = netaddrP->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        free(curr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        curr = netaddrP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * Returns the interface structure from the table with the matching index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
MIB_IFROW *getIF(jint index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    MIB_IFTABLE *tableP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    MIB_IFROW *ifrowP, *ret = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    ULONG size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    DWORD i, count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    jint ifindex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Ask the IP Helper library to enumerate the adapters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    size = sizeof(MIB_IFTABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    tableP = (MIB_IFTABLE *)malloc(size);
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   110
    if(tableP == NULL)
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   111
        return NULL;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   112
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   113
    count = GetIfTable(tableP, &size, TRUE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    if (count == ERROR_INSUFFICIENT_BUFFER || count == ERROR_BUFFER_OVERFLOW) {
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   115
        MIB_IFTABLE* newTableP =  (MIB_IFTABLE *)realloc(tableP, size);
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   116
        if (newTableP == NULL) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   117
            free(tableP);
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   118
            return NULL;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   119
        }
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   120
        tableP = newTableP;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   121
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   122
        count = GetIfTable(tableP, &size, TRUE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    if (count != NO_ERROR) {
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   126
        free(tableP);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   130
    {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   131
    ifrowP = tableP->table;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   132
    for (i=0; i<tableP->dwNumEntries; i++) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   133
    /*
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   134
     * Warning: the real index is obtained by GetFriendlyIfIndex()
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   135
    */
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   136
        ifindex = GetFriendlyIfIndex(ifrowP->dwIndex);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (ifindex == index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
          /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
           * Create a copy of the entry so that we can free the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
           */
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   141
            ret = (MIB_IFROW *) malloc(sizeof(MIB_IFROW));
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   142
            if (ret == NULL) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   143
                free(tableP);
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   144
                return NULL;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   145
            }
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   146
            memcpy(ret, ifrowP, sizeof(MIB_IFROW));
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   147
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        /* onto the next interface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        ifrowP++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
      free(tableP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * Enumerate network interfaces using IP Helper Library routine GetIfTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * We use GetIfTable rather than other IP helper routines because it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * available on 98 & NT SP4+.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * Returns the number of interfaces found or -1 if error. If no error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * occurs then netifPP be returned as list of netif structures or NULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * if no interfaces are found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 */
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   167
int enumInterfaces(JNIEnv *env, netif **netifPP)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    MIB_IFTABLE *tableP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    MIB_IFROW *ifrowP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    ULONG size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    DWORD ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    netif *netifP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    DWORD i;
14768
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   176
    int lo=0, eth=0, tr=0, fddi=0, ppp=0, sl=0, wlan=0, net=0, wlen=0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Ask the IP Helper library to enumerate the adapters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    size = sizeof(MIB_IFTABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    tableP = (MIB_IFTABLE *)malloc(size);
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   183
    if (tableP == NULL) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   184
        JNU_ThrowOutOfMemoryError(env, "Native heap allocation failure");
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   185
        return -1;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   186
    }
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   187
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   188
    ret = GetIfTable(tableP, &size, TRUE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    if (ret == ERROR_INSUFFICIENT_BUFFER || ret == ERROR_BUFFER_OVERFLOW) {
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   190
        MIB_IFTABLE * newTableP = (MIB_IFTABLE *)realloc(tableP, size);
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   191
        if (newTableP == NULL) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   192
            free(tableP);
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   193
            JNU_ThrowOutOfMemoryError(env, "Native heap allocation failure");
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   194
            return -1;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   195
        }
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   196
        tableP = newTableP;
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   197
        ret = GetIfTable(tableP, &size, TRUE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    if (ret != NO_ERROR) {
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   201
        free(tableP);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        JNU_ThrowByName(env, "java/lang/Error",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                "IP Helper Library GetIfTable function failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Iterate through the list of adapters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    netifP = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    ifrowP = tableP->table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    for (i=0; i<tableP->dwNumEntries; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        char dev_name[8];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        netif *curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
         * Generate a name for the device as Windows doesn't have any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
         * real concept of a device name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        switch (ifrowP->dwType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            case MIB_IF_TYPE_ETHERNET:
12542
31190502e9e3 7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents: 10417
diff changeset
   226
                _snprintf_s(dev_name, 8, _TRUNCATE, "eth%d", eth++);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            case MIB_IF_TYPE_TOKENRING:
12542
31190502e9e3 7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents: 10417
diff changeset
   230
                _snprintf_s(dev_name, 8, _TRUNCATE, "tr%d", tr++);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            case MIB_IF_TYPE_FDDI:
12542
31190502e9e3 7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents: 10417
diff changeset
   234
                _snprintf_s(dev_name, 8, _TRUNCATE, "fddi%d", fddi++);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            case MIB_IF_TYPE_LOOPBACK:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                /* There should only be only IPv4 loopback address */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                if (lo > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                }
12542
31190502e9e3 7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents: 10417
diff changeset
   242
                strncpy_s(dev_name, 8, "lo", _TRUNCATE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                lo++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            case MIB_IF_TYPE_PPP:
12542
31190502e9e3 7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents: 10417
diff changeset
   247
                _snprintf_s(dev_name, 8, _TRUNCATE, "ppp%d", ppp++);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            case MIB_IF_TYPE_SLIP:
12542
31190502e9e3 7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents: 10417
diff changeset
   251
                _snprintf_s(dev_name, 8, _TRUNCATE, "sl%d", sl++);
31190502e9e3 7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents: 10417
diff changeset
   252
                break;
31190502e9e3 7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents: 10417
diff changeset
   253
31190502e9e3 7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents: 10417
diff changeset
   254
            case IF_TYPE_IEEE80211:
31190502e9e3 7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents: 10417
diff changeset
   255
                _snprintf_s(dev_name, 8, _TRUNCATE, "wlan%d", wlan++);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            default:
12542
31190502e9e3 7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents: 10417
diff changeset
   259
                _snprintf_s(dev_name, 8, _TRUNCATE, "net%d", net++);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
         * Allocate a netif structure and space for the name and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
         * display name (description in this case).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        curr = (netif *)calloc(1, sizeof(netif));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (curr != NULL) {
14768
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   268
            wlen = MultiByteToWideChar(CP_OEMCP, 0, ifrowP->bDescr,
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   269
                       ifrowP->dwDescrLen, NULL, 0);
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   270
            if(wlen == 0) {
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   271
                // MultiByteToWideChar should not fail
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   272
                // But in rare case it fails, we allow 'char' to be displayed
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   273
                curr->displayName = (char *)malloc(ifrowP->dwDescrLen + 1);
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   274
            } else {
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   275
                curr->displayName = (wchar_t *)malloc(wlen*(sizeof(wchar_t))+1);
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   276
            }
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   277
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            curr->name = (char *)malloc(strlen(dev_name) + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            if (curr->name == NULL || curr->displayName == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                if (curr->name) free(curr->name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                if (curr->displayName) free(curr->displayName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                curr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (curr == NULL) {
13245
7ab3ef5b9520 7181353: Update error message to distinguish native OOM and java OOM in net
zhouyx
parents: 12542
diff changeset
   287
            JNU_ThrowOutOfMemoryError(env, "Native heap allocation failure");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            free_netif(netifP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            free(tableP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
         * Populate the interface. Note that we need to convert the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
         * index into its "friendly" value as otherwise we will expose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
         * 32-bit numbers as index values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        strcpy(curr->name, dev_name);
14768
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   299
        if (wlen == 0) {
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   300
            // display char type in case of MultiByteToWideChar failure
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   301
            strncpy(curr->displayName, ifrowP->bDescr, ifrowP->dwDescrLen);
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   302
            curr->displayName[ifrowP->dwDescrLen] = '\0';
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   303
        } else {
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   304
            // call MultiByteToWideChar again to fill curr->displayName
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   305
            // it should not fail, because we have called it once before
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   306
            if (MultiByteToWideChar(CP_OEMCP, 0, ifrowP->bDescr,
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   307
                   ifrowP->dwDescrLen, curr->displayName, wlen) == 0) {
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   308
                JNU_ThrowByName(env, "java/lang/Error",
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   309
                       "Cannot get multibyte char for interface display name");
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   310
                free_netif(netifP);
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   311
                free(tableP);
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   312
                free(curr->name);
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   313
                free(curr->displayName);
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   314
                free(curr);
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   315
                return -1;
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   316
            } else {
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   317
                curr->displayName[wlen*(sizeof(wchar_t))] = '\0';
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   318
                curr->dNameIsUnicode = TRUE;
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   319
            }
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   320
        }
8800c12ef525 6512101: Incorrect encoding in NetworkInterface.getDisplayName()
dingxmin
parents: 14342
diff changeset
   321
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        curr->dwIndex = ifrowP->dwIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        curr->ifType = ifrowP->dwType;
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   324
        curr->index = GetFriendlyIfIndex(ifrowP->dwIndex);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
         * Put the interface at tail of list as GetIfTable(,,TRUE) is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
         * returning the interfaces in index order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        if (netifP == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            netifP = curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            netif *tail = netifP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            while (tail->next != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                tail = tail->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            tail->next = curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        /* onto the next interface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        ifrowP++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Free the interface table and return the interface list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    if (tableP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        free(tableP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    *netifPP = netifP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
 * Enumerate the IP addresses on an interface using the IP helper library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
 * routine GetIfAddrTable and matching based on the index name. There are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
 * more efficient routines but we use GetIfAddrTable because it's avaliable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
 * on 98 and NT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
 * Returns the count of addresses, or -1 if error. If no error occurs then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
 * netaddrPP will return a list of netaddr structures with the IP addresses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
int enumAddresses_win(JNIEnv *env, netif *netifP, netaddr **netaddrPP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    MIB_IPADDRTABLE *tableP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    ULONG size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    DWORD ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    DWORD i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    netaddr *netaddrP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    unsigned long mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * Use GetIpAddrTable to enumerate the IP Addresses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    size = sizeof(MIB_IPADDRTABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    tableP = (MIB_IPADDRTABLE *)malloc(size);
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   379
    if (tableP == NULL) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   380
        JNU_ThrowOutOfMemoryError(env, "Native heap allocation failure");
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   381
        return -1;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   382
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   384
    ret = GetIpAddrTable(tableP, &size, FALSE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    if (ret == ERROR_INSUFFICIENT_BUFFER || ret == ERROR_BUFFER_OVERFLOW) {
17193
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   386
        MIB_IPADDRTABLE * newTableP = (MIB_IPADDRTABLE *)realloc(tableP, size);
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   387
        if (newTableP == NULL) {
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   388
            free(tableP);
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   389
            JNU_ThrowOutOfMemoryError(env, "Native heap allocation failure");
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   390
            return -1;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   391
        }
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   392
        tableP = newTableP;
8b561b7fb87a 8012108: Memory leak in jdk/src/windows/native/java/net/NetworkInterface_winXP.c
jzavgren
parents: 16870
diff changeset
   393
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   394
        ret = GetIpAddrTable(tableP, &size, FALSE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    if (ret != NO_ERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        if (tableP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            free(tableP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        JNU_ThrowByName(env, "java/lang/Error",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                "IP Helper Library GetIpAddrTable function failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * Iterate through the table to find the addresses with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * matching dwIndex. Ignore 0.0.0.0 addresses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    netaddrP = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    while (i<tableP->dwNumEntries) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (tableP->table[i].dwIndex == netifP->dwIndex &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            tableP->table[i].dwAddr != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            netaddr *curr = (netaddr *)malloc(sizeof(netaddr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            if (curr == NULL) {
13245
7ab3ef5b9520 7181353: Update error message to distinguish native OOM and java OOM in net
zhouyx
parents: 12542
diff changeset
   419
                JNU_ThrowOutOfMemoryError(env, "Native heap allocation failure");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                free_netaddr(netaddrP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                free(tableP);
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
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26595
diff changeset
   425
            curr->addr.sa4.sin_family = AF_INET;
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26595
diff changeset
   426
            curr->addr.sa4.sin_addr.s_addr = tableP->table[i].dwAddr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
             * Get netmask / broadcast address
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            switch (netifP->ifType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            case MIB_IF_TYPE_ETHERNET:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            case MIB_IF_TYPE_TOKENRING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            case MIB_IF_TYPE_FDDI:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            case MIB_IF_TYPE_LOOPBACK:
12542
31190502e9e3 7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents: 10417
diff changeset
   435
            case IF_TYPE_IEEE80211:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
              /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
               * Contrary to what it seems to indicate, dwBCastAddr doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
               * contain the broadcast address but 0 or 1 depending on whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
               * the broadcast address should set the bits of the host part
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
               * to 0 or 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
               * Yes, I know it's stupid, but what can I say, it's MSFTs API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
               */
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26595
diff changeset
   443
              curr->brdcast.sa4.sin_family = AF_INET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
              if (tableP->table[i].dwBCastAddr == 1)
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26595
diff changeset
   445
                curr->brdcast.sa4.sin_addr.s_addr = (tableP->table[i].dwAddr & tableP->table[i].dwMask) | (0xffffffff ^ tableP->table[i].dwMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
              else
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26595
diff changeset
   447
                curr->brdcast.sa4.sin_addr.s_addr = (tableP->table[i].dwAddr & tableP->table[i].dwMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
              mask = ntohl(tableP->table[i].dwMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
              curr->mask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
              while (mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                mask <<= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                curr->mask++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            case MIB_IF_TYPE_PPP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            case MIB_IF_TYPE_SLIP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
              /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
               * these don't have broadcast/subnet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
               */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
              curr->mask = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            curr->next = netaddrP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            netaddrP = curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    *netaddrPP = netaddrP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    free(tableP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
 * Method:    init
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
Java_java_net_NetworkInterface_init(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * Get the various JNI ids that we require
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    ni_class = (*env)->NewGlobalRef(env, cls);
21409
246ccfb4a0f0 8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents: 20851
diff changeset
   489
    CHECK_NULL(ni_class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    ni_nameID = (*env)->GetFieldID(env, ni_class, "name", "Ljava/lang/String;");
21409
246ccfb4a0f0 8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents: 20851
diff changeset
   491
    CHECK_NULL(ni_nameID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    ni_displayNameID = (*env)->GetFieldID(env, ni_class, "displayName", "Ljava/lang/String;");
21409
246ccfb4a0f0 8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents: 20851
diff changeset
   493
    CHECK_NULL(ni_displayNameID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    ni_indexID = (*env)->GetFieldID(env, ni_class, "index", "I");
21409
246ccfb4a0f0 8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents: 20851
diff changeset
   495
    CHECK_NULL(ni_indexID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    ni_addrsID = (*env)->GetFieldID(env, ni_class, "addrs", "[Ljava/net/InetAddress;");
21409
246ccfb4a0f0 8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents: 20851
diff changeset
   497
    CHECK_NULL(ni_addrsID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    ni_bindsID = (*env)->GetFieldID(env, ni_class, "bindings", "[Ljava/net/InterfaceAddress;");
21409
246ccfb4a0f0 8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents: 20851
diff changeset
   499
    CHECK_NULL(ni_bindsID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    ni_childsID = (*env)->GetFieldID(env, ni_class, "childs", "[Ljava/net/NetworkInterface;");
21409
246ccfb4a0f0 8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents: 20851
diff changeset
   501
    CHECK_NULL(ni_childsID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    ni_ctor = (*env)->GetMethodID(env, ni_class, "<init>", "()V");
21409
246ccfb4a0f0 8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents: 20851
diff changeset
   503
    CHECK_NULL(ni_ctor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    ni_ibcls = (*env)->FindClass(env, "java/net/InterfaceAddress");
21409
246ccfb4a0f0 8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents: 20851
diff changeset
   505
    CHECK_NULL(ni_ibcls);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    ni_ibcls = (*env)->NewGlobalRef(env, ni_ibcls);
21409
246ccfb4a0f0 8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents: 20851
diff changeset
   507
    CHECK_NULL(ni_ibcls);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    ni_ibctrID = (*env)->GetMethodID(env, ni_ibcls, "<init>", "()V");
21409
246ccfb4a0f0 8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents: 20851
diff changeset
   509
    CHECK_NULL(ni_ibctrID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    ni_ibaddressID = (*env)->GetFieldID(env, ni_ibcls, "address", "Ljava/net/InetAddress;");
21409
246ccfb4a0f0 8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents: 20851
diff changeset
   511
    CHECK_NULL(ni_ibaddressID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    ni_ibbroadcastID = (*env)->GetFieldID(env, ni_ibcls, "broadcast", "Ljava/net/Inet4Address;");
21409
246ccfb4a0f0 8026880: NetworkInterface native initializing code should check fieldID values
chegar
parents: 20851
diff changeset
   513
    CHECK_NULL(ni_ibbroadcastID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    ni_ibmaskID = (*env)->GetFieldID(env, ni_ibcls, "maskLength", "S");
22646
5fa3669fd35d 8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents: 21409
diff changeset
   515
    CHECK_NULL(ni_ibmaskID);
5fa3669fd35d 8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents: 21409
diff changeset
   516
5fa3669fd35d 8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents: 21409
diff changeset
   517
    initInetAddressIDs(env);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
 * Create a NetworkInterface object, populate the name and index, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
 * populate the InetAddress array based on the IP addresses for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
 * interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
 */
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   525
jobject createNetworkInterface
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   526
    (JNIEnv *env, netif *ifs, int netaddrCount, netaddr *netaddrP)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    jobject netifObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    jobject name, displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    jobjectArray addrArr, bindsArr, childArr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    netaddr *addrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    jint addr_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    jint bind_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * Create a NetworkInterface object and populate it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    netifObj = (*env)->NewObject(env, ni_class, ni_ctor);
23563
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   539
    CHECK_NULL_RETURN(netifObj, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    name = (*env)->NewStringUTF(env, ifs->name);
23563
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   541
    CHECK_NULL_RETURN(name, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    if (ifs->dNameIsUnicode) {
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   543
        displayName = (*env)->NewString(env, (PWCHAR)ifs->displayName,
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   544
                                       (jsize)wcslen ((PWCHAR)ifs->displayName));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        displayName = (*env)->NewStringUTF(env, ifs->displayName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
23563
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   548
    CHECK_NULL_RETURN(displayName, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    (*env)->SetObjectField(env, netifObj, ni_nameID, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    (*env)->SetObjectField(env, netifObj, ni_displayNameID, displayName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    (*env)->SetIntField(env, netifObj, ni_indexID, ifs->index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * Get the IP addresses for this interface if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * Note that 0 is a valid number of addresses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    if (netaddrCount < 0) {
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   558
        netaddrCount = enumAddresses_win(env, ifs, &netaddrP);
10417
947e9a7bf244 7084560: Crash in net.dll
michaelm
parents: 9003
diff changeset
   559
        if (netaddrCount == -1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
22646
5fa3669fd35d 8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents: 21409
diff changeset
   563
    addrArr = (*env)->NewObjectArray(env, netaddrCount, ia_class, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    if (addrArr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        free_netaddr(netaddrP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    bindsArr = (*env)->NewObjectArray(env, netaddrCount, ni_ibcls, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    if (bindsArr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
      free_netaddr(netaddrP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
      return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    addrs = netaddrP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    addr_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    bind_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    while (addrs != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        jobject iaObj, ia2Obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        jobject ibObj = NULL;
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26595
diff changeset
   580
        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: 21409
diff changeset
   581
            iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            if (iaObj == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                free_netaddr(netaddrP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            /* default ctor will set family to AF_INET */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26595
diff changeset
   588
            setInetAddress_addr(env, iaObj, ntohl(addrs->addr.sa4.sin_addr.s_addr));
51151
d6b131d2bc8b 8193419: Better Internet address support
vtewari
parents: 47216
diff changeset
   589
            JNU_CHECK_EXCEPTION_RETURN(env, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            if (addrs->mask != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
              ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
              if (ibObj == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                free_netaddr(netaddrP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
              (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
22646
5fa3669fd35d 8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents: 21409
diff changeset
   597
              ia2Obj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
              if (ia2Obj == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                free_netaddr(netaddrP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
              }
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26595
diff changeset
   602
              setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.sa4.sin_addr.s_addr));
51151
d6b131d2bc8b 8193419: Better Internet address support
vtewari
parents: 47216
diff changeset
   603
              JNU_CHECK_EXCEPTION_RETURN(env, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
              (*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
              (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
              (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        } else /* AF_INET6 */ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            int scope;
22646
5fa3669fd35d 8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents: 21409
diff changeset
   610
            iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            if (iaObj) {
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26595
diff changeset
   612
                jboolean ret = setInet6Address_ipaddress(env, iaObj,  (jbyte *)&(addrs->addr.sa6.sin6_addr.s6_addr));
20821
e0d0a585aa49 8015743: Address internet addresses
michaelm
parents: 17193
diff changeset
   613
                if (ret == JNI_FALSE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                }
20821
e0d0a585aa49 8015743: Address internet addresses
michaelm
parents: 17193
diff changeset
   616
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26595
diff changeset
   617
                scope = addrs->addr.sa6.sin6_scope_id;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                if (scope != 0) { /* zero is default value, no need to set */
20821
e0d0a585aa49 8015743: Address internet addresses
michaelm
parents: 17193
diff changeset
   619
                    setInet6Address_scopeid(env, iaObj, scope);
e0d0a585aa49 8015743: Address internet addresses
michaelm
parents: 17193
diff changeset
   620
                    setInet6Address_scopeifname(env, iaObj, netifObj);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                if (ibObj == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                  free_netaddr(netaddrP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                  return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        (*env)->SetObjectArrayElement(env, addrArr, addr_index, iaObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        addrs = addrs->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        addr_index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    (*env)->SetObjectField(env, netifObj, ni_addrsID, addrArr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    (*env)->SetObjectField(env, netifObj, ni_bindsID, bindsArr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    free_netaddr(netaddrP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * Windows doesn't have virtual interfaces, so child array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * is always empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    childArr = (*env)->NewObjectArray(env, 0, ni_class, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    if (childArr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
      return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    (*env)->SetObjectField(env, netifObj, ni_childsID, childArr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    /* return the NetworkInterface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    return netifObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
 * Method:    getByName0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
 * Signature: (Ljava/lang/String;)Ljava/net/NetworkInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    (JNIEnv *env, jclass cls, jstring name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    netif *ifList, *curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    jboolean isCopy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    const char *name_utf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    jobject netifObj = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   668
    // Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   669
    if (ipv6_available()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        return Java_java_net_NetworkInterface_getByName0_XP (env, cls, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    /* get the list of interfaces */
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   674
    if (enumInterfaces(env, &ifList) < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    /* get the name as a C string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
23563
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   680
    if (name_utf != NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
23563
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   682
        /* Search by name */
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   683
        curr = ifList;
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   684
        while (curr != NULL) {
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   685
            if (strcmp(name_utf, curr->name) == 0) {
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   686
                break;
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   687
            }
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   688
            curr = curr->next;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
23563
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   690
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   691
        /* if found create a NetworkInterface */
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   692
        if (curr != NULL) {;
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   693
            netifObj = createNetworkInterface(env, curr, -1, NULL);
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   694
        }
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   695
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   696
        /* release the UTF string */
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   697
        (*env)->ReleaseStringUTFChars(env, name, name_utf);
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   698
    } else {
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   699
        if (!(*env)->ExceptionCheck(env))
71ed058849d4 8025293: JNI exception pending checks in java.net
msheppar
parents: 23010
diff changeset
   700
            JNU_ThrowOutOfMemoryError(env, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    /* release the interface list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    free_netif(ifList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    return netifObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
 * Class:     NetworkInterface
1097
af4930f761df 6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents: 1094
diff changeset
   711
 * Method:    getByIndex0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
 * Signature: (I)LNetworkInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
 */
1097
af4930f761df 6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents: 1094
diff changeset
   714
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByIndex0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
  (JNIEnv *env, jclass cls, jint index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    netif *ifList, *curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    jobject netifObj = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   720
    // Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   721
    if (ipv6_available()) {
1097
af4930f761df 6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents: 1094
diff changeset
   722
        return Java_java_net_NetworkInterface_getByIndex0_XP (env, cls, index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    /* get the list of interfaces */
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   726
    if (enumInterfaces(env, &ifList) < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    /* search by index */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    curr = ifList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    while (curr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        if (index == curr->index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        curr = curr->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    /* if found create a NetworkInterface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    if (curr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        netifObj = createNetworkInterface(env, curr, -1, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    /* release the interface list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    free_netif(ifList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    return netifObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
 * Method:    getByInetAddress0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
 * Signature: (Ljava/net/InetAddress;)Ljava/net/NetworkInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    (JNIEnv *env, jclass cls, jobject iaObj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    netif *ifList, *curr;
51151
d6b131d2bc8b 8193419: Better Internet address support
vtewari
parents: 47216
diff changeset
   759
    jobject netifObj = NULL;
16870
f35b2bd19761 8000724: Improve networking serialization
michaelm
parents: 14768
diff changeset
   760
    jint addr = getInetAddress_addr(env, iaObj);
51151
d6b131d2bc8b 8193419: Better Internet address support
vtewari
parents: 47216
diff changeset
   761
    JNU_CHECK_EXCEPTION_RETURN(env, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   763
    // Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   764
    if (ipv6_available()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        return Java_java_net_NetworkInterface_getByInetAddress0_XP (env, cls, iaObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    /* get the list of interfaces */
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   769
    if (enumInterfaces(env, &ifList) < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * Enumerate the addresses on each interface until we find a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * matching address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    curr = ifList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    while (curr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        netaddr *addrList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        netaddr *addrP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        /* enumerate the addresses on this interface */
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   784
        count = enumAddresses_win(env, curr, &addrList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        if (count < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            free_netif(ifList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        /* iterate through each address */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        addrP = addrList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        while (addrP != NULL) {
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26595
diff changeset
   794
            if ((unsigned long)addr == ntohl(addrP->addr.sa4.sin_addr.s_addr)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            addrP = addrP->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
         * Address matched so create NetworkInterface for this interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
         * and address list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        if (addrP != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            /* createNetworkInterface will free addrList */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            netifObj = createNetworkInterface(env, curr, count, addrList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        /* on next interface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        curr = curr->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    /* release the interface list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    free_netif(ifList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    return netifObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
 * Method:    getAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
 * Signature: ()[Ljava/net/NetworkInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
JNIEXPORT jobjectArray JNICALL Java_java_net_NetworkInterface_getAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    netif *ifList, *curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    jobjectArray netIFArr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    jint arr_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   833
    // Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   834
    if (ipv6_available()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        return Java_java_net_NetworkInterface_getAll_XP (env, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * Get list of interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     */
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   841
    count = enumInterfaces(env, &ifList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    if (count < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    /* allocate a NetworkInterface array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    netIFArr = (*env)->NewObjectArray(env, count, cls, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    if (netIFArr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * Iterate through the interfaces, create a NetworkInterface instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * for each array element and populate the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    curr = ifList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    arr_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    while (curr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        jobject netifObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        netifObj = createNetworkInterface(env, curr, -1, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        if (netifObj == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        /* put the NetworkInterface into the array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        (*env)->SetObjectArrayElement(env, netIFArr, arr_index++, netifObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        curr = curr->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    /* release the interface list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    free_netif(ifList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    return netIFArr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
 * Method:    isUp0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
 * Signature: (Ljava/lang/String;)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isUp0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    (JNIEnv *env, jclass cls, jstring name, jint index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
  jboolean ret = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   887
  // Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   888
  if (ipv6_available()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    return Java_java_net_NetworkInterface_isUp0_XP(env, cls, name, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    MIB_IFROW *ifRowP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    ifRowP = getIF(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    if (ifRowP != NULL) {
19866
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents: 17193
diff changeset
   894
      ret = ifRowP->dwAdminStatus == MIB_IF_ADMIN_STATUS_UP &&
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   895
            (ifRowP->dwOperStatus == MIB_IF_OPER_STATUS_OPERATIONAL ||
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   896
             ifRowP->dwOperStatus == MIB_IF_OPER_STATUS_CONNECTED);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
      free(ifRowP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
 * Method:    isP2P0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
 * Signature: (Ljava/lang/String;I)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
 */
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   908
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isP2P0
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   909
    (JNIEnv *env, jclass cls, jstring name, jint index) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
  MIB_IFROW *ifRowP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
  jboolean ret = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   913
  // Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   914
  if (ipv6_available()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    return Java_java_net_NetworkInterface_isP2P0_XP(env, cls, name, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    ifRowP = getIF(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    if (ifRowP != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
      switch(ifRowP->dwType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
      case MIB_IF_TYPE_PPP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
      case MIB_IF_TYPE_SLIP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        ret = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
      free(ifRowP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
  return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
 * Method:    isLoopback0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
 * Signature: (Ljava/lang/String;I)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isLoopback0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    (JNIEnv *env, jclass cls, jstring name, jint index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
  MIB_IFROW *ifRowP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
  jboolean ret = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   941
  // Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   942
  if (ipv6_available()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    return Java_java_net_NetworkInterface_isLoopback0_XP(env, cls, name, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    ifRowP = getIF(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    if (ifRowP != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
      if (ifRowP->dwType == MIB_IF_TYPE_LOOPBACK)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        ret = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
      free(ifRowP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
 * Method:    supportsMulticast0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
 * Signature: (Ljava/lang/String;I)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_supportsMulticast0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    (JNIEnv *env, jclass cls, jstring name, jint index) {
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   962
    return Java_java_net_NetworkInterface_supportsMulticast0_XP(env, cls,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                                                               name, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
 * Method:    getMacAddr0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
 * Signature: ([bLjava/lang/String;I)[b
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
 */
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   971
JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   972
    (JNIEnv *env, jclass class, jbyteArray addrArray, jstring name, jint index) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
  jbyteArray ret = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
  int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
  MIB_IFROW *ifRowP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   977
  // Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
   978
  if (ipv6_available()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    return Java_java_net_NetworkInterface_getMacAddr0_XP(env, class, name, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    ifRowP = getIF(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    if (ifRowP != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
      switch(ifRowP->dwType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
      case MIB_IF_TYPE_ETHERNET:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
      case MIB_IF_TYPE_TOKENRING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
      case MIB_IF_TYPE_FDDI:
12542
31190502e9e3 7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN
khazra
parents: 10417
diff changeset
   987
      case IF_TYPE_IEEE80211:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        len = ifRowP->dwPhysAddrLen;
26595
1f96f8175e05 8058216: NetworkInterface.getHardwareAddress can return zero length byte array when run with preferIPv4Stack
chegar
parents: 25859
diff changeset
   989
        if (len > 0) {
1f96f8175e05 8058216: NetworkInterface.getHardwareAddress can return zero length byte array when run with preferIPv4Stack
chegar
parents: 25859
diff changeset
   990
            ret = (*env)->NewByteArray(env, len);
1f96f8175e05 8058216: NetworkInterface.getHardwareAddress can return zero length byte array when run with preferIPv4Stack
chegar
parents: 25859
diff changeset
   991
            if (!IS_NULL(ret)) {
1f96f8175e05 8058216: NetworkInterface.getHardwareAddress can return zero length byte array when run with preferIPv4Stack
chegar
parents: 25859
diff changeset
   992
              (*env)->SetByteArrayRegion(env, ret, 0, len, (jbyte *) ifRowP->bPhysAddr);
1f96f8175e05 8058216: NetworkInterface.getHardwareAddress can return zero length byte array when run with preferIPv4Stack
chegar
parents: 25859
diff changeset
   993
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
      free(ifRowP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
 * Class:       java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
 * Method:      getMTU0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
 * Signature:   ([bLjava/lang/String;I)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
 */
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
  1008
JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
  1009
    (JNIEnv *env, jclass class, jstring name, jint index) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
  jint ret = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
  MIB_IFROW *ifRowP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
9003
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
  1013
  // Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
e1b0f0099915 7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
chegar
parents: 5506
diff changeset
  1014
  if (ipv6_available()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    return Java_java_net_NetworkInterface_getMTU0_XP(env, class, name, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    ifRowP = getIF(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    if (ifRowP != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
      ret = ifRowP->dwMtu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
      free(ifRowP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
}