1 /* Example of Reading Datagrams
2 Copyright (C) 1991-2014 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, if not, see <http://www.gnu.org/licenses/>.
22 #include <sys/socket.h>
25 #define SERVER "/tmp/serversocket"
26 #define CLIENT "/tmp/mysocket"
28 #define MESSAGE "Yow!!! Are we having fun yet?!?"
33 extern int make_named_socket (const char *name
);
36 struct sockaddr_un name
;
40 /* Make the socket. */
41 sock
= make_named_socket (CLIENT
);
43 /* Initialize the server socket address. */
44 name
.sun_family
= AF_LOCAL
;
45 strcpy (name
.sun_path
, SERVER
);
46 size
= strlen (name
.sun_path
) + sizeof (name
.sun_family
);
48 /* Send the datagram. */
49 nbytes
= sendto (sock
, MESSAGE
, strlen (MESSAGE
) + 1, 0,
50 (struct sockaddr
*) & name
, size
);
53 perror ("sendto (client)");
57 /* Wait for a reply. */
58 nbytes
= recvfrom (sock
, message
, MAXMSG
, 0, NULL
, 0);
61 perror ("recfrom (client)");
65 /* Print a diagnostic message. */
66 fprintf (stderr
, "Client: got message: %s\n", message
);