127700Smckusick .\" Copyright (c) 1986 Regents of the University of California.
227700Smckusick .\" All rights reserved.  The Berkeley software License Agreement
327700Smckusick .\" specifies the terms and conditions for redistribution.
427700Smckusick .\"
5*27884Skarels .\"	@(#)udgramsend.c	6.2 (Berkeley) 05/08/86
627700Smckusick .\"
727700Smckusick #include <sys/types.h>
827700Smckusick #include <sys/socket.h>
927700Smckusick #include <sys/un.h>
1027700Smckusick #include <stdio.h>
1127700Smckusick 
1227700Smckusick #define DATA "The sea is calm tonight, the tide is full . . ."
1327700Smckusick 
1427700Smckusick /*
1527700Smckusick  * Here I send a datagram to a receiver whose name I get from the command
1627700Smckusick  * line arguments.  The form of the command line is udgramsend pathname
1727700Smckusick  */
1827700Smckusick 
1927700Smckusick main(argc, argv)
20*27884Skarels 	int argc;
21*27884Skarels 	char *argv[];
2227700Smckusick {
23*27884Skarels 	int sock;
2427700Smckusick 	struct sockaddr_un name;
2527700Smckusick 
2627700Smckusick 	/* Create socket on which to send. */
2727700Smckusick 	sock = socket(AF_UNIX, SOCK_DGRAM, 0);
2827700Smckusick 	if (sock < 0) {
2927700Smckusick 		perror("opening datagram socket");
30*27884Skarels 		exit(1);
3127700Smckusick 	}
3227700Smckusick 	/* Construct name of socket to send to. */
3327700Smckusick 	name.sun_family = AF_UNIX;
3427700Smckusick 	strcpy(name.sun_path, argv[1]);
3527700Smckusick 	/* Send message. */
3627700Smckusick 	if (sendto(sock, DATA, sizeof(DATA), 0,
3727700Smckusick 	    &name, sizeof(struct sockaddr_un)) < 0) {
3827700Smckusick 		perror("sending datagram message");
3927700Smckusick 	}
4027700Smckusick 	close(sock);
4127700Smckusick }
42