1 /* Datagram Socket Example
2 Copyright (C) 1991-2013 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/>.
21 #include <sys/socket.h>
24 #define SERVER "/tmp/serversocket"
32 struct sockaddr_un name
;
36 /* Remove the filename first, it's ok if the call fails */
39 /* Make the socket, then loop endlessly. */
40 sock
= make_named_socket (SERVER
);
43 /* Wait for a datagram. */
45 nbytes
= recvfrom (sock
, message
, MAXMSG
, 0,
46 (struct sockaddr
*) & name
, &size
);
49 perror ("recfrom (server)");
53 /* Give a diagnostic message. */
54 fprintf (stderr
, "Server: got message: %s\n", message
);
56 /* Bounce the message back to the sender. */
57 nbytes
= sendto (sock
, message
, nbytes
, 0,
58 (struct sockaddr
*) & name
, size
);
61 perror ("sendto (server)");