From 7f6cf00bf7dff12cbdcbadd8161bb46b818a6b09 Mon Sep 17 00:00:00 2001 From: CSRG Date: Thu, 9 Feb 1989 03:22:30 -0800 Subject: [PATCH] BSD 4_4_Lite2 development Work on file usr/src/contrib/connectd/old/test/fdstrclient.c Synthesized-from: CSRG/cd3/4.4BSD-Lite2 --- .../contrib/connectd/old/test/fdstrclient.c | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 usr/src/contrib/connectd/old/test/fdstrclient.c diff --git a/usr/src/contrib/connectd/old/test/fdstrclient.c b/usr/src/contrib/connectd/old/test/fdstrclient.c new file mode 100644 index 0000000000..78510116ad --- /dev/null +++ b/usr/src/contrib/connectd/old/test/fdstrclient.c @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include + +#include +#include + +struct sockaddr_un to; +struct sockaddr_un from; +struct msghdr msg; +struct iovec iov[1]; +char myname[1024]; + +int catchsig(); + +main(argc, argv) + char *argv[]; +{ + int s, len, tolen, fromlen, fd; + char buf[BUFSIZ]; + struct stat sb; + + if (argc < 3) { + printf("usage: %s socket file\n", argv[0]); + exit(1); + } + if (stat(argv[1], &sb) < 0) { + perror(argv[1]); + exit(1); + } + if ((sb.st_mode & S_IFMT) != S_IFSOCK) { + printf("%s: not a socket\n", argv[1]); + exit(1); + } + fd = open(argv[2], O_RDONLY); + if (fd < 0) { + perror(argv[2]); + exit(1); + } + s = socket(AF_UNIX, SOCK_STREAM, 0); + if (s < 0) { + perror("socket"); + exit(1); + } + from.sun_family = AF_UNIX; + sprintf(myname, "client%d", getpid()); + strcpy(from.sun_path, myname); + if (bind(s, &from, strlen(from.sun_path) + 2) < 0) { + perror("fdclient: bind"); + exit(1); + } + signal(SIGPIPE, catchsig); + signal(SIGINT, catchsig); + to.sun_family = AF_UNIX; + strcpy(to.sun_path, argv[1]); + strcpy(buf, myname); + len = strlen(buf); + tolen = strlen(to.sun_path) + 2; + printf("Client: send greeting from %s\n", myname); fflush(stdout); + if (connect(s, &to, tolen) < 0) { + perror("fdclient: connect"); + goto bad; + } + if (send(s, buf, len, 0) < 0) { + perror("fdclient: send"); + goto bad; + } + len = recv(s, buf, sizeof (buf), 0); + if (len < 0) { + perror("fdclient: recv"); + goto bad; + } + printf("Client: message received"); + if (len > 0) + printf(" \"%.*s\"", len, buf); + putchar('\n'); fflush(stdout); + iov->iov_base = argv[2]; + iov->iov_len = strlen(argv[2]); + msg.msg_iov = iov; + msg.msg_iovlen = 1; +/* msg.msg_accrights = (caddr_t)&fd; + msg.msg_accrightslen = sizeof (fd); +*/ + printf("Client: send \"%s\"\n", argv[2]); fflush(stdout); + if (sendmsg(s, &msg, 0) < 0) { + perror("fdclient: sendmsg"); + goto bad; + } +bad: + unlink(myname); +} + +catchsig(s) + int s; +{ + + psignal(s, "Client"); + unlink(myname); + exit(1); +} -- 2.20.1