count++;
switch (res->ai_family) { case AF_INET: case AF_INET6: count++; break; default: break; }
JNIEXPORT jobjectArray JNICALL Java_java_net_InetAddress_getAllHostAddresses  (JNIEnv *env, jclass this, jstring host){	char *hostname;		struct addrinfo			hints;	struct addrinfo			*res, *reshead;	int err;	int count = 0;	jobjectArray 			addressArray;	jclass 					byteArrayClass;#ifdef DEBUG	printf("NATIVE: InetAddress.getAllHostAddresses(): enter\n");#endif	hostname = (char *)(*env)->GetStringUTFChars(env, host, NULL);	memset(&hints, 0, sizeof(hints));	hints.ai_family = AF_UNSPEC;	hints.ai_flags = AI_PASSIVE;	/* we don't want to get duplicate addresses for TCP/UDP 	 * so we set the hints.ai_socktype to SOCK_STREAM 	 */	/*hints.ai_socktype = SOCK_STREAM;*/	err = getaddrinfo(hostname, NULL, &hints, &res);	if (err) {		/* get a reference to the UnknownHostException */		jclass uhe = (*env)->FindClass(env, "java/net/UnknownHostException");			if (uhe == 0)			return NULL;		/* throw it */		(*env)->ThrowNew(env, uhe, gai_strerror(err));		return NULL;	}	/* save the result pointer and count the number of addresses returned */	reshead = res;	while (res != NULL) {		count++;		res = res->ai_next;	}	/* allocate storage for addressArray */	byteArrayClass = (*env)->FindClass(env, "[B");	addressArray = (*env)->NewObjectArray(env, count, byteArrayClass, NULL);	/* restore the result pointer and get the addresses out */	res = reshead;	count = 0;	while (res != NULL) {		jbyte *addressBytes = NULL;		jbyteArray addressBytesArray;		int addrlen = 0;		switch (res->ai_family) {			case AF_INET:				addressBytes = (jbyte *)&((struct sockaddr_in *)res->ai_addr)->sin_addr;				addrlen = IPV4_ADDRLEN;				break;			case AF_INET6:				addressBytes = (jbyte *)&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;				addrlen = IPV6_ADDRLEN;				break;			default:				break;		}		if (addressBytes != NULL) {			/* now put it in the array */			addressBytesArray = (*env)->NewByteArray(env,addrlen);			(*env)->SetByteArrayRegion(env, addressBytesArray, 0,										addrlen, addressBytes);			(*env)->SetObjectArrayElement(env, addressArray, count,											addressBytesArray);			count++;		}		res = res->ai_next;	} 	/* free the the result pointer */	freeaddrinfo(reshead);#ifdef DEBUG	printf("NATIVE: getAllHostAddresses(): returning\n");#endif	return addressArray;}