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.1 (Berkeley) 05/04/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 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(0); 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(0); 42 } 43 if (write(sock, DATA, sizeof(DATA)) < 0) 44 perror("writing on stream socket"); 45 } 46