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