diff --git a/src/send/core/send_packet.c b/src/send/core/send_packet.c index d8cf15b..4d9779a 100644 --- a/src/send/core/send_packet.c +++ b/src/send/core/send_packet.c @@ -1,9 +1,13 @@ +#include "internal/icmp_internal.h" #include "internal/icmp_send.h" #include #include #include #include +/* Forward declarations */ +static int handle_send_error(struct icmp_handle *h); +/* -------------------- */ int send_packet(struct icmp_handle *h, const void *buffer, size_t len, struct sockaddr_in *dest) @@ -14,19 +18,7 @@ send_packet(struct icmp_handle *h, const void *buffer, size_t len, sizeof(struct sockaddr_in)); if (bytes_sent < 0) - { - int saved_errno = errno; - - if (EAGAIN == saved_errno || EWOULDBLOCK == saved_errno) - { - icmp_set_error_fmt(h, ICMP_ERR_EAGAIN, - "Send would block (buffer full, retry later)"); - return -1; - } - icmp_set_error_fmt(h, ICMP_ERR_SEND, "sendto() failed: %s", - strerror(saved_errno)); - return -1; - } + return handle_send_error(h); if ((size_t)bytes_sent != len) { @@ -37,3 +29,20 @@ send_packet(struct icmp_handle *h, const void *buffer, size_t len, return 0; } + +static int +handle_send_error(struct icmp_handle *h) +{ + int saved_errno; + + saved_errno = errno; + if (EAGAIN == saved_errno || EWOULDBLOCK == saved_errno) + { + icmp_set_error_fmt(h, ICMP_ERR_EAGAIN, + "Send would block (buffer full, retry later)"); + return -1; + } + icmp_set_error_fmt(h, ICMP_ERR_SEND, "sendto() failed: %s", + strerror(saved_errno)); + return -1; +}