1 /*
2  * Copyright (c) 2002-2011 by XMLVM.org
3  *
4  * Project Info:  http://www.xmlvm.org
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19  * USA.
20  */
21 
22 
23 #include "hysock.h"
24 
25 
26 #ifndef __XMLVM_SOCK_H__
27 #define __XMLVM_SOCK_H__
28 
29 /* socket structure flags */
30 #define SOCKET_IPV4_OPEN_MASK '\x1'    /* 00000001 */
31 #define SOCKET_IPV6_OPEN_MASK '\x2'    /* 00000010 */
32 #define SOCKET_BOTH_OPEN_MASK '\x3'    /* 00000011 */
33 #define SOCKET_USE_IPV4_MASK '\x4'    /* 00000100 - this tells which one to pick when doing an operation */
34 
35 int harmony_supports_ipv6();
36 int preferIPv4Stack();
37 int preferIPv6Addresses();
38 
39 char* netLookupErrorString (I_32 anErrorNum);
40 U_16 hysock_htons(U_16 port);
41 U_16 hysock_ntohs (U_16 val);
42 I_32 hysock_socketIsValid (hysocket_t handle);
43 U_16 hysock_sockaddr_port (hysockaddr_t handle);
44 void setJavaIoFileDescriptorContents (JAVA_OBJECT fd, void *value);
45 void* getJavaIoFileDescriptorContentsAsAPointer (JAVA_OBJECT fd);
46 void netGetJavaNetInetAddressValue (JAVA_OBJECT anInetAddress, U_8* buffer, U_32* length);
47 void netGetJavaNetInetAddressScopeId (JAVA_OBJECT anInetAddress, U_32* scope_id);
48 I_32 netGetSockAddr (JAVA_OBJECT fileDescriptor, hysockaddr_t sockaddrP, JAVA_BOOLEAN preferIPv6Addresses);
49 JAVA_OBJECT newJavaNetInetAddressGenericBS (JAVA_ARRAY_BYTE* address, U_32 length, const char* hostName, U_32 scope_id);
50 I_32 hysock_socket (hysocket_t * handle, I_32 family, I_32 socktype, I_32 protocol);
51 I_32 hysock_sockaddr_init6 (hysockaddr_t handle, U_8 * addr, I_32 addrlength, I_16 family, U_16 nPort, U_32 flowinfo, U_32 scope_id, hysocket_t sock);
52 I_32 hysock_getnameinfo (hysockaddr_t in_addr, I_32 sockaddr_size, char *name, I_32 name_length, int flags);
53 I_32 hysock_bind (hysocket_t sock, hysockaddr_t addr);
54 I_32 hysock_getsockname (hysocket_t handle, hysockaddr_t addrHandle);
55 I_32 hysock_connect (hysocket_t sock, hysockaddr_t addr);
56 I_32 hysock_write (hysocket_t sock, U_8 * buf, I_32 nbyte, I_32 flags);
57 I_32 hysock_read (hysocket_t sock, U_8 * buf, I_32 nbyte, I_32 flags);
58 I_32 hysock_close (hysocket_t * sock);
59 I_32 hysock_listen (hysocket_t sock, I_32 backlog);
60 I_32 hysock_accept (hysocket_t serverSock, hysockaddr_t addrHandle, hysocket_t * sockHandle);
61 I_32 hysock_timeval_init (U_32 secTime, U_32 uSecTime, hytimeval_t timeP);
62 I_32 hysock_select_read (hysocket_t hysocketP, I_32 secTime, I_32 uSecTime, BOOLEAN accept);
63 I_32 hysock_fdset_init (hysocket_t socketP);
64 I_32 hysock_fdset_size (hysocket_t handle);
65 I_32 hysock_select (I_32 nfds, hyfdset_t readfds, hyfdset_t writefds, hyfdset_t exceptfds, hytimeval_t timeout);
66 I_32 platformSocketLevel (I_32 portableSocketLevel);
67 I_32 platformSocketOption (I_32 portableSocketOption);
68 I_32 hysock_setopt_bool (hysocket_t socketP, I_32 optlevel, I_32 optname, BOOLEAN * optval);
69 
70 void throwJavaNetSocketException (I_32 errorNumber);
71 
72 #endif
73