diff options
| author | Frediano Ziglio <fziglio@redhat.com> | 2016-11-15 16:03:23 +0000 |
|---|---|---|
| committer | Frediano Ziglio <fziglio@redhat.com> | 2016-11-15 16:03:23 +0000 |
| commit | bb81bbac972b6df99906c3c2aaae3a41717dd07b (patch) | |
| tree | 5d0eae1cea90b78e442898446f4582ba89152b6b /tun.c | |
| parent | 31774993fabf9aa85b7b7e16c1fd8593dbf4df24 (diff) | |
Use err instead of perror/exit
More or less perror+exit does the same of err call
so simplify code using err function.
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Diffstat (limited to 'tun.c')
| -rw-r--r-- | tun.c | 37 |
1 files changed, 13 insertions, 24 deletions
@@ -5,6 +5,7 @@ #include <unistd.h> #include <poll.h> #include <errno.h> +#include <err.h> #include <stdbool.h> #include <sys/socket.h> #include <linux/if.h> @@ -100,22 +101,16 @@ tun_init(const char *ip) tun_name[0] = 0; fd = tun_alloc(tun_name, IFF_TUN|IFF_NO_PI); - if (fd < 0) { - perror("error creating TUN device"); - exit(EXIT_FAILURE); - } + if (fd < 0) + err(EXIT_FAILURE, "error creating TUN device"); sprintf(cmd, "ip link set %s up", tun_name); - if (system(cmd) != 0) { - perror("system"); - exit(EXIT_FAILURE); - } + if (system(cmd) != 0) + err(EXIT_FAILURE, "system"); sprintf(cmd, "ip addr add %s dev %s", ip, tun_name); - if (system(cmd) != 0) { - perror("system"); - exit(EXIT_FAILURE); - } + if (system(cmd) != 0) + err(EXIT_FAILURE, "system"); return fd; } @@ -141,10 +136,8 @@ create_remote_socket(void) } remote_sock = socket(AF_INET, SOCK_DGRAM, 0); - if (remote_sock < 0) { - perror("socket"); - exit(EXIT_FAILURE); - } + if (remote_sock < 0) + err(EXIT_FAILURE, "socket"); } void @@ -198,10 +191,8 @@ tun_set_server(int port) sin.sin_port = htons((short) port); sin.sin_addr.s_addr = INADDR_ANY; - if (bind(remote_sock, (struct sockaddr *) &sin, sizeof(sin)) < 0) { - perror("bind"); - exit(EXIT_FAILURE); - } + if (bind(remote_sock, (struct sockaddr *) &sin, sizeof(sin)) < 0) + err(EXIT_FAILURE, "bind"); remote_connected = false; is_server = true; } @@ -532,10 +523,8 @@ handle_tun(void) if (tun_log_filename) { pcap = pcap_open(tun_log_filename); - if (!pcap) { - perror("error opening log file"); - exit(EXIT_FAILURE); - } + if (!pcap) + err(EXIT_FAILURE, "error opening log file"); } if (remote_sock >= 0) |
