1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1037 */
1038 if (opt == java_net_SocketOptions_SO_BINDADDR) {
1039 SOCKETADDRESS him;
1040 int len;
1041 int port;
1042 jobject iaObj;
1043 jclass iaCntrClass;
1044 jfieldID iaFieldID;
1045
1046 len = sizeof(him);
1047 memset((char *)&him, 0, len);
1048
1049 if (fd == -1) {
1050 /* must be an IPV6 only socket. Case where both sockets are != -1
1051 * is handled in java
1052 */
1053 fd = getFD1 (env, this);
1054 }
1055
1056 if (getsockname(fd, (struct sockaddr *)&him, &len) < 0) {
1057 NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
1058 "Error getting socket name");
1059 return -1;
1060 }
1061 iaObj = NET_SockaddrToInetAddress(env, (struct sockaddr *)&him, &port);
1062 CHECK_NULL_RETURN(iaObj, -1);
1063
1064 iaCntrClass = (*env)->GetObjectClass(env, iaContainerObj);
1065 iaFieldID = (*env)->GetFieldID(env, iaCntrClass, "addr", "Ljava/net/InetAddress;");
1066 CHECK_NULL_RETURN(iaFieldID, -1);
1067 (*env)->SetObjectField(env, iaContainerObj, iaFieldID, iaObj);
1068 return 0; /* notice change from before */
1069 }
1070
1071 /*
1072 * Map the Java level socket option to the platform specific
1073 * level and option name.
1074 */
1075 if (NET_MapSocketOption(opt, &level, &optname)) {
1076 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Invalid option");
1077 return -1;
1078 }
|
1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1037 */
1038 if (opt == java_net_SocketOptions_SO_BINDADDR) {
1039 SOCKETADDRESS him;
1040 int len;
1041 int port;
1042 jobject iaObj;
1043 jclass iaCntrClass;
1044 jfieldID iaFieldID;
1045
1046 len = sizeof(him);
1047 memset((char *)&him, 0, len);
1048
1049 if (fd == -1) {
1050 /* must be an IPV6 only socket. Case where both sockets are != -1
1051 * is handled in java
1052 */
1053 fd = getFD1 (env, this);
1054 }
1055
1056 if (getsockname(fd, (struct sockaddr *)&him, &len) < 0) {
1057 JNU_ThrowByNameWithMessageAndLastError
1058 (env, JNU_JAVANETPKG "SocketException", "Error getting socket name");
1059 return -1;
1060 }
1061 iaObj = NET_SockaddrToInetAddress(env, (struct sockaddr *)&him, &port);
1062 CHECK_NULL_RETURN(iaObj, -1);
1063
1064 iaCntrClass = (*env)->GetObjectClass(env, iaContainerObj);
1065 iaFieldID = (*env)->GetFieldID(env, iaCntrClass, "addr", "Ljava/net/InetAddress;");
1066 CHECK_NULL_RETURN(iaFieldID, -1);
1067 (*env)->SetObjectField(env, iaContainerObj, iaFieldID, iaObj);
1068 return 0; /* notice change from before */
1069 }
1070
1071 /*
1072 * Map the Java level socket option to the platform specific
1073 * level and option name.
1074 */
1075 if (NET_MapSocketOption(opt, &level, &optname)) {
1076 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Invalid option");
1077 return -1;
1078 }
|