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