2 #include <sys/socket.h>
12 test_sendto_self(int to_s, int s)
18 uint8_t data[CMSG_SPACE(sizeof(int))];
24 iov.iov_len = sizeof(buf);
26 memset(&msg, 0, sizeof(msg));
29 msg.msg_control = ctrl.data;
30 msg.msg_controllen = sizeof(ctrl.data);
32 memset(&ctrl, 0, sizeof(ctrl));
33 cm = CMSG_FIRSTHDR(&msg);
34 cm->cmsg_len = CMSG_LEN(sizeof(int));
35 cm->cmsg_level = SOL_SOCKET;
36 cm->cmsg_type = SCM_RIGHTS;
37 *((int *)CMSG_DATA(cm)) = s;
39 n = sendmsg(to_s, &msg, 0);
41 err(1, "sendmsg failed");
42 else if (n != sizeof(buf))
43 errx(1, "sendmsg sent %d", n);
47 usage(const char *cmd)
49 fprintf(stderr, "%s [-x]\n", cmd);
54 main(int argc, char *argv[])
59 while ((opt = getopt(argc, argv, "x")) != -1) {
70 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, s) < 0)
71 err(1, "socketpair(LOCAL, STREAM) failed");
74 fprintf(stderr, "cross reference\n");
75 /* Send s[0] to s[1].rcvbuf */
76 test_sendto_self(s[0], s[0]);
77 /* Send s[1] to s[0].rcvbuf */
78 test_sendto_self(s[1], s[1]);
80 fprintf(stderr, "self reference\n");
81 /* Send s[0] to s[0].rcvbuf */
82 test_sendto_self(s[1], s[0]);
83 /* Send s[1] to s[1].rcvbuf */
84 test_sendto_self(s[0], s[1]);