1 /* |
1 /* |
2 * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
55 } |
55 } |
56 |
56 |
57 JNIEXPORT jobject JNICALL |
57 JNIEXPORT jobject JNICALL |
58 Java_sun_nio_ch_InheritedChannel_peerAddress0(JNIEnv *env, jclass cla, jint fd) |
58 Java_sun_nio_ch_InheritedChannel_peerAddress0(JNIEnv *env, jclass cla, jint fd) |
59 { |
59 { |
60 struct sockaddr *sa; |
60 SOCKETADDRESS sa; |
61 socklen_t sa_len; |
61 socklen_t len = sizeof(SOCKETADDRESS); |
62 jobject remote_ia = NULL; |
62 jobject remote_ia = NULL; |
63 jint remote_port; |
63 jint remote_port; |
64 |
64 |
65 NET_AllocSockaddr(&sa, (int *)&sa_len); |
65 if (getpeername(fd, &sa.sa, &len) == 0) { |
66 if (getpeername(fd, sa, &sa_len) == 0) { |
66 if (matchFamily(&sa.sa)) { |
67 if (matchFamily(sa)) { |
67 remote_ia = NET_SockaddrToInetAddress(env, &sa.sa, (int *)&remote_port); |
68 remote_ia = NET_SockaddrToInetAddress(env, sa, (int *)&remote_port); |
|
69 } |
68 } |
70 } |
69 } |
71 free((void *)sa); |
|
72 |
70 |
73 return remote_ia; |
71 return remote_ia; |
74 } |
72 } |
75 |
73 |
76 |
74 |
77 JNIEXPORT jint JNICALL |
75 JNIEXPORT jint JNICALL |
78 Java_sun_nio_ch_InheritedChannel_peerPort0(JNIEnv *env, jclass cla, jint fd) |
76 Java_sun_nio_ch_InheritedChannel_peerPort0(JNIEnv *env, jclass cla, jint fd) |
79 { |
77 { |
80 struct sockaddr *sa; |
78 SOCKETADDRESS sa; |
81 socklen_t sa_len; |
79 socklen_t len = sizeof(SOCKETADDRESS); |
82 jint remote_port = -1; |
80 jint remote_port = -1; |
83 |
81 |
84 NET_AllocSockaddr(&sa, (int *)&sa_len); |
82 if (getpeername(fd, &sa.sa, &len) == 0) { |
85 if (getpeername(fd, sa, &sa_len) == 0) { |
83 if (matchFamily(&sa.sa)) { |
86 if (matchFamily(sa)) { |
84 NET_SockaddrToInetAddress(env, &sa.sa, (int *)&remote_port); |
87 NET_SockaddrToInetAddress(env, sa, (int *)&remote_port); |
|
88 } |
85 } |
89 } |
86 } |
90 free((void *)sa); |
|
91 |
87 |
92 return remote_port; |
88 return remote_port; |
93 } |
89 } |
94 |
90 |
95 JNIEXPORT jint JNICALL |
91 JNIEXPORT jint JNICALL |