1*62785Sbostic .\" Copyright (c) 1986, 1993
2*62785Sbostic .\"	The Regents of the University of California.  All rights reserved.
348154Sbostic .\"
448154Sbostic .\" %sccs.include.redist.roff%
548154Sbostic .\"
6*62785Sbostic .\"	@(#)udgramsend.c	8.1 (Berkeley) 06/08/93
748154Sbostic .\"
827700Smckusick #include <sys/types.h>
927700Smckusick #include <sys/socket.h>
1027700Smckusick #include <sys/un.h>
1127700Smckusick #include <stdio.h>
1227700Smckusick 
1327700Smckusick #define DATA "The sea is calm tonight, the tide is full . . ."
1427700Smckusick 
1527700Smckusick /*
1627700Smckusick  * Here I send a datagram to a receiver whose name I get from the command
1727700Smckusick  * line arguments.  The form of the command line is udgramsend pathname
1827700Smckusick  */
1927700Smckusick 
2027700Smckusick main(argc, argv)
2127884Skarels 	int argc;
2227884Skarels 	char *argv[];
2327700Smckusick {
2427884Skarels 	int sock;
2527700Smckusick 	struct sockaddr_un name;
2627700Smckusick 
2727700Smckusick 	/* Create socket on which to send. */
2827700Smckusick 	sock = socket(AF_UNIX, SOCK_DGRAM, 0);
2927700Smckusick 	if (sock < 0) {
3027700Smckusick 		perror("opening datagram socket");
3127884Skarels 		exit(1);
3227700Smckusick 	}
3327700Smckusick 	/* Construct name of socket to send to. */
3427700Smckusick 	name.sun_family = AF_UNIX;
3527700Smckusick 	strcpy(name.sun_path, argv[1]);
3627700Smckusick 	/* Send message. */
3727700Smckusick 	if (sendto(sock, DATA, sizeof(DATA), 0,
3827700Smckusick 	    &name, sizeof(struct sockaddr_un)) < 0) {
3927700Smckusick 		perror("sending datagram message");
4027700Smckusick 	}
4127700Smckusick 	close(sock);
4227700Smckusick }
43