Skip to content

Commit

Permalink
Merge pull request #120 from compscidr/jason/handle-failed-sendto
Browse files Browse the repository at this point in the history
exception handling for failed sendto
  • Loading branch information
compscidr authored Aug 22, 2024
2 parents a3ad3cf + 7d4e603 commit 8a56f35
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion icmp-common/src/main/java/com/jasonernst/icmp_common/ICMP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ abstract class ICMP {
val stringDumper = StringPacketDumper()
logger.debug("bytesToSend: ${icmpHeader.toByteArray().size}\n${stringDumper.dumpBufferToString(bytesToSend, 0 , bytesToSend.limit())}")
val sendTimeMs = System.currentTimeMillis()
val bytesSent = sendto(fd, bytesToSend, 0, inetAddress, ICMP_PORT)
val bytesSent = try {
sendto(fd, bytesToSend, 0, inetAddress, ICMP_PORT)
} catch (e: Exception) {
return PingResult.Failed(e.message ?: "Failed to ping ${inetAddress.hostAddress}")
}
logger.debug("bytesSent: $bytesSent")

val recvBuffer = ByteBuffer.allocate(1024)
Expand Down

0 comments on commit 8a56f35

Please sign in to comment.