1 .\" Copyright (c) 1986, 1993
2 .\"	The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" %sccs.include.redist.roff%
5 .\"
6 .\"	@(#)ustreamwrite.c	8.1 (Berkeley) 06/08/93
7 .\"
8 #include <sys/types.h>
9 #include <sys/socket.h>
10 #include <sys/un.h>
11 #include <stdio.h>
12 
13 #define DATA "Half a league, half a league . . ."
14 
15 /*
16  * This program connects to the socket named in the command line and sends a
17  * one line message to that socket. The form of the command line is
18  * ustreamwrite pathname
19  */
20 main(argc, argv)
21 	int argc;
22 	char *argv[];
23 {
24 	int sock;
25 	struct sockaddr_un server;
26 	char buf[1024];
27 
28 	/* Create socket */
29 	sock = socket(AF_UNIX, SOCK_STREAM, 0);
30 	if (sock < 0) {
31 		perror("opening stream socket");
32 		exit(1);
33 	}
34 	/* Connect socket using name specified by command line. */
35 	server.sun_family = AF_UNIX;
36 	strcpy(server.sun_path, argv[1]);
37 
38 	if (connect(sock, &server, sizeof(struct sockaddr_un)) < 0) {
39 		close(sock);
40 		perror("connecting stream socket");
41 		exit(1);
42 	}
43 	if (write(sock, DATA, sizeof(DATA)) < 0)
44 		perror("writing on stream socket");
45 }
46