430 if (trafficClass != 0 && ipv6_available()) {
431 NET_SetTrafficClass(&rmtaddr, trafficClass);
432 }
433
434 /*
435 * Send the datagram.
436 *
437 * If we are connected it's possible that sendto will return
438 * ECONNREFUSED indicating that an ICMP port unreachable has
439 * received.
440 */
441 ret = NET_SendTo(fd, fullPacket, packetBufferLen, 0, rmtaddrP, len);
442
443 if (ret < 0) {
444 if (errno == ECONNREFUSED) {
445 JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException",
446 "ICMP Port Unreachable");
447 } else {
448 JNU_ThrowIOExceptionWithLastError(env, "sendto failed");
449 }
450 }
451
452 if (mallocedPacket) {
453 free(fullPacket);
454 }
455 return;
456 }
457
458 /*
459 * Class: java_net_PlainDatagramSocketImpl
460 * Method: peek
461 * Signature: (Ljava/net/InetAddress;)I
462 */
463 JNIEXPORT jint JNICALL
464 Java_java_net_PlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
465 jobject addressObj) {
466
467 jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
468 jint timeout = (*env)->GetIntField(env, this, pdsi_timeoutID);
469 jint fd;
830 n = packetBufferLen;
831 }
832 if (n == -1) {
833 (*env)->SetIntField(env, packet, dp_offsetID, 0);
834 (*env)->SetIntField(env, packet, dp_lengthID, 0);
835 if (errno == ECONNREFUSED) {
836 JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException",
837 "ICMP Port Unreachable");
838 } else {
839 if (errno == EBADF) {
840 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
841 } else {
842 JNU_ThrowByNameWithMessageAndLastError
843 (env, JNU_JAVANETPKG "SocketException", "Receive failed");
844 }
845 }
846 } else {
847 int port;
848 jobject packetAddress;
849
850 /*
851 * success - fill in received address...
852 *
853 * REMIND: Fill in an int on the packet, and create inetadd
854 * object in Java, as a performance improvement. Also
855 * construct the inetadd object lazily.
856 */
857
858 /*
859 * Check if there is an InetAddress already associated with this
860 * packet. If so we check if it is the same source address. We
861 * can't update any existing InetAddress because it is immutable
862 */
863 packetAddress = (*env)->GetObjectField(env, packet, dp_addressID);
864 if (packetAddress != NULL) {
865 if (!NET_SockaddrEqualsInetAddress(env, &rmtaddr,
866 packetAddress)) {
867 /* force a new InetAddress to be created */
868 packetAddress = NULL;
869 }
|
430 if (trafficClass != 0 && ipv6_available()) {
431 NET_SetTrafficClass(&rmtaddr, trafficClass);
432 }
433
434 /*
435 * Send the datagram.
436 *
437 * If we are connected it's possible that sendto will return
438 * ECONNREFUSED indicating that an ICMP port unreachable has
439 * received.
440 */
441 ret = NET_SendTo(fd, fullPacket, packetBufferLen, 0, rmtaddrP, len);
442
443 if (ret < 0) {
444 if (errno == ECONNREFUSED) {
445 JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException",
446 "ICMP Port Unreachable");
447 } else {
448 JNU_ThrowIOExceptionWithLastError(env, "sendto failed");
449 }
450 } else if (ret > 0) {
451 JVM_callNetworkWriteBytes(env, ret);
452 }
453
454 if (mallocedPacket) {
455 free(fullPacket);
456 }
457 return;
458 }
459
460 /*
461 * Class: java_net_PlainDatagramSocketImpl
462 * Method: peek
463 * Signature: (Ljava/net/InetAddress;)I
464 */
465 JNIEXPORT jint JNICALL
466 Java_java_net_PlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
467 jobject addressObj) {
468
469 jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
470 jint timeout = (*env)->GetIntField(env, this, pdsi_timeoutID);
471 jint fd;
832 n = packetBufferLen;
833 }
834 if (n == -1) {
835 (*env)->SetIntField(env, packet, dp_offsetID, 0);
836 (*env)->SetIntField(env, packet, dp_lengthID, 0);
837 if (errno == ECONNREFUSED) {
838 JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException",
839 "ICMP Port Unreachable");
840 } else {
841 if (errno == EBADF) {
842 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
843 } else {
844 JNU_ThrowByNameWithMessageAndLastError
845 (env, JNU_JAVANETPKG "SocketException", "Receive failed");
846 }
847 }
848 } else {
849 int port;
850 jobject packetAddress;
851
852 if (n > 0) {
853 JVM_callNetworkReadBytes(env, n);
854 }
855
856 /*
857 * success - fill in received address...
858 *
859 * REMIND: Fill in an int on the packet, and create inetadd
860 * object in Java, as a performance improvement. Also
861 * construct the inetadd object lazily.
862 */
863
864 /*
865 * Check if there is an InetAddress already associated with this
866 * packet. If so we check if it is the same source address. We
867 * can't update any existing InetAddress because it is immutable
868 */
869 packetAddress = (*env)->GetObjectField(env, packet, dp_addressID);
870 if (packetAddress != NULL) {
871 if (!NET_SockaddrEqualsInetAddress(env, &rmtaddr,
872 packetAddress)) {
873 /* force a new InetAddress to be created */
874 packetAddress = NULL;
875 }
|