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
23 * questions.
24 */
25
26 #include "net_util.h"
27
28 #include "java_net_InetAddress.h"
29
30 int IPv4_supported();
31 int IPv6_supported();
32 int reuseport_supported();
33
34 static int IPv4_available;
35 static int IPv6_available;
36 static int REUSEPORT_available;
37
38 JNIEXPORT jint JNICALL ipv4_available()
39 {
40 return IPv4_available;
41 }
42
43 JNIEXPORT jint JNICALL ipv6_available()
44 {
45 return IPv6_available;
46 }
47
48 JNIEXPORT jint JNICALL reuseport_available()
315 in_cksum(unsigned short *addr, int len) {
316 int nleft = len;
317 int sum = 0;
318 unsigned short *w = addr;
319 unsigned short answer = 0;
320 while(nleft > 1) {
321 sum += *w++;
322 nleft -= 2;
323 }
324
325 if (nleft == 1) {
326 *(unsigned char *) (&answer) = *(unsigned char *)w;
327 sum += answer;
328 }
329
330 sum = (sum >> 16) + (sum & 0xffff);
331 sum += (sum >> 16);
332 answer = ~sum;
333 return (answer);
334 }
|
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
23 * questions.
24 */
25
26 #include "net_util.h"
27
28 #include "java_net_InetAddress.h"
29 #include "java_net_spi_InetAddressResolver_LookupPolicy.h"
30
31 int IPv4_supported();
32 int IPv6_supported();
33 int reuseport_supported();
34
35 static int IPv4_available;
36 static int IPv6_available;
37 static int REUSEPORT_available;
38
39 JNIEXPORT jint JNICALL ipv4_available()
40 {
41 return IPv4_available;
42 }
43
44 JNIEXPORT jint JNICALL ipv6_available()
45 {
46 return IPv6_available;
47 }
48
49 JNIEXPORT jint JNICALL reuseport_available()
316 in_cksum(unsigned short *addr, int len) {
317 int nleft = len;
318 int sum = 0;
319 unsigned short *w = addr;
320 unsigned short answer = 0;
321 while(nleft > 1) {
322 sum += *w++;
323 nleft -= 2;
324 }
325
326 if (nleft == 1) {
327 *(unsigned char *) (&answer) = *(unsigned char *)w;
328 sum += answer;
329 }
330
331 sum = (sum >> 16) + (sum & 0xffff);
332 sum += (sum >> 16);
333 answer = ~sum;
334 return (answer);
335 }
336
337 int lookupCharacteristicsToAddressFamily(int characteristics) {
338 int ipv4 = characteristics & java_net_spi_InetAddressResolver_LookupPolicy_IPV4;
339 int ipv6 = characteristics & java_net_spi_InetAddressResolver_LookupPolicy_IPV6;
340
341 if (ipv4 != 0 && ipv6 == 0) {
342 return AF_INET;
343 }
344
345 if (ipv4 == 0 && ipv6 != 0) {
346 return AF_INET6;
347 }
348 return AF_UNSPEC;
349 }
350
351 int addressesInSystemOrder(int characteristics) {
352 return (characteristics &
353 (java_net_spi_InetAddressResolver_LookupPolicy_IPV4_FIRST |
354 java_net_spi_InetAddressResolver_LookupPolicy_IPV6_FIRST)) == 0;
355 }
|