summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-01-10 00:45:48 +0200
committerDaniel Borkmann <dborkman@redhat.com>2015-01-11 12:10:52 +0100
commitf7f5b215eadf47fde1300cd8855532bc4bfe0ff4 (patch)
tree1d0e81eea510d8d90083ca371918dc7b441f82c6
parentb8a9e53262ab24231542e9ce93daadaf3809dac2 (diff)
sock: Add cause message in case of error
Add error messages which explain the cause of error state of the socket functions, so it makes message like: $ ./netsniff-ng/netsniff-ng -i wlp3s0 Creation of PF socket failed: Operation not permitted more understandable. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
-rw-r--r--sock.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/sock.c b/sock.c
index 6c973ed..fbf50d8 100644
--- a/sock.c
+++ b/sock.c
@@ -19,7 +19,7 @@ int af_socket(int af)
sock = socket(af, SOCK_DGRAM, 0);
if (unlikely(sock < 0))
- panic("Creation AF socket failed!\n");
+ panic("Creation AF socket failed: %s\n", strerror(errno));
return sock;
}
@@ -28,7 +28,7 @@ int pf_socket(void)
{
int sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (unlikely(sock < 0))
- panic("Creation of PF socket failed!\n");
+ panic("Creation of PF socket failed: %s\n", strerror(errno));
return sock;
}
@@ -37,7 +37,7 @@ int pf_tx_socket(void)
{
int sock = socket(PF_PACKET, SOCK_RAW, 0);
if (unlikely(sock < 0))
- panic("Creation of PF TX socket failed!\n");
+ panic("Creation of PF TX socket failed: %s\n", strerror(errno));
return sock;
}
@@ -67,14 +67,14 @@ void set_sock_prio(int fd, int prio)
ret = setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val));
if (unlikely(ret))
- panic("Cannot set socket priority!\n");
+ panic("Cannot set socket priority: %s\n", strerror(errno));
}
void set_nonblocking(int fd)
{
int ret = fcntl(fd, F_SETFL, fcntl(fd, F_GETFD, 0) | O_NONBLOCK);
if (unlikely(ret < 0))
- panic("Cannot fcntl!\n");
+ panic("Cannot fcntl: %s\n", strerror(errno));
}
int set_nonblocking_sloppy(int fd)
@@ -88,7 +88,7 @@ void set_socket_keepalive(int fd)
ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof(one));
if (unlikely(ret))
- panic("Cannot set TCP keepalive!\n");
+ panic("Cannot set TCP keepalive: %s\n", strerror(errno));
}
void set_tcp_nodelay(int fd)
@@ -97,7 +97,7 @@ void set_tcp_nodelay(int fd)
ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
if (unlikely(ret))
- panic("Cannot set TCP nodelay!\n");
+ panic("Cannot set TCP nodelay: %s\n", strerror(errno));
}
int set_ipv6_only(int fd)
@@ -112,7 +112,7 @@ int set_reuseaddr(int fd)
ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
if (unlikely(ret < 0))
- panic("Cannot reuse addr!\n");
+ panic("Cannot reuse addr: %s\n", strerror(errno));
return 0;
}
@@ -123,7 +123,7 @@ void set_mtu_disc_dont(int fd)
ret = setsockopt(fd, SOL_IP, IP_MTU_DISCOVER, &mtu, sizeof(mtu));
if (unlikely(ret))
- panic("Cannot set MTU discovery options!\n");
+ panic("Cannot set MTU discovery options: %s\n", strerror(errno));
}
enum {