/** * Blue Whale Systems Ltd - Michael Magure - 22 Aug 2007 */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_cldc_io_j2me_socket_Protocol_getIPv4Address0() { int ipv4AddressBytes = 0; void *handle = (void*)KNI_GetParameterAsInt(1); int ret = pcsl_socket_getremoteaddr(handle, (char *) &ipv4AddressBytes); if( PCSL_NET_SUCCESS == ret ) { return ipv4AddressBytes; } return 0; }
/** * Gets the requested IP number. * <p> * Java declaration: * <pre> * getHost(Z)Ljava/lang/String; * </pre> * * @param local <tt>true</tt> to get the local host IP address, or * <tt>false</tt> to get the remote host IP address. * * @return the IP address as a dotted-quad <tt>String</tt> */ KNIEXPORT KNI_RETURNTYPE_OBJECT Java_com_sun_midp_io_j2me_socket_Protocol_getHost0(void) { int local; void *pcslHandle; char value[MAX_HOST_LENGTH]; int status = PCSL_NET_INVALID; local = (int)KNI_GetParameterAsBoolean(1); memset(value, '\0', MAX_HOST_LENGTH); KNI_StartHandles(2); KNI_DeclareHandle(result); KNI_DeclareHandle(thisObject); KNI_GetThisPointer(thisObject); pcslHandle = (void *)(getMidpSocketProtocolPtr(thisObject)->handle); if (INVALID_HANDLE == pcslHandle) { KNI_ThrowNew(midpIOException, "invalid handle during socket::getHost"); } else { if (local) { status = pcsl_socket_getlocaladdr(pcslHandle, value); } else { status = pcsl_socket_getremoteaddr(pcslHandle, value); } if (status == PCSL_NET_SUCCESS) { KNI_NewStringUTF(value, result); } else { KNI_ThrowNew(midpIOException, NULL); } } KNI_EndHandlesAndReturnObject(result); }