1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include <unistd.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include "zdtmtst.h"
const char *test_doc = "Check unconnected unix sockets";
const char *test_author = "Vagin Andrew <avagin@parallels.com>";
int main(int argc, char ** argv)
{
int sk, skc;
int ret;
char path[PATH_MAX];
struct sockaddr_un addr;
socklen_t addrlen;
test_init(argc, argv);
sk = socket(AF_UNIX, SOCK_STREAM, 0);
if (sk == -1) {
pr_perror("socket");
return 1;
}
skc = socket(AF_UNIX, SOCK_STREAM, 0);
if (skc == -1) {
pr_perror("socket");
return 1;
}
snprintf(path, sizeof(path), "X/zdtm-%s-%d", argv[0], getpid());
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, path, sizeof(addr.sun_path));
addrlen = sizeof(addr.sun_family) + strlen(path);
addr.sun_path[0] = 0;
ret = bind(sk, (struct sockaddr *) &addr, addrlen);
if (ret) {
fail("bind\n");
return 1;
}
test_daemon();
test_waitsig();
if (listen(sk, 1) == -1) {
pr_perror("listen");
return 1;
}
if (connect(skc, (struct sockaddr *) &addr, addrlen) == -1) {
fail("Unable to connect");
return 1;
}
pass();
return 0;
}
|