1 /*
2 * Copyright (c) 1998, 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
23 * questions.
24 */
25 #include <windows.h>
26 #include <winsock2.h>
27
28 #include "sysSocket.h"
29 #include "socketTransport.h"
30
31 typedef jboolean bool_t;
32
33 /*
34 * Table of Windows Sockets errors, the specific exception we
35 * throw for the error, and the error text.
36 *
37 * Note that this table excludes OS dependent errors.
38 */
39 static struct {
40 int errCode;
41 const char *errString;
42 } const winsock_errors[] = {
43 { WSAEPROVIDERFAILEDINIT, "Provider initialization failed (check %SystemRoot%)" },
44 { WSAEACCES, "Permission denied" },
45 { WSAEADDRINUSE, "Address already in use" },
46 { WSAEADDRNOTAVAIL, "Cannot assign requested address" },
180 int flags, struct sockaddr *from, socklen_t *fromlen) {
181 return recvfrom(fd, buf, (int)nBytes, flags, from, fromlen);
182 }
183
184 int
185 dbgsysSendTo(int fd, char *buf, size_t len,
186 int flags, struct sockaddr *to, socklen_t tolen) {
187 return sendto(fd, buf, (int)len, flags, to, tolen);
188 }
189
190 int
191 dbgsysRecv(int fd, char *buf, size_t nBytes, int flags) {
192 return recv(fd, buf, (int) nBytes, flags);
193 }
194
195 int
196 dbgsysSend(int fd, char *buf, size_t nBytes, int flags) {
197 return send(fd, buf, (int)nBytes, flags);
198 }
199
200 struct hostent *
201 dbgsysGetHostByName(char *hostname) {
202 return gethostbyname(hostname);
203 }
204
205 unsigned short
206 dbgsysHostToNetworkShort(unsigned short hostshort) {
207 return htons(hostshort);
208 }
209
210 int
211 dbgsysSocket(int domain, int type, int protocol) {
212 int fd = (int)socket(domain, type, protocol);
213 if (fd != SOCKET_ERROR) {
214 SetHandleInformation((HANDLE)(UINT_PTR)fd, HANDLE_FLAG_INHERIT, FALSE);
215 }
216 return fd;
217 }
218
219 int
220 dbgsysSocketClose(int fd) {
221 struct linger l;
222 int len = sizeof(l);
223
224 if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&l, &len) == 0) {
225 if (l.l_onoff == 0) {
226 WSASendDisconnect(fd, NULL);
227 }
228 }
229 return closesocket(fd);
230 }
231
232 /* Additions to original follow */
233
234 int
235 dbgsysBind(int fd, struct sockaddr *name, socklen_t namelen) {
236 return bind(fd, name, namelen);
237 }
238
239
240 uint32_t
241 dbgsysInetAddr(const char* cp) {
242 return (uint32_t)inet_addr(cp);
243 }
244
245 uint32_t
246 dbgsysHostToNetworkLong(uint32_t hostlong) {
247 return (uint32_t)htonl((u_long)hostlong);
248 }
249
250 unsigned short
251 dbgsysNetworkToHostShort(unsigned short netshort) {
252 return ntohs(netshort);
253 }
254
255 int
256 dbgsysGetSocketName(int fd, struct sockaddr *name, socklen_t *namelen) {
257 return getsockname(fd, name, namelen);
258 }
259
260 uint32_t
261 dbgsysNetworkToHostLong(uint32_t netlong) {
262 return (uint32_t)ntohl((u_long)netlong);
|
1 /*
2 * Copyright (c) 1998, 2018, 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 #include <windows.h>
26 #include <winsock2.h>
27 #include <ws2tcpip.h>
28
29 #include "sysSocket.h"
30 #include "socketTransport.h"
31
32 typedef jboolean bool_t;
33
34 /*
35 * Table of Windows Sockets errors, the specific exception we
36 * throw for the error, and the error text.
37 *
38 * Note that this table excludes OS dependent errors.
39 */
40 static struct {
41 int errCode;
42 const char *errString;
43 } const winsock_errors[] = {
44 { WSAEPROVIDERFAILEDINIT, "Provider initialization failed (check %SystemRoot%)" },
45 { WSAEACCES, "Permission denied" },
46 { WSAEADDRINUSE, "Address already in use" },
47 { WSAEADDRNOTAVAIL, "Cannot assign requested address" },
181 int flags, struct sockaddr *from, socklen_t *fromlen) {
182 return recvfrom(fd, buf, (int)nBytes, flags, from, fromlen);
183 }
184
185 int
186 dbgsysSendTo(int fd, char *buf, size_t len,
187 int flags, struct sockaddr *to, socklen_t tolen) {
188 return sendto(fd, buf, (int)len, flags, to, tolen);
189 }
190
191 int
192 dbgsysRecv(int fd, char *buf, size_t nBytes, int flags) {
193 return recv(fd, buf, (int) nBytes, flags);
194 }
195
196 int
197 dbgsysSend(int fd, char *buf, size_t nBytes, int flags) {
198 return send(fd, buf, (int)nBytes, flags);
199 }
200
201 int
202 dbgsysGetAddrInfo(char *hostname, char *service,
203 struct addrinfo *hints,
204 struct addrinfo **result) {
205 return getaddrinfo(hostname, service, hints, result);
206 }
207
208 unsigned short
209 dbgsysHostToNetworkShort(unsigned short hostshort) {
210 return htons(hostshort);
211 }
212
213 int
214 dbgsysSocket(int domain, int type, int protocol) {
215 int fd = (int)socket(domain, type, protocol);
216 if (fd != SOCKET_ERROR) {
217 SetHandleInformation((HANDLE)(UINT_PTR)fd, HANDLE_FLAG_INHERIT, FALSE);
218 }
219 return fd;
220 }
221
222 int
223 dbgsysSocketClose(int fd) {
224 struct linger l;
225 int len = sizeof(l);
226
227 if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&l, &len) == 0) {
228 if (l.l_onoff == 0) {
229 shutdown(fd, SD_SEND);
230 }
231 }
232 return closesocket(fd);
233 }
234
235 /* Additions to original follow */
236
237 int
238 dbgsysBind(int fd, struct sockaddr *name, socklen_t namelen) {
239 return bind(fd, name, namelen);
240 }
241
242
243 uint32_t
244 dbgsysInetAddr(const char* cp) {
245 uint32_t addr;
246 inet_pton(AF_INET, cp, &addr);
247 return addr;
248 }
249
250 uint32_t
251 dbgsysHostToNetworkLong(uint32_t hostlong) {
252 return (uint32_t)htonl((u_long)hostlong);
253 }
254
255 unsigned short
256 dbgsysNetworkToHostShort(unsigned short netshort) {
257 return ntohs(netshort);
258 }
259
260 int
261 dbgsysGetSocketName(int fd, struct sockaddr *name, socklen_t *namelen) {
262 return getsockname(fd, name, namelen);
263 }
264
265 uint32_t
266 dbgsysNetworkToHostLong(uint32_t netlong) {
267 return (uint32_t)ntohl((u_long)netlong);
|