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