diff options
author | rwatson <rwatson@FreeBSD.org> | 2004-10-23 22:11:35 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2004-10-23 22:11:35 +0000 |
commit | e5417785bfd48ee9ddbfa3f83b5b82b5c1336ac5 (patch) | |
tree | 7e11bc709a3c42a4c86736801220d5a968f9e6c8 /tools/regression/netinet/tcpstream/tcpstream.c | |
parent | 8cebff99b35a5edd06d796192e0ce76c9d754f58 (diff) | |
download | FreeBSD-src-e5417785bfd48ee9ddbfa3f83b5b82b5c1336ac5.zip FreeBSD-src-e5417785bfd48ee9ddbfa3f83b5b82b5c1336ac5.tar.gz |
Use errx() instead of perror()/exit() for conciseness.
Suggested by: ru (some time ago)
Diffstat (limited to 'tools/regression/netinet/tcpstream/tcpstream.c')
-rw-r--r-- | tools/regression/netinet/tcpstream/tcpstream.c | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/tools/regression/netinet/tcpstream/tcpstream.c b/tools/regression/netinet/tcpstream/tcpstream.c index 5417d08..c8fe9a3 100644 --- a/tools/regression/netinet/tcpstream/tcpstream.c +++ b/tools/regression/netinet/tcpstream/tcpstream.c @@ -40,6 +40,8 @@ #include <arpa/inet.h> +#include <err.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -88,15 +90,11 @@ tcpstream_client(struct sockaddr_in sin, long seed) srandom(seed); sock = socket(PF_INET, SOCK_STREAM, 0); - if (sock == -1) { - perror("socket"); - exit(-1); - } + if (sock == -1) + errx(-1, "socket: %s", strerror(errno)); - if (connect(sock, (struct sockaddr *) &sin, sizeof(sin)) == -1) { - perror("connect"); - exit(-1); - } + if (connect(sock, (struct sockaddr *) &sin, sizeof(sin)) == -1) + errx(-1, "connect: %s", strerror(errno)); for (j = 0; j < MAX_LOOPS; j++) { for (i = 0; i < MAX_LONGS; i++) { @@ -128,20 +126,14 @@ tcpstream_server(struct sockaddr_in sin, long seed) int input_byte_counter; listen_sock = socket(PF_INET, SOCK_STREAM, 0); - if (listen_sock == -1) { - perror("socket"); - exit(-1); - } + if (listen_sock == -1) + errx(-1, "socket: %s", strerror(errno)); - if (bind(listen_sock, (struct sockaddr *)&sin, sizeof(sin)) == -1) { - perror("bind"); - exit(-1); - } + if (bind(listen_sock, (struct sockaddr *)&sin, sizeof(sin)) == -1) + errx(-1, "bind: %s", strerror(errno)); - if (listen(listen_sock, -1) == -1) { - perror("listen"); - exit(-1); - } + if (listen(listen_sock, -1) == -1) + errx(-1, "listen: %s", strerror(errno)); while (1) { bzero(&other_sin, sizeof(other_sin)); @@ -201,11 +193,8 @@ main(int argc, char *argv[]) sin.sin_len = sizeof(sin); sin.sin_family = AF_INET; - if (inet_aton(argv[2], &sin.sin_addr) != 1) { - errno = EINVAL; - perror(argv[2]); - exit(-1); - } + if (inet_aton(argv[2], &sin.sin_addr) != 1) + errx(-1, "%s: %s", argv[2], strerror(EINVAL)); port = strtoul(argv[3], &dummy, 10); if (port < 1 || port > 65535 || *dummy != '\0') |