jdk/src/solaris/native/java/net/NetworkInterface.c
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8554 14e626e9407b
child 10605 8c19a790b7c1
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8554
diff changeset
     2
 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
    26
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <errno.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <strings.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <netinet/in.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <sys/socket.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <arpa/inet.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <net/if.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <net/if_arp.h>
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
    37
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#ifdef __solaris__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <sys/dlpi.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <fcntl.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include <stropts.h>
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
    42
#include <sys/sockio.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#endif
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
    44
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include <sys/ioctl.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#include <bits/ioctls.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#include <sys/utsname.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#define _PATH_PROCNET_IFINET6           "/proc/net/if_inet6"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#include "jvm.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#include "net_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
typedef struct _netaddr  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    struct sockaddr *addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    struct sockaddr *brdcast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    short mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    int family; /* to make searches simple */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    struct _netaddr *next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
} netaddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
typedef struct _netif {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    char *name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    char virtual;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    netaddr *addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    struct _netif *childs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    struct _netif *next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
} netif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
#include "java_net_NetworkInterface.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
/************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
jclass ni_class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
jfieldID ni_nameID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
jfieldID ni_indexID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
jfieldID ni_descID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
jfieldID ni_addrsID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
jfieldID ni_bindsID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
jfieldID ni_virutalID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
jfieldID ni_childsID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
jfieldID ni_parentID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
jmethodID ni_ctrID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
static jclass ni_iacls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
static jclass ni_ia4cls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
static jclass ni_ia6cls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
static jclass ni_ibcls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
static jmethodID ni_ia4ctrID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
static jmethodID ni_ia6ctrID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
static jmethodID ni_ibctrID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
static jfieldID ni_iaaddressID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
static jfieldID ni_iafamilyID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
static jfieldID ni_ia6ipaddressID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
static jfieldID ni_ibaddressID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
static jfieldID ni_ib4broadcastID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
static jfieldID ni_ib4maskID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   111
/** Private methods declarations **/
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
static jobject createNetworkInterface(JNIEnv *env, netif *ifs);
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   113
static int     getFlags0(JNIEnv *env, jstring  ifname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   115
static netif  *enumInterfaces(JNIEnv *env);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   116
static netif  *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   117
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
#ifdef AF_INET6
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   119
static netif  *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   122
static netif  *addif(JNIEnv *env, int sock, const char * if_name, netif *ifs, struct sockaddr* ifr_addrP, int family, short prefix);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   123
static void    freeif(netif *ifs);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   124
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   125
static int     openSocket(JNIEnv *env, int proto);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   126
static int     openSocketWithFallback(JNIEnv *env, const char *ifname);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   127
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   128
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   129
static struct  sockaddr *getBroadcast(JNIEnv *env, int sock, const char *name, struct sockaddr *brdcast_store);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   130
static short   getSubnet(JNIEnv *env, int sock, const char *ifname);
6002
4df5b9bcf842 6967937: Scope id no longer being set after 6931566
chegar
parents: 5969
diff changeset
   131
static int     getIndex(int sock, const char *ifname);
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   132
6129
e76ab178e431 6972374: NetworkInterface.getNetworkInterfaces throws "java.net.SocketException" on Solaris zone
chegar
parents: 6108
diff changeset
   133
static int     getFlags(int sock, const char *ifname);
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   134
static int     getMacAddress(JNIEnv *env, int sock,  const char* ifname, const struct in_addr* addr, unsigned char *buf);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   135
static int     getMTU(JNIEnv *env, int sock, const char *ifname);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   136
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   137
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   138
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   139
#ifdef __solaris__
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   140
static netif *enumIPvXInterfaces(JNIEnv *env, int sock, netif *ifs, int family);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   141
static int    getMacFromDevice(JNIEnv *env, const char* ifname, unsigned char* retbuf);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   142
#endif
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   143
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   144
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   145
/******************* Java entry points *****************************/
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * Method:    init
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
Java_java_net_NetworkInterface_init(JNIEnv *env, jclass cls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    ni_class = (*env)->FindClass(env,"java/net/NetworkInterface");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    ni_class = (*env)->NewGlobalRef(env, ni_class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    ni_nameID = (*env)->GetFieldID(env, ni_class,"name", "Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    ni_indexID = (*env)->GetFieldID(env, ni_class, "index", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    ni_addrsID = (*env)->GetFieldID(env, ni_class, "addrs", "[Ljava/net/InetAddress;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    ni_bindsID = (*env)->GetFieldID(env, ni_class, "bindings", "[Ljava/net/InterfaceAddress;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    ni_descID = (*env)->GetFieldID(env, ni_class, "displayName", "Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    ni_virutalID = (*env)->GetFieldID(env, ni_class, "virtual", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    ni_childsID = (*env)->GetFieldID(env, ni_class, "childs", "[Ljava/net/NetworkInterface;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    ni_parentID = (*env)->GetFieldID(env, ni_class, "parent", "Ljava/net/NetworkInterface;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    ni_ctrID = (*env)->GetMethodID(env, ni_class, "<init>", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    ni_ia6cls = (*env)->FindClass(env, "java/net/Inet6Address");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    ni_ia6cls = (*env)->NewGlobalRef(env, ni_ia6cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    ni_ibcls = (*env)->FindClass(env, "java/net/InterfaceAddress");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    ni_ibcls = (*env)->NewGlobalRef(env, ni_ibcls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "<init>", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    ni_ibctrID = (*env)->GetMethodID(env, ni_ibcls, "<init>", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    ni_iaaddressID = (*env)->GetFieldID(env, ni_iacls, "address", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    ni_iafamilyID = (*env)->GetFieldID(env, ni_iacls, "family", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    ni_ia6ipaddressID = (*env)->GetFieldID(env, ni_ia6cls, "ipaddress", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    ni_ibaddressID = (*env)->GetFieldID(env, ni_ibcls, "address", "Ljava/net/InetAddress;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    ni_ib4broadcastID = (*env)->GetFieldID(env, ni_ibcls, "broadcast", "Ljava/net/Inet4Address;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    ni_ib4maskID = (*env)->GetFieldID(env, ni_ibcls, "maskLength", "S");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * Method:    getByName0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * Signature: (Ljava/lang/String;)Ljava/net/NetworkInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    (JNIEnv *env, jclass cls, jstring name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    netif *ifs, *curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    jboolean isCopy;
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   196
    const char* name_utf;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    jobject obj = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    ifs = enumInterfaces(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    if (ifs == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   204
    name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   205
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Search the list of interface based on name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    curr = ifs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    while (curr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (strcmp(name_utf, curr->name) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        curr = curr->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /* if found create a NetworkInterface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    if (curr != NULL) {;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        obj = createNetworkInterface(env, curr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /* release the UTF string and interface list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    (*env)->ReleaseStringUTFChars(env, name, name_utf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    freeif(ifs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    return obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 * Class:     java_net_NetworkInterface
1097
af4930f761df 6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents: 910
diff changeset
   232
 * Method:    getByIndex0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 * Signature: (Ljava/lang/String;)Ljava/net/NetworkInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 */
1097
af4930f761df 6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents: 910
diff changeset
   235
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByIndex0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    (JNIEnv *env, jclass cls, jint index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    netif *ifs, *curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    jobject obj = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    if (index <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    ifs = enumInterfaces(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    if (ifs == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Search the list of interface based on index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    curr = ifs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    while (curr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (index == curr->index) {
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
        curr = curr->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /* if found create a NetworkInterface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    if (curr != NULL) {;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        obj = createNetworkInterface(env, curr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    freeif(ifs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    return obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 * Method:    getByInetAddress0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 * Signature: (Ljava/net/InetAddress;)Ljava/net/NetworkInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    (JNIEnv *env, jclass cls, jobject iaObj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    netif *ifs, *curr;
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   279
4814
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 2163
diff changeset
   280
#ifdef AF_INET6
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   281
    int family = (  (*env)->GetIntField(env, iaObj, ni_iafamilyID) == IPv4 ) ? AF_INET : AF_INET6;
4814
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 2163
diff changeset
   282
#else
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   283
    int family =  AF_INET;
4814
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 2163
diff changeset
   284
#endif
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   285
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    jobject obj = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    jboolean match = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    ifs = enumInterfaces(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    if (ifs == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    curr = ifs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    while (curr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        netaddr *addrP = curr->addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
         * Iterate through each address on the interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        while (addrP != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            if (family == addrP->family) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                if (family == AF_INET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    int address1 = htonl(((struct sockaddr_in*)addrP->addr)->sin_addr.s_addr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    int address2 = (*env)->GetIntField(env, iaObj, ni_iaaddressID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                    if (address1 == address2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                        match = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
#ifdef AF_INET6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                if (family == AF_INET6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    jbyte *bytes = (jbyte *)&(((struct sockaddr_in6*)addrP->addr)->sin6_addr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    jbyteArray ipaddress = (*env)->GetObjectField(env, iaObj, ni_ia6ipaddressID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    jbyte caddr[16];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                    (*env)->GetByteArrayRegion(env, ipaddress, 0, 16, caddr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                    while (i < 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                        if (caddr[i] != bytes[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    if (i >= 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                        match = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            if (match) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            addrP = addrP->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (match) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        curr = curr->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /* if found create a NetworkInterface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    if (match) {;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        obj = createNetworkInterface(env, curr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    freeif(ifs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    return obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
 * Class:     java_net_NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
 * Method:    getAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
 * Signature: ()[Ljava/net/NetworkInterface;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
JNIEXPORT jobjectArray JNICALL Java_java_net_NetworkInterface_getAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    (JNIEnv *env, jclass cls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    netif *ifs, *curr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    jobjectArray netIFArr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    jint arr_index, ifCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    ifs = enumInterfaces(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    if (ifs == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /* count the interface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    ifCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    curr = ifs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    while (curr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        ifCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        curr = curr->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /* allocate a NetworkInterface array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    netIFArr = (*env)->NewObjectArray(env, ifCount, cls, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    if (netIFArr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        freeif(ifs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * Iterate through the interfaces, create a NetworkInterface instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * for each array element and populate the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    curr = ifs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    arr_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    while (curr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        jobject netifObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        netifObj = createNetworkInterface(env, curr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        if (netifObj == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            freeif(ifs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        /* put the NetworkInterface into the array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        (*env)->SetObjectArrayElement(env, netIFArr, arr_index++, netifObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        curr = curr->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    freeif(ifs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    return netIFArr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   417
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   418
/*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   419
 * Class:     java_net_NetworkInterface
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   420
 * Method:    isUp0
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   421
 * Signature: (Ljava/lang/String;I)Z
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   422
 */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   423
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isUp0(JNIEnv *env, jclass cls, jstring name, jint index) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   424
    int ret = getFlags0(env, name);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   425
    return ((ret & IFF_UP) && (ret & IFF_RUNNING)) ? JNI_TRUE :  JNI_FALSE;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   426
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   427
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   428
/*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   429
 * Class:     java_net_NetworkInterface
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   430
 * Method:    isP2P0
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   431
 * Signature: (Ljava/lang/String;I)Z
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   432
 */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   433
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isP2P0(JNIEnv *env, jclass cls, jstring name, jint index) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   434
    int ret = getFlags0(env, name);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   435
    return (ret & IFF_POINTOPOINT) ? JNI_TRUE :  JNI_FALSE;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   436
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   437
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   438
/*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   439
 * Class:     java_net_NetworkInterface
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   440
 * Method:    isLoopback0
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   441
 * Signature: (Ljava/lang/String;I)Z
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   442
 */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   443
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isLoopback0(JNIEnv *env, jclass cls, jstring name, jint index) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   444
    int ret = getFlags0(env, name);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   445
    return (ret & IFF_LOOPBACK) ? JNI_TRUE :  JNI_FALSE;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   446
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   447
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   448
/*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   449
 * Class:     java_net_NetworkInterface
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   450
 * Method:    supportsMulticast0
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   451
 * Signature: (Ljava/lang/String;I)Z
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   452
 */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   453
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_supportsMulticast0(JNIEnv *env, jclass cls, jstring name, jint index) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   454
    int ret = getFlags0(env, name);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   455
    return (ret & IFF_MULTICAST) ? JNI_TRUE :  JNI_FALSE;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   456
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   457
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   458
/*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   459
 * Class:     java_net_NetworkInterface
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   460
 * Method:    getMacAddr0
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   461
 * Signature: ([bLjava/lang/String;I)[b
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   462
 */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   463
JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0(JNIEnv *env, jclass class, jbyteArray addrArray, jstring name, jint index) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   464
    jint addr;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   465
    jbyte caddr[4];
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   466
    struct in_addr iaddr;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   467
    jbyteArray ret = NULL;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   468
    unsigned char mac[16];
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   469
    int len;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   470
    int sock;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   471
    jboolean isCopy;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   472
    const char* name_utf;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   473
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   474
    name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   475
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   476
    if ((sock =openSocketWithFallback(env, name_utf)) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   477
       (*env)->ReleaseStringUTFChars(env, name, name_utf);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   478
       return JNI_FALSE;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   479
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   480
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   481
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   482
    if (!IS_NULL(addrArray)) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   483
       (*env)->GetByteArrayRegion(env, addrArray, 0, 4, caddr);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   484
       addr = ((caddr[0]<<24) & 0xff000000);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   485
       addr |= ((caddr[1] <<16) & 0xff0000);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   486
       addr |= ((caddr[2] <<8) & 0xff00);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   487
       addr |= (caddr[3] & 0xff);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   488
       iaddr.s_addr = htonl(addr);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   489
       len = getMacAddress(env, sock, name_utf, &iaddr, mac);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   490
    } else {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   491
       len = getMacAddress(env, sock, name_utf,NULL, mac);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   492
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   493
    if (len > 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   494
       ret = (*env)->NewByteArray(env, len);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   495
       if (IS_NULL(ret)) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   496
          /* we may have memory to free at the end of this */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   497
          goto fexit;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   498
       }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   499
       (*env)->SetByteArrayRegion(env, ret, 0, len, (jbyte *) (mac));
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   500
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   501
 fexit:
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   502
   /* release the UTF string and interface list */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   503
   (*env)->ReleaseStringUTFChars(env, name, name_utf);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   504
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   505
   close(sock);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   506
   return ret;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   507
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   508
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   509
/*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   510
 * Class:       java_net_NetworkInterface
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   511
 * Method:      getMTU0
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   512
 * Signature:   ([bLjava/lang/String;I)I
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   513
 */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   514
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   515
JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0(JNIEnv *env, jclass class, jstring name, jint index) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   516
    jboolean isCopy;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   517
    int ret = -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   518
    int sock;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   519
    const char* name_utf;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   520
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   521
    name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   522
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   523
    if ((sock =openSocketWithFallback(env, name_utf)) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   524
       (*env)->ReleaseStringUTFChars(env, name, name_utf);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   525
       return JNI_FALSE;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   526
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   527
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   528
    ret = getMTU(env, sock, name_utf);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   529
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   530
    (*env)->ReleaseStringUTFChars(env, name, name_utf);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   531
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   532
    close(sock);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   533
    return ret;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   534
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   535
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   536
/*** Private methods definitions ****/
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   537
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   538
static int getFlags0(JNIEnv *env, jstring name) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   539
    jboolean isCopy;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   540
    int ret, sock;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   541
    const char* name_utf;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   542
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   543
    name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   544
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   545
    if ((sock = openSocketWithFallback(env, name_utf)) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   546
        (*env)->ReleaseStringUTFChars(env, name, name_utf);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   547
         return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   548
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   549
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   550
    name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   551
6129
e76ab178e431 6972374: NetworkInterface.getNetworkInterfaces throws "java.net.SocketException" on Solaris zone
chegar
parents: 6108
diff changeset
   552
    ret = getFlags(sock, name_utf);
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   553
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   554
    close(sock);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   555
    (*env)->ReleaseStringUTFChars(env, name, name_utf);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   556
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   557
    if (ret < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   558
        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL  SIOCGLIFFLAGS failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   559
        return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   560
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   561
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   562
    return ret;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   563
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   564
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   565
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   566
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   567
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
 * Create a NetworkInterface object, populate the name and index, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
 * populate the InetAddress array based on the IP addresses for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
 * interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
 */
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   573
jobject createNetworkInterface(JNIEnv *env, netif *ifs) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    jobject netifObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    jobject name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    jobjectArray addrArr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    jobjectArray bindArr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    jobjectArray childArr;
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   579
    netaddr *addrs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    jint addr_index, addr_count, bind_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    jint child_count, child_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    netaddr *addrP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    netif *childP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    jobject tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * Create a NetworkInterface object and populate it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    netifObj = (*env)->NewObject(env, ni_class, ni_ctrID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    name = (*env)->NewStringUTF(env, ifs->name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    if (netifObj == NULL || name == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    (*env)->SetObjectField(env, netifObj, ni_nameID, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    (*env)->SetObjectField(env, netifObj, ni_descID, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    (*env)->SetIntField(env, netifObj, ni_indexID, ifs->index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    (*env)->SetBooleanField(env, netifObj, ni_virutalID, ifs->virtual ? JNI_TRUE : JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * Count the number of address on this interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    addr_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    addrP = ifs->addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    while (addrP != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        addr_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        addrP = addrP->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * Create the array of InetAddresses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    addrArr = (*env)->NewObjectArray(env, addr_count,  ni_iacls, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    if (addrArr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    bindArr = (*env)->NewObjectArray(env, addr_count, ni_ibcls, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    if (bindArr == NULL) {
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   619
       return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    addrP = ifs->addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    addr_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    bind_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    while (addrP != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        jobject iaObj = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        jobject ibObj = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        if (addrP->family == AF_INET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            if (iaObj) {
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   631
                 (*env)->SetIntField(env, iaObj, ni_iaaddressID, htonl(((struct sockaddr_in*)addrP->addr)->sin_addr.s_addr));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            if (ibObj) {
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   635
                 (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   636
                 if (addrP->brdcast) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   637
                    jobject ia2Obj = NULL;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   638
                    ia2Obj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   639
                    if (ia2Obj) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   640
                       (*env)->SetIntField(env, ia2Obj, ni_iaaddressID,
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   641
                                                               htonl(((struct sockaddr_in*)addrP->brdcast)->sin_addr.s_addr));
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   642
                       (*env)->SetObjectField(env, ibObj, ni_ib4broadcastID, ia2Obj);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   643
                       (*env)->SetShortField(env, ibObj, ni_ib4maskID, addrP->mask);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   644
                    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   645
                 }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   646
                 (*env)->SetObjectArrayElement(env, bindArr, bind_index++, ibObj);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
#ifdef AF_INET6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        if (addrP->family == AF_INET6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            int scope=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            if (iaObj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                jbyteArray ipaddress = (*env)->NewByteArray(env, 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                if (ipaddress == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                (*env)->SetByteArrayRegion(env, ipaddress, 0, 16,
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   660
                                                                        (jbyte *)&(((struct sockaddr_in6*)addrP->addr)->sin6_addr));
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   661
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                scope = ((struct sockaddr_in6*)addrP->addr)->sin6_scope_id;
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   663
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                if (scope != 0) { /* zero is default value, no need to set */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                    (*env)->SetIntField(env, iaObj, ia6_scopeidID, scope);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                    (*env)->SetBooleanField(env, iaObj, ia6_scopeidsetID, JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                    (*env)->SetObjectField(env, iaObj, ia6_scopeifnameID, netifObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                (*env)->SetObjectField(env, iaObj, ni_ia6ipaddressID, ipaddress);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            if (ibObj) {
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   673
                (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   674
                (*env)->SetShortField(env, ibObj, ni_ib4maskID, addrP->mask);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   675
                (*env)->SetObjectArrayElement(env, bindArr, bind_index++, ibObj);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        if (iaObj == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        (*env)->SetObjectArrayElement(env, addrArr, addr_index++, iaObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        addrP = addrP->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * See if there is any virtual interface attached to this one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    child_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    childP = ifs->childs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    while (childP) {
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   694
        child_count++;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   695
        childP = childP->next;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    childArr = (*env)->NewObjectArray(env, child_count, ni_class, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    if (childArr == NULL) {
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   700
        return 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
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * Create the NetworkInterface instances for the sub-interfaces as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    child_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    childP = ifs->childs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    while(childP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
      tmp = createNetworkInterface(env, childP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
      if (tmp == NULL) {
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   712
         return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
      (*env)->SetObjectField(env, tmp, ni_parentID, netifObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
      (*env)->SetObjectArrayElement(env, childArr, child_index++, tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
      childP = childP->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    (*env)->SetObjectField(env, netifObj, ni_addrsID, addrArr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    (*env)->SetObjectField(env, netifObj, ni_bindsID, bindArr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    (*env)->SetObjectField(env, netifObj, ni_childsID, childArr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    /* return the NetworkInterface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    return netifObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
 * Enumerates all interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
static netif *enumInterfaces(JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    netif *ifs;
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   731
    int sock;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * Enumerate IPv4 addresses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     */
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   736
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   737
    sock = openSocket(env, AF_INET);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   738
    if (sock < 0 && (*env)->ExceptionOccurred(env)) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   739
        return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   742
    ifs = enumIPv4Interfaces(env, sock, NULL);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   743
    close(sock);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   744
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   745
    if (ifs == NULL && (*env)->ExceptionOccurred(env)) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   746
        return NULL;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   747
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   748
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   749
    /* return partial list if exception occure in the middle of process ???*/
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   750
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * If IPv6 is available then enumerate IPv6 addresses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
#ifdef AF_INET6
6108
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   755
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   756
        /* User can disable ipv6 expicitly by -Djava.net.preferIPv4Stack=true,
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   757
         * so we have to call ipv6_available()
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   758
         */
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   759
        if (ipv6_available()) {
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   760
6108
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   761
           sock =  openSocket(env, AF_INET6);
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   762
           if (sock < 0 && (*env)->ExceptionOccurred(env)) {
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   763
               freeif(ifs);
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   764
               return NULL;
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   765
           }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
6108
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   767
           ifs = enumIPv6Interfaces(env, sock, ifs);
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   768
           close(sock);
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   769
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   770
           if ((*env)->ExceptionOccurred(env)) {
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   771
              freeif(ifs);
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   772
              return NULL;
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   773
           }
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   774
d5bfa0bc6123 6964714: NetworkInterface getInetAddresses enumerates IPv6 addresses if java.net.preferIPvStack property set
dsamersoff
parents: 6002
diff changeset
   775
       }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    return ifs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   781
#define CHECKED_MALLOC3(_pointer,_type,_size) \
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   782
       do{ \
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   783
        _pointer = (_type)malloc( _size ); \
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   784
        if (_pointer == NULL) { \
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   785
            JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); \
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   786
            return ifs; /* return untouched list */ \
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   787
        } \
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   788
       } while(0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
 * Free an interface list (including any attached addresses)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
void freeif(netif *ifs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    netif *currif = ifs;
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   796
    netif *child = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    while (currif != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        netaddr *addrP = currif->addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        while (addrP != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            netaddr *next = addrP->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            free(addrP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            addrP = next;
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   804
         }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   806
            /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   807
            * Don't forget to free the sub-interfaces.
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   808
            */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   809
          if (currif->childs != NULL) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   810
                freeif(currif->childs);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   811
          }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   813
          ifs = currif->next;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   814
          free(currif);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   815
          currif = ifs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   819
netif *addif(JNIEnv *env, int sock, const char * if_name, netif *ifs, struct sockaddr* ifr_addrP, int family, short prefix) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   820
    netif *currif = ifs, *parent;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    netaddr *addrP;
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   822
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   823
    #ifdef __solaris__
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   824
    char name[LIFNAMSIZ],  vname[LIFNAMSIZ];
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   825
    #else
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   826
    char name[IFNAMSIZ],  vname[IFNAMSIZ];
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   827
    #endif
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   828
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   829
    char  *name_colonP;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   830
    int mask;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    int isVirtual = 0;
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   832
    int addr_size;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * If the interface name is a logical interface then we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * remove the unit number so that we have the physical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * interface (eg: hme0:1 -> hme0). NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * currently doesn't have any concept of physical vs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * logical interfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    strcpy(name, if_name);
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   842
    *vname = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * Create and populate the netaddr node. If allocation fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * return an un-updated list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     */
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   848
    /*Allocate for addr and brdcast at once*/
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   849
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   850
#ifdef AF_INET6
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   851
    addr_size = (family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   852
#else
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   853
    addr_size = sizeof(struct sockaddr_in);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   854
#endif
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   855
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   856
    CHECKED_MALLOC3(addrP, netaddr *, sizeof(netaddr)+2*addr_size);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   857
    addrP->addr = (struct sockaddr *)( (char *) addrP+sizeof(netaddr) );
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   858
    memcpy(addrP->addr, ifr_addrP, addr_size);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   859
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    addrP->family = family;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    addrP->brdcast = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    addrP->mask = prefix;
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   863
    addrP->next = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    if (family == AF_INET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
       * Deal with brodcast addr & subnet mask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
       */
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   868
       struct sockaddr * brdcast_to = (struct sockaddr *) ((char *) addrP + sizeof(netaddr) + addr_size);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   869
       addrP->brdcast = getBroadcast(env, sock, name,  brdcast_to );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   871
       if (addrP->brdcast && (mask = getSubnet(env, sock, name)) != -1) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   872
           addrP->mask = mask;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   873
       }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   874
     }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   875
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   876
    /**
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   877
     * Deal with virtual interface with colon notaion e.g. eth0:1
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   878
     */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   879
    name_colonP = strchr(name, ':');
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   880
    if (name_colonP != NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
      /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
       * This is a virtual interface. If we are able to access the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
       * we need to create a new entry if it doesn't exist yet *and* update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
       * the 'parent' interface with the new records.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
       */
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   886
        *name_colonP = 0;
6129
e76ab178e431 6972374: NetworkInterface.getNetworkInterfaces throws "java.net.SocketException" on Solaris zone
chegar
parents: 6108
diff changeset
   887
        if (getFlags(sock, name) < 0) {
2058
577525f89bd4 6800805: java.net.NetworkInterface.getNetworkInterfaces() does not list IPv6 network interfaces correctly
chegar
parents: 1097
diff changeset
   888
            // failed to access parent interface do not create parent.
577525f89bd4 6800805: java.net.NetworkInterface.getNetworkInterfaces() does not list IPv6 network interfaces correctly
chegar
parents: 1097
diff changeset
   889
            // We are a virtual interface with no parent.
577525f89bd4 6800805: java.net.NetworkInterface.getNetworkInterfaces() does not list IPv6 network interfaces correctly
chegar
parents: 1097
diff changeset
   890
            isVirtual = 1;
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   891
            *name_colonP = ':';
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        }
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   893
        else{
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   894
           // Got access to parent, so create it if necessary.
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   895
           // Save original name to vname and truncate name by ':'
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   896
            memcpy(vname, name, sizeof(vname) );
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   897
            vname[name_colonP - name] = ':';
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   898
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * Check if this is a "new" interface. Use the interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * name for matching because index isn't supported on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * Solaris 2.6 & 7.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    while (currif != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        if (strcmp(name, currif->name) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        currif = currif->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * If "new" then create an netif structure and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * insert it onto the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    if (currif == NULL) {
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   918
         CHECKED_MALLOC3(currif, netif *, sizeof(netif)+IFNAMSIZ );
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   919
         currif->name = (char *) currif+sizeof(netif);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   920
         strcpy(currif->name, name);
6002
4df5b9bcf842 6967937: Scope id no longer being set after 6931566
chegar
parents: 5969
diff changeset
   921
         currif->index = getIndex(sock, name);
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   922
         currif->addr = NULL;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   923
         currif->childs = NULL;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   924
         currif->virtual = isVirtual;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   925
         currif->next = ifs;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   926
         ifs = currif;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * Finally insert the address on the interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    addrP->next = currif->addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    currif->addr = addrP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    parent = currif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * Let's deal with the virtual interface now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    if (vname[0]) {
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   941
        netaddr *tmpaddr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   943
        currif = parent->childs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   945
        while (currif != NULL) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   946
            if (strcmp(vname, currif->name) == 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   947
                break;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   948
            }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   949
            currif = currif->next;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        }
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   951
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   952
        if (currif == NULL) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   953
            CHECKED_MALLOC3(currif, netif *, sizeof(netif)+ IFNAMSIZ );
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   954
            currif->name = (char *) currif + sizeof(netif);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   955
            strcpy(currif->name, vname);
6002
4df5b9bcf842 6967937: Scope id no longer being set after 6931566
chegar
parents: 5969
diff changeset
   956
            currif->index = getIndex(sock, vname);
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   957
            currif->addr = NULL;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   958
           /* Need to duplicate the addr entry? */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   959
            currif->virtual = 1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   960
            currif->childs = NULL;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   961
            currif->next = parent->childs;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   962
            parent->childs = currif;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   963
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   965
        CHECKED_MALLOC3(tmpaddr, netaddr *, sizeof(netaddr)+2*addr_size);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   966
        memcpy(tmpaddr, addrP, sizeof(netaddr));
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   967
        if (addrP->addr != NULL) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   968
            tmpaddr->addr = (struct sockaddr *) ( (char*)tmpaddr + sizeof(netaddr) ) ;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   969
            memcpy(tmpaddr->addr, addrP->addr, addr_size);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   970
        }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   971
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   972
        if (addrP->brdcast != NULL) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   973
            tmpaddr->brdcast = (struct sockaddr *) ((char *) tmpaddr + sizeof(netaddr)+addr_size);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   974
            memcpy(tmpaddr->brdcast, addrP->brdcast, addr_size);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   975
        }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   976
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   977
        tmpaddr->next = currif->addr;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   978
        currif->addr = tmpaddr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    return ifs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   984
/* Open socket for further ioct calls
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   985
 * proto is AF_INET/AF_INET6
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
 */
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   987
static int  openSocket(JNIEnv *env, int proto){
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   988
    int sock;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   989
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   990
    if ((sock = JVM_Socket(proto, SOCK_DGRAM, 0)) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   991
        /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   992
         * If EPROTONOSUPPORT is returned it means we don't have
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   993
         * support  for this proto so don't throw an exception.
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   994
         */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   995
        if (errno != EPROTONOSUPPORT) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   996
            NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "Socket creation failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   997
        }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   998
        return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
   999
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1001
    return sock;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1002
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1003
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1004
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1005
/** Linux **/
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1006
#ifdef __linux__
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1007
/* Open socket for further ioct calls, try v4 socket first and
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1008
 * if it falls return v6 socket
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1009
 */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1010
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1011
#ifdef AF_INET6
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1012
static int openSocketWithFallback(JNIEnv *env, const char *ifname){
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1013
    int sock;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1014
    struct ifreq if2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1016
     if ((sock = JVM_Socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1017
         if (errno == EPROTONOSUPPORT){
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1018
              if ( (sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0)) < 0 ){
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1019
                 NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "IPV6 Socket creation failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1020
                 return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1021
              }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1022
         }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1023
         else{ // errno is not NOSUPPORT
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1024
             NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "IPV4 Socket creation failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1025
             return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1026
         }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1027
   }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1028
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1029
     /* Linux starting from 2.6.? kernel allows ioctl call with either IPv4 or IPv6 socket regardless of type
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1030
        of address of an interface */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1031
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1032
       return sock;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1033
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1034
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1035
#else
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1036
static int openSocketWithFallback(JNIEnv *env, const char *ifname){
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1037
    return openSocket(env,AF_INET);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1038
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1039
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1041
static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1042
    struct ifconf ifc;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1043
    struct ifreq *ifreqP;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1044
    char *buf;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1045
    int numifs;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1046
    unsigned i;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1047
709
4d98e12330e6 6628569: api/java_net/MulticastSocket/descriptions.html#setTTL fails is ipv6 configured
chegar
parents: 2
diff changeset
  1048
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1049
    /* need to do a dummy SIOCGIFCONF to determine the buffer size.
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1050
     * SIOCGIFCOUNT doesn't work
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1051
     */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1052
    ifc.ifc_buf = NULL;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1053
    if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1054
        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "ioctl SIOCGIFCONF failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1055
        return ifs;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1056
    }
709
4d98e12330e6 6628569: api/java_net/MulticastSocket/descriptions.html#setTTL fails is ipv6 configured
chegar
parents: 2
diff changeset
  1057
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1058
    CHECKED_MALLOC3(buf,char *, ifc.ifc_len);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1059
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1060
    ifc.ifc_buf = buf;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1061
    if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1062
        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "ioctl SIOCGIFCONF failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1063
        (void) free(buf);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1064
        return ifs;
709
4d98e12330e6 6628569: api/java_net/MulticastSocket/descriptions.html#setTTL fails is ipv6 configured
chegar
parents: 2
diff changeset
  1065
    }
4d98e12330e6 6628569: api/java_net/MulticastSocket/descriptions.html#setTTL fails is ipv6 configured
chegar
parents: 2
diff changeset
  1066
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1067
    /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1068
     * Iterate through each interface
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1069
     */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1070
    ifreqP = ifc.ifc_req;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1071
    for (i=0; i<ifc.ifc_len/sizeof (struct ifreq); i++, ifreqP++) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1072
        /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1073
         * Add to the list
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1074
         */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1075
        ifs = addif(env, sock, ifreqP->ifr_name, ifs, (struct sockaddr *) & (ifreqP->ifr_addr), AF_INET, 0);
709
4d98e12330e6 6628569: api/java_net/MulticastSocket/descriptions.html#setTTL fails is ipv6 configured
chegar
parents: 2
diff changeset
  1076
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1077
        /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1078
         * If an exception occurred then free the list
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1079
         */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1080
        if ((*env)->ExceptionOccurred(env)) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1081
            free(buf);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1082
            freeif(ifs);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1083
            return NULL;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1084
        }
709
4d98e12330e6 6628569: api/java_net/MulticastSocket/descriptions.html#setTTL fails is ipv6 configured
chegar
parents: 2
diff changeset
  1085
    }
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1086
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1087
    /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1088
     * Free socket and buffer
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1089
     */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1090
    free(buf);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1091
    return ifs;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1092
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1093
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1094
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1095
/*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1096
 * Enumerates and returns all IPv6 interfaces on Linux
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1097
 */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1098
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1099
#ifdef AF_INET6
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1100
static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1101
    FILE *f;
8554
14e626e9407b 7022269: clean up fscanf usage in Linux networking native code
chegar
parents: 8549
diff changeset
  1102
    char addr6[40], devname[21];
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1103
    char addr6p[8][5];
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1104
    int plen, scope, dad_status, if_idx;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1105
    uint8_t ipv6addr[16];
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1106
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1107
    if ((f = fopen(_PATH_PROCNET_IFINET6, "r")) != NULL) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1108
        while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n",
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1109
                         addr6p[0], addr6p[1], addr6p[2], addr6p[3], addr6p[4], addr6p[5], addr6p[6], addr6p[7],
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1110
                         &if_idx, &plen, &scope, &dad_status, devname) != EOF) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1111
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1112
            struct netif *ifs_ptr = NULL;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1113
            struct netif *last_ptr = NULL;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1114
            struct sockaddr_in6 addr;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1115
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1116
            sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s",
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1117
                           addr6p[0], addr6p[1], addr6p[2], addr6p[3], addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1118
            inet_pton(AF_INET6, addr6, ipv6addr);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1119
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1120
            memset(&addr, 0, sizeof(struct sockaddr_in6));
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1121
            memcpy((void*)addr.sin6_addr.s6_addr, (const void*)ipv6addr, 16);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1122
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1123
            addr.sin6_scope_id = if_idx;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1124
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1125
            ifs = addif(env, sock, devname, ifs, (struct sockaddr *)&addr, AF_INET6, plen);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1126
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1127
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1128
            /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1129
             * If an exception occurred then return the list as is.
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1130
             */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1131
            if ((*env)->ExceptionOccurred(env)) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1132
                fclose(f);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1133
                return ifs;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1134
            }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1135
       }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1136
       fclose(f);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1137
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1138
    return ifs;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1139
}
709
4d98e12330e6 6628569: api/java_net/MulticastSocket/descriptions.html#setTTL fails is ipv6 configured
chegar
parents: 2
diff changeset
  1140
#endif
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1141
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
6002
4df5b9bcf842 6967937: Scope id no longer being set after 6931566
chegar
parents: 5969
diff changeset
  1143
static int getIndex(int sock, const char *name){
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1144
     /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1145
      * Try to get the interface index
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1146
      * (Not supported on Solaris 2.6 or 7)
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1147
      */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1148
    struct ifreq if2;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1149
    strcpy(if2.ifr_name, name);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1150
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1151
    if (ioctl(sock, SIOCGIFINDEX, (char *)&if2) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1152
        return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1153
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1154
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1155
    return if2.ifr_ifindex;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
 * Returns the IPv4 broadcast address of a named interface, if it exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
 * Returns 0 if it doesn't have one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
 */
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1162
static struct sockaddr *getBroadcast(JNIEnv *env, int sock, const char *ifname, struct sockaddr *brdcast_store) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
  struct sockaddr *ret = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
  struct ifreq if2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
  memset((char *) &if2, 0, sizeof(if2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
  strcpy(if2.ifr_name, ifname);
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1168
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
  /* Let's make sure the interface does have a broadcast address */
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1170
  if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2)  < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1171
      NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL  SIOCGIFFLAGS failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1172
      return ret;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
  }
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1174
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1175
  if (if2.ifr_flags & IFF_BROADCAST) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1176
      /* It does, let's retrieve it*/
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1177
      if (ioctl(sock, SIOCGIFBRDADDR, (char *)&if2) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1178
          NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGIFBRDADDR failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1179
          return ret;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1180
      }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1181
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1182
      ret = brdcast_store;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
      memcpy(ret, &if2.ifr_broadaddr, sizeof(struct sockaddr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
  }
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1185
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
  return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
 * Returns the IPv4 subnet prefix length (aka subnet mask) for the named
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
 * interface, if it has one, otherwise return -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
 */
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1193
static short getSubnet(JNIEnv *env, int sock, const char *ifname) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1194
    unsigned int mask;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1195
    short ret;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1196
    struct ifreq if2;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1197
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1198
    memset((char *) &if2, 0, sizeof(if2));
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1199
    strcpy(if2.ifr_name, ifname);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1200
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1201
    if (ioctl(sock, SIOCGIFNETMASK, (char *)&if2) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1202
        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGIFNETMASK failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1203
        return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1204
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1205
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1206
    mask = ntohl(((struct sockaddr_in*)&(if2.ifr_addr))->sin_addr.s_addr);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1207
    ret = 0;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1208
    while (mask) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1209
       mask <<= 1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1210
       ret++;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1211
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1212
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1213
    return ret;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1214
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1215
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1216
/**
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1217
 * Get the Hardware address (usually MAC address) for the named interface.
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1218
 * return puts the data in buf, and returns the length, in byte, of the
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1219
 * MAC address. Returns -1 if there is no hardware address on that interface.
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1220
 */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1221
static int getMacAddress(JNIEnv *env, int sock, const char* ifname, const struct in_addr* addr, unsigned char *buf) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1222
    static struct ifreq ifr;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1223
    int i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1225
    strcpy(ifr.ifr_name, ifname);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1226
    if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1227
        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGIFHWADDR failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1228
        return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1229
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1230
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1231
    memcpy(buf, &ifr.ifr_hwaddr.sa_data, IFHWADDRLEN);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1232
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1233
   /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1234
    * All bytes to 0 means no hardware address.
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1235
    */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1236
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1237
    for (i = 0; i < IFHWADDRLEN; i++) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1238
        if (buf[i] != 0)
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1239
            return IFHWADDRLEN;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1240
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1241
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
    return -1;
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1243
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1244
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1245
static int getMTU(JNIEnv *env, int sock,  const char *ifname) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1246
    struct ifreq if2;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1247
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1248
    memset((char *) &if2, 0, sizeof(if2));
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1249
    strcpy(if2.ifr_name, ifname);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1250
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1251
    if (ioctl(sock, SIOCGIFMTU, (char *)&if2) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1252
        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGIFMTU failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1253
        return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1254
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1255
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1256
    return  if2.ifr_mtu;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1257
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1258
6129
e76ab178e431 6972374: NetworkInterface.getNetworkInterfaces throws "java.net.SocketException" on Solaris zone
chegar
parents: 6108
diff changeset
  1259
static int getFlags(int sock, const char *ifname) {
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1260
  struct ifreq if2;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1261
  int ret = -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
  memset((char *) &if2, 0, sizeof(if2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
  strcpy(if2.ifr_name, ifname);
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1265
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1266
  if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2) < 0){
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1267
      return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1268
  }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1269
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1270
  return if2.ifr_flags;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1271
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1272
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1273
#endif
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1274
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1275
/** Solaris **/
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1276
#ifdef __solaris__
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1277
/* Open socket for further ioct calls, try v4 socket first and
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1278
 * if it falls return v6 socket
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1279
 */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1280
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1281
#ifdef AF_INET6
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1282
static int openSocketWithFallback(JNIEnv *env, const char *ifname){
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1283
    int sock, alreadyV6 = 0;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1284
    struct lifreq if2;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1285
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1286
     if ((sock = JVM_Socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1287
         if (errno == EPROTONOSUPPORT){
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1288
              if ( (sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0)) < 0 ){
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1289
                 NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "IPV6 Socket creation failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1290
                 return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1291
              }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1292
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1293
              alreadyV6=1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1294
         }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1295
         else{ // errno is not NOSUPPORT
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1296
             NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "IPV4 Socket creation failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1297
             return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1298
         }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1299
   }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1300
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1301
     /**
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1302
      * Solaris requires that we have IPv6 socket to query an
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1303
      * interface without IPv4 address - check it here
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1304
      * POSIX 1 require the kernell to return ENOTTY if the call is
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1305
      * unappropriate for device e.g. NETMASK for device having IPv6
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1306
      * only address but not all devices follows the standart so
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1307
      * fallback on any error.  It's not an ecology friendly but more
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1308
      * reliable.
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1309
      */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1310
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1311
    if (! alreadyV6 ){
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1312
        memset((char *) &if2, 0, sizeof(if2));
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1313
        strcpy(if2.lifr_name, ifname);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1314
        if (ioctl(sock, SIOCGLIFNETMASK, (char *)&if2) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1315
                close(sock);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1316
                if ( (sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0)) < 0 ){
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1317
                      NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "IPV6 Socket creation failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1318
                      return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1319
                }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1320
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    }
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1322
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1323
    return sock;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1324
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1325
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1326
#else
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1327
static int openSocketWithFallback(JNIEnv *env, const char *ifname){
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1328
    return openSocket(env,AF_INET);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1329
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1330
#endif
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1331
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1332
/*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1333
 * Enumerates and returns all IPv4 interfaces
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1334
 * (linux verison)
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1335
 */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1336
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1337
static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1338
     return enumIPvXInterfaces(env,sock, ifs, AF_INET);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1341
#ifdef AF_INET6
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1342
static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1343
    return enumIPvXInterfaces(env,sock, ifs, AF_INET6);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1344
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1345
#endif
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1346
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1347
/*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1348
   Enumerates and returns all interfaces on Solaris
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1349
   use the same code for IPv4 and IPv6
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1350
 */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1351
static netif *enumIPvXInterfaces(JNIEnv *env, int sock, netif *ifs, int family) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1352
    struct lifconf ifc;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1353
    struct lifreq *ifr;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1354
    int n;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1355
    char *buf;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1356
    struct lifnum numifs;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1357
    unsigned bufsize;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1358
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1359
    /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1360
     * Get the interface count
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1361
     */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1362
    numifs.lifn_family = family;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1363
    numifs.lifn_flags = 0;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1364
    if (ioctl(sock, SIOCGLIFNUM, (char *)&numifs) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1365
        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "ioctl SIOCGLIFNUM failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1366
        return ifs;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1367
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1368
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1369
    /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1370
     *  Enumerate the interface configurations
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1371
     */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1372
    bufsize = numifs.lifn_count * sizeof (struct lifreq);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1373
    CHECKED_MALLOC3(buf, char *, bufsize);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1374
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1375
    ifc.lifc_family = family;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1376
    ifc.lifc_flags = 0;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1377
    ifc.lifc_len = bufsize;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1378
    ifc.lifc_buf = buf;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1379
    if (ioctl(sock, SIOCGLIFCONF, (char *)&ifc) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1380
        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "ioctl SIOCGLIFCONF failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1381
        free(buf);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1382
        return ifs;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1383
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1384
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1385
    /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1386
     * Iterate through each interface
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1387
     */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1388
    ifr = ifc.lifc_req;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1389
    for (n=0; n<numifs.lifn_count; n++, ifr++) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1390
        int index = -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1391
        struct lifreq if2;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1392
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1393
        /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1394
        * Ignore either IPv4 or IPv6 addresses
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1395
        */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1396
        if (ifr->lifr_addr.ss_family != family) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1397
            continue;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1398
        }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1399
6002
4df5b9bcf842 6967937: Scope id no longer being set after 6931566
chegar
parents: 5969
diff changeset
  1400
#ifdef AF_INET6
4df5b9bcf842 6967937: Scope id no longer being set after 6931566
chegar
parents: 5969
diff changeset
  1401
        if (ifr->lifr_addr.ss_family == AF_INET6) {
4df5b9bcf842 6967937: Scope id no longer being set after 6931566
chegar
parents: 5969
diff changeset
  1402
            struct sockaddr_in6 *s6= (struct sockaddr_in6 *)&(ifr->lifr_addr);
4df5b9bcf842 6967937: Scope id no longer being set after 6931566
chegar
parents: 5969
diff changeset
  1403
            s6->sin6_scope_id = getIndex(sock, ifr->lifr_name);
4df5b9bcf842 6967937: Scope id no longer being set after 6931566
chegar
parents: 5969
diff changeset
  1404
        }
4df5b9bcf842 6967937: Scope id no longer being set after 6931566
chegar
parents: 5969
diff changeset
  1405
#endif
4df5b9bcf842 6967937: Scope id no longer being set after 6931566
chegar
parents: 5969
diff changeset
  1406
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1407
        /* add to the list */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1408
        ifs = addif(env, sock,ifr->lifr_name, ifs, (struct sockaddr *)&(ifr->lifr_addr),family, (short) ifr->lifr_addrlen);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1409
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1410
        /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1411
        * If an exception occurred we return immediately
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1412
        */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1413
        if ((*env)->ExceptionOccurred(env)) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1414
            free(buf);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1415
            return ifs;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1416
        }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1417
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1418
   }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1419
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1420
    free(buf);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1421
    return ifs;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1422
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1423
6002
4df5b9bcf842 6967937: Scope id no longer being set after 6931566
chegar
parents: 5969
diff changeset
  1424
static int getIndex(int sock, const char *name){
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1425
   /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1426
    * Try to get the interface index
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1427
    * (Not supported on Solaris 2.6 or 7)
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1428
    */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1429
    struct lifreq if2;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1430
    strcpy(if2.lifr_name, name);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1431
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1432
    if (ioctl(sock, SIOCGLIFINDEX, (char *)&if2) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1433
        return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1434
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1435
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1436
    return if2.lifr_index;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1437
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1438
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1439
/**
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1440
 * Returns the IPv4 broadcast address of a named interface, if it exists.
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1441
 * Returns 0 if it doesn't have one.
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1442
 */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1443
static struct sockaddr *getBroadcast(JNIEnv *env, int sock, const char *ifname, struct sockaddr *brdcast_store) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1444
    struct sockaddr *ret = NULL;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1445
    struct lifreq if2;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1446
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1447
    memset((char *) &if2, 0, sizeof(if2));
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1448
    strcpy(if2.lifr_name, ifname);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1449
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1450
    /* Let's make sure the interface does have a broadcast address */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1451
    if (ioctl(sock, SIOCGLIFFLAGS, (char *)&if2)  < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1452
        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL  SIOCGLIFFLAGS failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1453
        return ret;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1454
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1455
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1456
    if (if2.lifr_flags & IFF_BROADCAST) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1457
        /* It does, let's retrieve it*/
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1458
        if (ioctl(sock, SIOCGLIFBRDADDR, (char *)&if2) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1459
            NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGLIFBRDADDR failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1460
            return ret;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1461
        }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1462
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1463
        ret = brdcast_store;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1464
        memcpy(ret, &if2.lifr_broadaddr, sizeof(struct sockaddr));
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1465
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1466
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1467
    return ret;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1468
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1469
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1470
/**
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1471
 * Returns the IPv4 subnet prefix length (aka subnet mask) for the named
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1472
 * interface, if it has one, otherwise return -1.
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1473
 */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1474
static short getSubnet(JNIEnv *env, int sock, const char *ifname) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1475
    unsigned int mask;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1476
    short ret;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1477
    struct lifreq if2;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1478
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1479
    memset((char *) &if2, 0, sizeof(if2));
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1480
    strcpy(if2.lifr_name, ifname);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1481
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1482
    if (ioctl(sock, SIOCGLIFNETMASK, (char *)&if2) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1483
        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGLIFNETMASK failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1484
        return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1485
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1486
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1487
    mask = ntohl(((struct sockaddr_in*)&(if2.lifr_addr))->sin_addr.s_addr);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1488
    ret = 0;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1489
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1490
    while (mask) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1491
       mask <<= 1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1492
       ret++;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1493
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1494
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1495
    return ret;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1496
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1497
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1498
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1499
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1500
#define DEV_PREFIX  "/dev/"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
 * Solaris specific DLPI code to get hardware address from a device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
 * Unfortunately, at least up to Solaris X, you have to have special
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
 * privileges (i.e. be root).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
static int getMacFromDevice(JNIEnv *env, const char* ifname, unsigned char* retbuf) {
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1508
    char style1dev[MAXPATHLEN];
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1509
    int fd;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1510
    dl_phys_addr_req_t dlpareq;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1511
    dl_phys_addr_ack_t *dlpaack;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1512
    struct strbuf msg;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1513
    char buf[128];
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1514
    int flags = 0;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1515
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1516
   /**
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1517
    * Device is in /dev
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1518
    * e.g.: /dev/bge0
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1519
    */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1520
    strcpy(style1dev, DEV_PREFIX);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1521
    strcat(style1dev, ifname);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1522
    if ((fd = open(style1dev, O_RDWR)) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1523
        /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1524
         * Can't open it. We probably are missing the privilege.
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1525
         * We'll have to try something else
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1526
         */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1527
         return 0;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1528
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1529
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1530
    dlpareq.dl_primitive = DL_PHYS_ADDR_REQ;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1531
    dlpareq.dl_addr_type = DL_CURR_PHYS_ADDR;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1533
    msg.buf = (char *)&dlpareq;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1534
    msg.len = DL_PHYS_ADDR_REQ_SIZE;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1535
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1536
    if (putmsg(fd, &msg, NULL, 0) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1537
        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "putmsg failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1538
        return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1539
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1540
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1541
    dlpaack = (dl_phys_addr_ack_t *)buf;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1543
    msg.buf = (char *)buf;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1544
    msg.len = 0;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1545
    msg.maxlen = sizeof (buf);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1546
    if (getmsg(fd, &msg, NULL, &flags) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1547
        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "getmsg failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1548
        return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1549
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1550
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1551
    if (msg.len < DL_PHYS_ADDR_ACK_SIZE || dlpaack->dl_primitive != DL_PHYS_ADDR_ACK) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1552
        JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Couldn't obtain phys addr\n");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1553
        return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1554
    }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1555
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1556
    memcpy(retbuf, &buf[dlpaack->dl_addr_offset], dlpaack->dl_addr_length);
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1557
    return dlpaack->dl_addr_length;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
 * Get the Hardware address (usually MAC address) for the named interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
 * return puts the data in buf, and returns the length, in byte, of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
 * MAC address. Returns -1 if there is no hardware address on that interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
 */
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1565
static int getMacAddress(JNIEnv *env, int sock, const char *ifname,  const struct in_addr* addr, unsigned char *buf) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1566
    struct arpreq arpreq;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1567
    struct sockaddr_in* sin;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1568
    struct sockaddr_in ipAddr;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1569
    int len, i;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1570
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1571
   /**
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1572
    * On Solaris we have to use DLPI, but it will only work if we have
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1573
    * privileged access (i.e. root). If that fails, we try a lookup
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1574
    * in the ARP table, which requires an IPv4 address.
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1575
    */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1576
    if ((len = getMacFromDevice(env, ifname, buf))  == 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1577
        /*DLPI failed - trying to do arp lookup*/
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1578
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1579
       if (addr == NULL) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1580
          /**
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1581
           * No IPv4 address for that interface, so can't do an ARP lookup.
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1582
           */
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1583
           return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1584
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1586
      len = 6; //???
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1587
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1588
      sin = (struct sockaddr_in *) &arpreq.arp_pa;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1589
      memset((char *) &arpreq, 0, sizeof(struct arpreq));
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1590
      ipAddr.sin_port = 0;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1591
      ipAddr.sin_family = AF_INET;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1592
      memcpy(&ipAddr.sin_addr, addr, sizeof(struct in_addr));
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1593
      memcpy(&arpreq.arp_pa, &ipAddr, sizeof(struct sockaddr_in));
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1594
      arpreq.arp_flags= ATF_PUBL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1596
      if (ioctl(sock, SIOCGARP, &arpreq) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1597
          if (errno != ENXIO) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1598
              // "No such device or address" means no hardware address, so it's
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1599
              // normal don't throw an exception
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1600
              NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1601
              return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1602
          }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1603
     }
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1604
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1605
     memcpy(buf, &arpreq.arp_ha.sa_data[0], len );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1608
    /*
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1609
     * All bytes to 0 means no hardware address.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1612
    for (i = 0; i < len; i++) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1613
      if (buf[i] != 0)
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1614
         return len;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1615
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1617
    return -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1620
static int getMTU(JNIEnv *env, int sock,  const char *ifname) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1621
    struct lifreq if2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1623
    memset((char *) &if2, 0, sizeof(if2));
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1624
    strcpy(if2.lifr_name, ifname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1626
    if (ioctl(sock, SIOCGLIFMTU, (char *)&if2) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1627
        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGLIFMTU failed");
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1628
        return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1629
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1631
    return  if2.lifr_mtu;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
6129
e76ab178e431 6972374: NetworkInterface.getNetworkInterfaces throws "java.net.SocketException" on Solaris zone
chegar
parents: 6108
diff changeset
  1635
static int getFlags(int sock, const char *ifname) {
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1636
     struct   lifreq lifr;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1637
     memset((caddr_t)&lifr, 0, sizeof(lifr));
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1638
     strcpy((caddr_t)&(lifr.lifr_name), ifname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1640
     if (ioctl(sock, SIOCGLIFFLAGS, (char *)&lifr) < 0) {
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1641
         return -1;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1642
     }
709
4d98e12330e6 6628569: api/java_net/MulticastSocket/descriptions.html#setTTL fails is ipv6 configured
chegar
parents: 2
diff changeset
  1643
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1644
     return  lifr.lifr_flags;
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1645
}
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1646
709
4d98e12330e6 6628569: api/java_net/MulticastSocket/descriptions.html#setTTL fails is ipv6 configured
chegar
parents: 2
diff changeset
  1647
4814
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 2163
diff changeset
  1648
#endif
5969
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1649
76a4031d39bd 6931566: NetworkInterface is not working when interface name is more than 15 characters long
dsamersoff
parents: 5506
diff changeset
  1650