#include "command.h"
#include <errno.h>
+#ifdef HAVE_ERROR_H
+#include <error.h>
+#else
+#include "portability/error.h"
+#endif
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
/* Get the current command stream flags */
flags = fcntl(command_stream, F_GETFL, 0);
if (flags == -1) {
- perror("Unexpected command stream error");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "Unexpected command stream error");
}
/* Set the O_NONBLOCK bit */
if (fcntl(command_stream, F_SETFL, flags | O_NONBLOCK)) {
- perror("Unexpected command stream error");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "Unexpected command stream error");
}
}
/* EAGAIN simply means there is no available data to read */
/* EINTR indicates we received a signal during read */
if (errno != EINTR && errno != EAGAIN) {
- perror("Unexpected command buffer read error");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "Unexpected command buffer read error");
}
}
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
+#ifdef HAVE_ERROR_H
+#include <error.h>
+#else
+#include "portability/error.h"
+#endif
#ifdef HAVE_LINUX_ERRQUEUE_H
#include <linux/errqueue.h>
#endif
packet, PACKET_BUFFER_SIZE,
&dest_sockaddr, &src_sockaddr, ¶m);
if (packet_size < 0) {
- perror("Unable to send to localhost");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "Unable to send to localhost");
}
bytes_sent =
packet, PACKET_BUFFER_SIZE,
&dest_sockaddr, &src_sockaddr, ¶m);
if (packet_size < 0) {
- perror("Unable to send to localhost");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "Unable to send to localhost");
}
bytes_sent =
send_packet(net_state, ¶m, MIN_PORT, packet, packet_size,
&dest_sockaddr);
if (bytes_sent < 0) {
- perror("Unable to send with swapped length");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "Unable to send with swapped length");
}
}
flags = fcntl(socket, F_GETFL, 0);
if (flags == -1) {
- perror("Unexpected socket F_GETFL error");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "Unexpected socket F_GETFL error");
}
if (fcntl(socket, F_SETFL, flags | O_NONBLOCK)) {
- perror("Unexpected socket F_SETFL O_NONBLOCK error");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "Unexpected socket F_SETFL O_NONBLOCK error");
}
}
*/
if (!net_state->platform.ip4_present
&& !net_state->platform.ip6_present) {
-
- errno = ip4_err;
- perror("Failure to open IPv4 sockets");
-
- errno = ip6_err;
- perror("Failure to open IPv6 sockets");
-
+ error(0, ip4_err, "Failure to open IPv4 sockets");
+ error(0, ip6_err, "Failure to open IPv6 sockets");
exit(EXIT_FAILURE);
}
}
}
if (gettimeofday(&probe->platform.departure_time, NULL)) {
- perror("gettimeofday failure");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "gettimeofday failure");
}
// there might be an off-by-one in the number of tries here.
if (timestamp == NULL) {
if (gettimeofday(&now, NULL)) {
- perror("gettimeofday failure");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "gettimeofday failure");
}
timestamp = &now;
keep the timing as precise as we can.
*/
if (gettimeofday(×tamp, NULL)) {
- perror("gettimeofday failure");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "gettimeofday failure");
}
if (packet_length == -1) {
continue;
}
- perror("Failure receiving replies");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "Failure receiving replies");
}
#ifdef HAVE_LINUX_ERRQUEUE_H
int proto, length = sizeof(int);
if (getsockopt(socket, SOL_SOCKET, SO_PROTOCOL, &proto, &length) < 0) {
- perror("getsockopt SO_PROTOCOL error");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "getsockopt SO_PROTOCOL error");
}
handle_error_queue_packet(net_state, &remote_addr, ICMP_TIME_EXCEEDED, proto,
packet, packet_length, ×tamp);
if (errno == EAGAIN) {
return;
} else {
- perror("probe socket select error");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "probe socket select error");
}
}
}
if (getsockopt(probe_socket, SOL_SOCKET, SO_ERROR, &err, &err_length)) {
- perror("probe socket SO_ERROR");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "probe socket SO_ERROR");
}
/*
struct probe_t *probe_safe_iter;
if (gettimeofday(&now, NULL)) {
- perror("gettimeofday failure");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "gettimeofday failure");
}
LIST_FOREACH_SAFE(probe, &net_state->outstanding_probes,
struct timeval probe_timeout;
if (gettimeofday(&now, NULL)) {
- perror("gettimeofday failure");
- exit(EXIT_FAILURE);
+ error(EXIT_FAILURE, errno, "gettimeofday failure");
}
have_timeout = false;