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 .\" @(#)udgramsend.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 "The sea is calm tonight, the tide is full . . ." 13*27700Smckusick 14*27700Smckusick /* 15*27700Smckusick * Here I send a datagram to a receiver whose name I get from the command 16*27700Smckusick * line arguments. The form of the command line is udgramsend pathname 17*27700Smckusick */ 18*27700Smckusick 19*27700Smckusick main(argc, argv) 20*27700Smckusick int argc; 21*27700Smckusick char *argv[]; 22*27700Smckusick { 23*27700Smckusick int sock; 24*27700Smckusick struct sockaddr_un name; 25*27700Smckusick 26*27700Smckusick /* Create socket on which to send. */ 27*27700Smckusick sock = socket(AF_UNIX, SOCK_DGRAM, 0); 28*27700Smckusick if (sock < 0) { 29*27700Smckusick perror("opening datagram socket"); 30*27700Smckusick exit(-1); 31*27700Smckusick } 32*27700Smckusick /* Construct name of socket to send to. */ 33*27700Smckusick name.sun_family = AF_UNIX; 34*27700Smckusick strcpy(name.sun_path, argv[1]); 35*27700Smckusick /* Send message. */ 36*27700Smckusick if (sendto(sock, DATA, sizeof(DATA), 0, 37*27700Smckusick &name, sizeof(struct sockaddr_un)) < 0) { 38*27700Smckusick perror("sending datagram message"); 39*27700Smckusick } 40*27700Smckusick close(sock); 41*27700Smckusick } 42