mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-11 09:50:12 +00:00
Use errx() instead of fprintf()/exit() for conciseness.
Suggested by: ru (some time ago)
This commit is contained in:
parent
a09c60ffeb
commit
09745181fd
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=136844
@ -68,7 +68,7 @@ main(int argc, char *argv[])
|
||||
*/
|
||||
lso = socket(PF_INET, SOCK_STREAM, 0);
|
||||
if (lso == -1)
|
||||
err(1, "socket");
|
||||
errx(-1, "socket: %s", strerror(errno));
|
||||
|
||||
/*
|
||||
* Step 1. After socket(). Should return EINVAL, since no accept
|
||||
@ -77,16 +77,11 @@ main(int argc, char *argv[])
|
||||
bzero(&afa, sizeof(afa));
|
||||
len = sizeof(afa);
|
||||
ret = getsockopt(lso, SOL_SOCKET, SO_ACCEPTFILTER, &afa, &len);
|
||||
if (ret != -1) {
|
||||
fprintf(stderr, "FAIL: getsockopt() after socket() "
|
||||
"succeeded\n");
|
||||
exit(-1);
|
||||
}
|
||||
if (errno != EINVAL) {
|
||||
fprintf(stderr, "FAIL: getsockopt() after socket() "
|
||||
"failed with %d (%s)\n", errno, strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
if (ret != -1)
|
||||
errx(-1, "FAIL: getsockopt() after socket() succeeded");
|
||||
if (errno != EINVAL)
|
||||
errx(-1, "FAIL: getsockopt() after socket() failed with "
|
||||
"%d (%s)", errno, strerror(errno));
|
||||
|
||||
/*
|
||||
* Step 2. Bind(). Ideally this will succeed.
|
||||
@ -97,7 +92,7 @@ main(int argc, char *argv[])
|
||||
sin.sin_port = htons(8080);
|
||||
sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
if (bind(lso, (struct sockaddr *)&sin, sizeof(sin)) < 0)
|
||||
err(1, "bind");
|
||||
errx(-1, "bind: %s", strerror(errno));
|
||||
|
||||
/*
|
||||
* Step 3: After bind(). getsockopt() should return EINVAL, since no
|
||||
@ -105,15 +100,11 @@ main(int argc, char *argv[])
|
||||
*/
|
||||
len = sizeof(afa);
|
||||
ret = getsockopt(lso, SOL_SOCKET, SO_ACCEPTFILTER, &afa, &len);
|
||||
if (ret != -1) {
|
||||
fprintf(stderr, "FAIL: getsockopt() after bind() succeeded\n");
|
||||
exit(-1);
|
||||
}
|
||||
if (errno != EINVAL) {
|
||||
fprintf(stderr, "FAIL: getsockopt() after bind() failed "
|
||||
"with %d (%s)\n", errno, strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
if (ret != -1)
|
||||
errx(-1, "FAIL: getsockopt() after bind() succeeded");
|
||||
if (errno != EINVAL)
|
||||
errx(-1, "FAIL: getsockopt() after bind() failed with %d (%s)",
|
||||
errno, strerror(errno));
|
||||
|
||||
/*
|
||||
* Step 4: Setsockopt() before listen(). Should fail, since it's not
|
||||
@ -122,11 +113,8 @@ main(int argc, char *argv[])
|
||||
bzero(&afa, sizeof(afa));
|
||||
strcpy(afa.af_name, ACCF_NAME);
|
||||
ret = setsockopt(lso, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(afa));
|
||||
if (ret == 0) {
|
||||
fprintf(stderr, "FAIL: setsockopt() before listen() "
|
||||
"succeeded\n");
|
||||
exit(-1);
|
||||
}
|
||||
if (ret == 0)
|
||||
errx(-1, "FAIL: setsockopt() before listen() succeeded");
|
||||
|
||||
/*
|
||||
* Step 5: Getsockopt() after pre-listen() setsockopt(). Should
|
||||
@ -134,22 +122,18 @@ main(int argc, char *argv[])
|
||||
*/
|
||||
len = sizeof(afa);
|
||||
ret = getsockopt(lso, SOL_SOCKET, SO_ACCEPTFILTER, &afa, &len);
|
||||
if (ret == 0) {
|
||||
fprintf(stderr, "FAIL: getsockopt() after pre-listen() "
|
||||
"setsockopt() succeeded\n");
|
||||
exit(-1);
|
||||
}
|
||||
if (errno != EINVAL) {
|
||||
fprintf(stderr, "FAIL: pre-listen() getsockopt() failed "
|
||||
"with %d (%s)\n", errno, strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
if (ret == 0)
|
||||
errx(-1, "FAIL: getsockopt() after pre-listen() setsockopt() "
|
||||
"succeeded");
|
||||
if (errno != EINVAL)
|
||||
errx(-1, "FAIL: pre-listen() getsockopt() failed with %d (%s)",
|
||||
errno, strerror(errno));
|
||||
|
||||
/*
|
||||
* Step 6: listen().
|
||||
*/
|
||||
if (listen(lso, -1) < 0)
|
||||
err(1, "listen");
|
||||
errx(-1, "listen: %s", strerror(errno));
|
||||
|
||||
/*
|
||||
* Step 7: After listen(). This call to setsockopt() should succeed.
|
||||
@ -157,16 +141,12 @@ main(int argc, char *argv[])
|
||||
bzero(&afa, sizeof(afa));
|
||||
strcpy(afa.af_name, ACCF_NAME);
|
||||
ret = setsockopt(lso, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(afa));
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "FAIL: setsockopt() after listen() failed "
|
||||
"with %d (%s)\n", errno, strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
if (len != sizeof(afa)) {
|
||||
fprintf(stderr, "FAIL: setsockopt() after listen() returned "
|
||||
"wrong size (%d vs expected %d)\n", len, sizeof(afa));
|
||||
exit(-1);
|
||||
}
|
||||
if (ret != 0)
|
||||
errx(-1, "FAIL: setsockopt() after listen() failed with %d "
|
||||
"(%s)", errno, strerror(errno));
|
||||
if (len != sizeof(afa))
|
||||
errx(-1, "FAIL: setsockopt() after listen() returned wrong "
|
||||
"size (%d vs expected %d)", len, sizeof(afa));
|
||||
|
||||
/*
|
||||
* Step 8: After setsockopt(). Should succeed and identify
|
||||
@ -175,24 +155,17 @@ main(int argc, char *argv[])
|
||||
bzero(&afa, sizeof(afa));
|
||||
len = sizeof(afa);
|
||||
ret = getsockopt(lso, SOL_SOCKET, SO_ACCEPTFILTER, &afa, &len);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "FAIL: getsockopt() after listen() "
|
||||
"setsockopt() failed with %d (%s)\n", errno,
|
||||
strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
if (len != sizeof(afa)) {
|
||||
fprintf(stderr, "FAIL: getsockopt() after setsockopet() "
|
||||
" after listen() returned wrong size (got %d expected "
|
||||
"%d)\n", len, sizeof(afa));
|
||||
exit(-1);
|
||||
}
|
||||
if (strcmp(afa.af_name, ACCF_NAME) != 0) {
|
||||
fprintf(stderr, "FAIL: getsockopt() after setsockopt() "
|
||||
"after listen() mismatch (got %s expected %s)\n",
|
||||
afa.af_name, ACCF_NAME);
|
||||
exit(-1);
|
||||
}
|
||||
if (ret != 0)
|
||||
errx(-1, "FAIL: getsockopt() after listen() setsockopt() "
|
||||
"failed with %d (%s)", errno, strerror(errno));
|
||||
if (len != sizeof(afa))
|
||||
errx(-1, "FAIL: getsockopt() after setsockopet() after "
|
||||
"listen() returned wrong size (got %d expected %d)", len,
|
||||
sizeof(afa));
|
||||
if (strcmp(afa.af_name, ACCF_NAME) != 0)
|
||||
errx(-1, "FAIL: getsockopt() after setsockopt() after "
|
||||
"listen() mismatch (got %s expected %s)", afa.af_name,
|
||||
ACCF_NAME);
|
||||
|
||||
printf("PASS\n");
|
||||
close(lso);
|
||||
|
Loading…
Reference in New Issue
Block a user