+struct RuntimeHash *fdtoobject;
+
+int CALL24(___Socket______nativeConnect____I__AR_B_I, int ___fd___, int ___port___, struct ___Socket___ * ___this___, int ___fd___, struct ArrayObject * ___address___ ,int ___port___) {
+#ifdef RAW
+ // not supported in RAW version
+ return -1;
+#else
+ struct sockaddr_in sin;
+ int rc;
+
+ bzero(&sin, sizeof(sin));
+ sin.sin_family= AF_INET;
+ sin.sin_port=htons(___port___);
+ sin.sin_addr.s_addr=htonl(*(int *)(((char *)&VAR(___address___)->___length___)+sizeof(int)));
+#if defined(THREADS)||defined(DSTM)
+#ifdef PRECISE_GC
+ struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
+#endif
+#endif
+ do {
+ rc = connect(___fd___, (struct sockaddr *) &sin, sizeof(sin));
+ } while (rc<0 && errno==EINTR); /* repeat if interrupted */
+#if defined(THREADS)||defined(DSTM)
+#ifdef PRECISE_GC
+ restartaftergc(tmp);
+#endif
+#endif
+
+
+ if (rc<0) goto error;
+
+#ifdef TASK
+ //Make non-blocking
+ fcntl(___fd___, F_SETFD, 1);
+ fcntl(___fd___, F_SETFL, fcntl(___fd___, F_GETFL)|O_NONBLOCK);
+ RuntimeHashadd(fdtoobject, ___fd___, (int) VAR(___this___));
+ addreadfd(___fd___);
+#endif
+
+ return 0;
+
+ error:
+ close(___fd___);
+ return -1;
+#endif
+}
+
+#ifdef TASK
+int CALL12(___Socket______nativeBindFD____I, int ___fd___, struct ___Socket___ * ___this___, int ___fd___) {
+ if (RuntimeHashcontainskey(fdtoobject, ___fd___))
+ RuntimeHashremovekey(fdtoobject, ___fd___);
+ RuntimeHashadd(fdtoobject, ___fd___, (int) VAR(___this___));
+ addreadfd(___fd___);
+}
+#endif
+
+
+int CALL12(___Socket______nativeBind_____AR_B_I, int ___port___, struct ArrayObject * ___address___, int ___port___) {
+#ifdef RAW
+ // not supported in RAW version
+ return -1;
+#else
+ int fd;
+ int rc;
+ socklen_t sa_size;
+ struct sockaddr_in sin;
+ bzero(&sin, sizeof(sin));
+ sin.sin_family= AF_INET;
+ sin.sin_port=0;
+ sin.sin_addr.s_addr=INADDR_ANY;
+
+ fd=socket(AF_INET, SOCK_STREAM, 0);
+ if (fd<0) {
+#ifdef DEBUG
+ perror(NULL);
+ printf("createSocket error in nativeBind\n");
+#endif
+#ifdef TASK
+ longjmp(error_handler,12);
+#else
+#ifdef THREADS
+ threadexit();
+#else
+ exit(-1);
+#endif
+#endif
+ }
+
+ rc = bind(fd, (struct sockaddr *) &sin, sizeof(sin));
+ if (rc<0) goto error;
+
+ sa_size = sizeof(sin);
+ rc = getsockname(fd, (struct sockaddr *) &sin, &sa_size);
+ if (rc<0) goto error;
+
+ return fd;
+
+ error:
+ close(fd);
+#ifdef DEBUG
+ perror(NULL);
+ printf("createSocket error #2 in nativeBind\n");
+#endif
+#ifdef TASK
+ longjmp(error_handler,13);
+#else
+#ifdef THREADS
+ threadexit();
+#else
+ exit(-1);
+#endif
+#endif
+#endif
+}
+
+struct ArrayObject * CALL01(___InetAddress______getHostByName_____AR_B, struct ArrayObject * ___hostname___) {
+#ifdef RAW
+ // not supported in RAW version
+ return NULL;
+#else
+//struct ArrayObject * CALL01(___InetAddress______getHostByName_____AR_B, struct ___ArrayObject___ * ___hostname___) {
+ int length=VAR(___hostname___)->___length___;
+ int i,j,n;
+ char * str=malloc(length+1);
+ struct hostent *h;
+ struct ArrayObject * arraybytearray;
+
+ for(i=0;i<length;i++) {
+ str[i]=(((char *)&VAR(___hostname___)->___length___)+sizeof(int))[i];
+ }
+ str[length]=0;
+ h=gethostbyname(str);
+ free(str);
+
+ for (n=0; h->h_addr_list[n]; n++) /* do nothing */ ;
+
+#ifdef PRECISE_GC
+ arraybytearray=allocate_newarray(___params___,BYTEARRAYARRAYTYPE,n);
+#else
+ arraybytearray=allocate_newarray(BYTEARRAYARRAYTYPE,n);
+#endif
+ for(i=0;i<n;i++) {
+ struct ArrayObject *bytearray;
+#ifdef PRECISE_GC
+ {
+ int ptrarray[]={1, (int) ___params___, (int)arraybytearray};
+ bytearray=allocate_newarray(&ptrarray,BYTEARRAYTYPE,h->h_length);
+ arraybytearray=(struct ArrayObject *) ptrarray[2];
+ }
+#else
+ bytearray=allocate_newarray(BYTEARRAYTYPE,h->h_length);
+#endif
+ ((void **)&((&arraybytearray->___length___)[1]))[i]=bytearray;
+ {
+ int ha=ntohl(*(int *)h->h_addr_list[i]);
+ (&bytearray->___length___)[1]=ha;
+ }
+ }
+
+ return arraybytearray;
+#endif
+}
+