11638Srgrimes.\" Copyright (c) 1986, 1993
21638Srgrimes.\"	The Regents of the University of California.  All rights reserved.
31638Srgrimes.\"
41638Srgrimes.\" Redistribution and use in source and binary forms, with or without
51638Srgrimes.\" modification, are permitted provided that the following conditions
61638Srgrimes.\" are met:
71638Srgrimes.\" 1. Redistributions of source code must retain the above copyright
81638Srgrimes.\"    notice, this list of conditions and the following disclaimer.
91638Srgrimes.\" 2. Redistributions in binary form must reproduce the above copyright
101638Srgrimes.\"    notice, this list of conditions and the following disclaimer in the
111638Srgrimes.\"    documentation and/or other materials provided with the distribution.
12263142Seadler.\" 3. Neither the name of the University nor the names of its contributors
131638Srgrimes.\"    may be used to endorse or promote products derived from this software
141638Srgrimes.\"    without specific prior written permission.
151638Srgrimes.\"
161638Srgrimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
171638Srgrimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
181638Srgrimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
191638Srgrimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
201638Srgrimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
211638Srgrimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
221638Srgrimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
231638Srgrimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
241638Srgrimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
251638Srgrimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
261638Srgrimes.\" SUCH DAMAGE.
271638Srgrimes.\"
281638Srgrimes.\"	@(#)ustreamwrite.c	8.1 (Berkeley) 6/8/93
291638Srgrimes.\"
301638Srgrimes#include <sys/types.h>
311638Srgrimes#include <sys/socket.h>
321638Srgrimes#include <sys/un.h>
331638Srgrimes#include <stdio.h>
341638Srgrimes
351638Srgrimes#define DATA "Half a league, half a league . . ."
361638Srgrimes
371638Srgrimes/*
381638Srgrimes * This program connects to the socket named in the command line and sends a
391638Srgrimes * one line message to that socket. The form of the command line is
408875Srgrimes * ustreamwrite pathname
411638Srgrimes */
421638Srgrimesmain(argc, argv)
431638Srgrimes	int argc;
441638Srgrimes	char *argv[];
451638Srgrimes{
461638Srgrimes	int sock;
471638Srgrimes	struct sockaddr_un server;
481638Srgrimes	char buf[1024];
491638Srgrimes
501638Srgrimes	/* Create socket */
511638Srgrimes	sock = socket(AF_UNIX, SOCK_STREAM, 0);
521638Srgrimes	if (sock < 0) {
531638Srgrimes		perror("opening stream socket");
541638Srgrimes		exit(1);
551638Srgrimes	}
561638Srgrimes	/* Connect socket using name specified by command line. */
571638Srgrimes	server.sun_family = AF_UNIX;
581638Srgrimes	strcpy(server.sun_path, argv[1]);
591638Srgrimes
601638Srgrimes	if (connect(sock, &server, sizeof(struct sockaddr_un)) < 0) {
611638Srgrimes		close(sock);
621638Srgrimes		perror("connecting stream socket");
631638Srgrimes		exit(1);
641638Srgrimes	}
651638Srgrimes	if (write(sock, DATA, sizeof(DATA)) < 0)
661638Srgrimes		perror("writing on stream socket");
671638Srgrimes}
68