1*62785Sbostic .\" Copyright (c) 1986, 1993
2*62785Sbostic .\"	The Regents of the University of California.  All rights reserved.
348154Sbostic .\"
448154Sbostic .\" %sccs.include.redist.roff%
548154Sbostic .\"
6*62785Sbostic .\"	@(#)ustreamwrite.c	8.1 (Berkeley) 06/08/93
748154Sbostic .\"
827700Smckusick #include <sys/types.h>
927700Smckusick #include <sys/socket.h>
1027700Smckusick #include <sys/un.h>
1127700Smckusick #include <stdio.h>
1227700Smckusick 
1327700Smckusick #define DATA "Half a league, half a league . . ."
1427700Smckusick 
1527700Smckusick /*
1627700Smckusick  * This program connects to the socket named in the command line and sends a
1727700Smckusick  * one line message to that socket. The form of the command line is
1827700Smckusick  * ustreamwrite pathname
1927700Smckusick  */
2027700Smckusick main(argc, argv)
2127884Skarels 	int argc;
2227884Skarels 	char *argv[];
2327700Smckusick {
2427884Skarels 	int sock;
2527700Smckusick 	struct sockaddr_un server;
2627884Skarels 	char buf[1024];
2727700Smckusick 
2827700Smckusick 	/* Create socket */
2927700Smckusick 	sock = socket(AF_UNIX, SOCK_STREAM, 0);
3027700Smckusick 	if (sock < 0) {
3127700Smckusick 		perror("opening stream socket");
3227884Skarels 		exit(1);
3327700Smckusick 	}
3427700Smckusick 	/* Connect socket using name specified by command line. */
3527700Smckusick 	server.sun_family = AF_UNIX;
3627700Smckusick 	strcpy(server.sun_path, argv[1]);
3727700Smckusick 
3827700Smckusick 	if (connect(sock, &server, sizeof(struct sockaddr_un)) < 0) {
3927700Smckusick 		close(sock);
4027700Smckusick 		perror("connecting stream socket");
4127884Skarels 		exit(1);
4227700Smckusick 	}
4327700Smckusick 	if (write(sock, DATA, sizeof(DATA)) < 0)
4427700Smckusick 		perror("writing on stream socket");
4527700Smckusick }
46