1 .\" Copyright (c) 1986, 1993 2 .\" The Regents of the University of California. All rights reserved. 3 .\" 4 .\" %sccs.include.redist.roff% 5 .\" 6 .\" @(#)udgramsend.c 8.1 (Berkeley) 06/08/93 7 .\" 8 #include <sys/types.h> 9 #include <sys/socket.h> 10 #include <sys/un.h> 11 #include <stdio.h> 12 13 #define DATA "The sea is calm tonight, the tide is full . . ." 14 15 /* 16 * Here I send a datagram to a receiver whose name I get from the command 17 * line arguments. The form of the command line is udgramsend pathname 18 */ 19 20 main(argc, argv) 21 int argc; 22 char *argv[]; 23 { 24 int sock; 25 struct sockaddr_un name; 26 27 /* Create socket on which to send. */ 28 sock = socket(AF_UNIX, SOCK_DGRAM, 0); 29 if (sock < 0) { 30 perror("opening datagram socket"); 31 exit(1); 32 } 33 /* Construct name of socket to send to. */ 34 name.sun_family = AF_UNIX; 35 strcpy(name.sun_path, argv[1]); 36 /* Send message. */ 37 if (sendto(sock, DATA, sizeof(DATA), 0, 38 &name, sizeof(struct sockaddr_un)) < 0) { 39 perror("sending datagram message"); 40 } 41 close(sock); 42 } 43