summaryrefslogtreecommitdiff
path: root/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'socket.c')
-rw-r--r--socket.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/socket.c b/socket.c
index 6e1db07..14d5c62 100644
--- a/socket.c
+++ b/socket.c
@@ -5,6 +5,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/time.h>
+#include <fcntl.h>
#define TEST2(c, l, ...) ((c) ? 1 : \
(err++,printf(__FILE__":"#l": "#c" failed: " __VA_ARGS__),putchar('\n'),0))
@@ -17,7 +18,7 @@ int test_socket(void)
{
int err = 0;
struct sockaddr_in sa = { .sin_family = AF_INET };
- int s, c;
+ int s, c, t;
char buf[100];
TESTE((s=socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP))>=0);
@@ -35,6 +36,27 @@ int test_socket(void)
close(c);
close(s);
-
+
+ memset(&sa, 0, sizeof sa);
+ sa.sin_family = AF_INET;
+ TESTE((s=socket(PF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP))>=0);
+ TEST(fcntl(s, F_GETFD)&FD_CLOEXEC, "SOCK_CLOEXEC did not work");
+ TESTE(bind(s, (void *)&sa, sizeof sa)==0);
+ TESTE(getsockname(s, (void *)&sa, (socklen_t[]){sizeof sa})==0);
+ sa.sin_addr.s_addr = htonl(0x7f000001);
+
+ TESTE(listen(s, 1)==0);
+
+ TESTE((c=socket(PF_INET, SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP))>=0);
+ TEST(fcntl(c, F_GETFL)&O_NONBLOCK, "SOCK_NONBLOCK did not work");
+
+ TESTE(connect(c, (void *)&sa, sizeof sa)==0 || errno==EINPROGRESS);
+
+ TESTE((t=accept(s, (void *)&sa, &(socklen_t){sizeof sa}))>=0);
+
+ close(t);
+ close(c);
+ close(s);
+
return err;
}