commit 3ac4747d5703c30e1e8782d45a929dc56469fdf1
parent 9f579656f78d461d9cf697fa14b5c61d2dd211e2
Author: Francesco Saccone <francesco@francescosaccone.com>
Date: Tue, 1 Apr 2025 15:34:17 +0200
fix: add errno messages to print_error calls
Signed-off-by: Francesco Saccone <francesco@francescosaccone.com>
Diffstat:
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/socket.c b/socket.c
@@ -1,4 +1,5 @@
#include <arpa/inet.h>
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -16,7 +17,8 @@ create_socket(unsigned int port) {
struct sockaddr_in address;
if (socket_fd == -1) {
- print_error("error: socket creation");
+ print_error("error: create socket: %s",
+ strerror(errno));
return -1;
}
@@ -25,7 +27,8 @@ create_socket(unsigned int port) {
SO_REUSEADDR,
&yes,
sizeof(yes)) == -1) {
- print_error("error: set SO_REUSEADDR to socket");
+ print_error("error: set SO_REUSEADDR to socket: %s",
+ strerror(errno));
}
memset(&address, 0, sizeof(address));
@@ -36,12 +39,14 @@ create_socket(unsigned int port) {
if (bind(socket_fd,
(struct sockaddr *)&address,
sizeof(address)) == -1) {
- print_error("error: bind socket to address");
+ print_error("error: bind socket to address: %s",
+ strerror(errno));
return -1;
}
if (listen(socket_fd, 3) == -1) {
- print_error("error: listen on socket");
+ print_error("error: listen on socket: %s",
+ strerror(errno));
close(socket_fd);
return -1;
}