jint localport, remotePort, thisLocalport;
jint remotePort, thisLocalport;
JNIEXPORT void JNICALL Java_java_net_PlainSocketImpl_accept  (JNIEnv *env, jobject this, jobject impl){	struct sockaddr_storage ss;	socklen_t addrlen = sizeof(ss);	int sock;	jbyteArray remoteAddress;	jbyte *remoteAddressBytes;	jclass implClass, thisClass, inetClass, fdClass;	jfieldID localportID, portID, addressID, fdID, sockfdID, fdfdID;	jfieldID thisLocalportID;	jint localport, remotePort, thisLocalport;	jobject newInetAddress, newfd;	jmethodID inetMethod, fdMethod;		int sockfd = getSocketFileDescriptor(env, this);#ifdef DEBUG	printf("NATIVE: PlainSocketImpl.accept(): entering\n");#endif	sock = accept(sockfd, (struct sockaddr *)&ss, &addrlen);	if (sock < 0)		goto error;	switch (ss.__ss_family) {		case AF_INET: {			struct sockaddr_in *sin = (struct sockaddr_in *)&ss;			remoteAddress = (*env)->NewByteArray(env, 4);			remoteAddressBytes = (*env)->GetByteArrayElements(env, remoteAddress, NULL);			memcpy(remoteAddressBytes, &sin->sin_addr, 4);			(*env)->SetByteArrayRegion(env, remoteAddress, 0, 4, remoteAddressBytes);			remotePort = ntohs(sin->sin_port);			break;		}		case AF_INET6: {			struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ss;			remoteAddress = (*env)->NewByteArray(env, 16);			remoteAddressBytes = (*env)->GetByteArrayElements(env, remoteAddress, NULL);			memcpy(remoteAddressBytes, &(sin6->sin6_addr), 16);			(*env)->SetByteArrayRegion(env, remoteAddress, 0, 16, remoteAddressBytes);			remotePort = ntohs(sin6->sin6_port);			break;		}		default:			goto error;	}	implClass = (*env)->GetObjectClass(env, impl);	sockfdID = (*env)->GetFieldID(env, implClass, "sockfd", "I");	localportID = (*env)->GetFieldID(env, implClass, "localport", "I");	portID = (*env)->GetFieldID(env, implClass, "port", "I");	addressID = (*env)->GetFieldID(env, implClass, "address", "Ljava/net/InetAddress;");	fdID = (*env)->GetFieldID(env, implClass, "fd", "Ljava/io/FileDescriptor;");	/* impl.sockfd = sock; */	(*env)->SetIntField(env, impl, sockfdID, sock);		/* impl.localport = this.localport; */	thisClass = (*env)->GetObjectClass(env, this);	thisLocalportID = (*env)->GetFieldID(env, thisClass, "localport", "I");	thisLocalport = (*env)->GetIntField(env, this, thisLocalportID);	(*env)->SetIntField(env, impl, thisLocalportID, thisLocalport);	/* impl.address = new InetAddress(null, remoteAddress); */	inetClass = (*env)->FindClass(env, "java/net/InetAddress");	inetMethod = (*env)->GetMethodID(env, inetClass, "<init>", "(Ljava/lang/String;[B)V");	newInetAddress = (*env)->NewObject(env, inetClass, inetMethod, NULL, remoteAddress);	(*env)->SetObjectField(env, impl, addressID, newInetAddress); 	/* impl.port = remotePort; */	(*env)->SetIntField(env, impl, portID, remotePort);	/* impl.fd = new java.io.FileDescriptor(sock); */	fdClass = (*env)->FindClass(env, "java/io/FileDescriptor");	fdMethod = (*env)->GetMethodID(env, fdClass, "<init>", "()V");	newfd = (*env)->NewObject(env, fdClass, fdMethod);	/* fd.fd = sock */	fdfdID = (*env)->GetFieldID(env, fdClass, "fd", "I");	(*env)->SetIntField(env, newfd, fdfdID, sock);	/* impl.fd = newfd */	(*env)->SetObjectField(env, this, fdID, newfd); #ifdef DEBUG	printf("NATIVE: PlainSocketImpl.accept(): returning\n");#endif	return;	error:#ifdef DEBUG	printf("NATIVE: PlainSocketImpl.accept(): throwing\n");#endif		throwException(env, EX_IO, strerror(errno));		return;}