1 /*
2 * Copyright (c) 2009, 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
23 * questions.
24 */
25
26 #include <sys/types.h>
27 #include <sys/socket.h>
28 #include <errno.h>
29
30 #if defined(__solaris__)
31 #if !defined(PROTO_SDP)
32 #define PROTO_SDP 257
33 #endif
34 #elif defined(__linux__)
35 #if !defined(AF_INET_SDP)
36 #define AF_INET_SDP 27
37 #endif
38 #endif
39
40 #include "jni.h"
41 #include "jni_util.h"
42 #include "net_util.h"
43
44 #define RESTARTABLE(_cmd, _result) do { \
45 do { \
46 _result = _cmd; \
47 } while((_result == -1) && (errno == EINTR)); \
48 } while(0)
49
50
51 /**
52 * Creates a SDP socket.
53 */
54 static int create(JNIEnv* env)
55 {
56 int s;
57
58 #if defined(__solaris__)
59 int domain = ipv6_available() ? AF_INET6 : AF_INET;
60 s = socket(domain, SOCK_STREAM, PROTO_SDP);
61 #elif defined(__linux__)
62 /**
63 * IPv6 not supported by SDP on Linux
64 */
65 if (ipv6_available()) {
66 JNU_ThrowIOException(env, "IPv6 not supported");
67 return -1;
68 }
69 s = socket(AF_INET_SDP, SOCK_STREAM, 0);
70 #else
71 /* not supported on other platforms at this time */
72 s = -1;
73 errno = EPROTONOSUPPORT;
74 #endif
75
76 if (s < 0)
77 JNU_ThrowIOExceptionWithLastError(env, "socket");
78 return s;
79 }
80
81 /**
|
1 /*
2 * Copyright (c) 2009, 2020, 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
23 * questions.
24 */
25
26 #include <sys/types.h>
27 #include <sys/socket.h>
28 #include <errno.h>
29
30 #if defined(__linux__)
31 #if !defined(AF_INET_SDP)
32 #define AF_INET_SDP 27
33 #endif
34 #endif
35
36 #include "jni.h"
37 #include "jni_util.h"
38 #include "net_util.h"
39
40 #define RESTARTABLE(_cmd, _result) do { \
41 do { \
42 _result = _cmd; \
43 } while((_result == -1) && (errno == EINTR)); \
44 } while(0)
45
46
47 /**
48 * Creates a SDP socket.
49 */
50 static int create(JNIEnv* env)
51 {
52 int s;
53
54 #if defined(__linux__)
55 /**
56 * IPv6 not supported by SDP on Linux
57 */
58 if (ipv6_available()) {
59 JNU_ThrowIOException(env, "IPv6 not supported");
60 return -1;
61 }
62 s = socket(AF_INET_SDP, SOCK_STREAM, 0);
63 #else
64 /* not supported on other platforms at this time */
65 s = -1;
66 errno = EPROTONOSUPPORT;
67 #endif
68
69 if (s < 0)
70 JNU_ThrowIOExceptionWithLastError(env, "socket");
71 return s;
72 }
73
74 /**
|