.\" Copyright (c) 1986, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" %sccs.include.redist.roff% .\" .\" @(#)udgramsend.c 8.1 (Berkeley) 06/08/93 .\" #include #include #include #include #define DATA "The sea is calm tonight, the tide is full . . ." /* * Here I send a datagram to a receiver whose name I get from the command * line arguments. The form of the command line is udgramsend pathname */ main(argc, argv) int argc; char *argv[]; { int sock; struct sockaddr_un name; /* Create socket on which to send. */ sock = socket(AF_UNIX, SOCK_DGRAM, 0); if (sock < 0) { perror("opening datagram socket"); exit(1); } /* Construct name of socket to send to. */ name.sun_family = AF_UNIX; strcpy(name.sun_path, argv[1]); /* Send message. */ if (sendto(sock, DATA, sizeof(DATA), 0, &name, sizeof(struct sockaddr_un)) < 0) { perror("sending datagram message"); } close(sock); }