1
#define _XOPEN_SOURCE 500
4
* Copyright (C) 2002-2005 Novell/SUSE
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License as
8
* published by the Free Software Foundation, version 2 of the
14
#include <sys/types.h>
17
#include <sys/socket.h>
26
int main(int argc, char *argv[]) {
28
struct sockaddr_un remote;
29
char read_buffer[17], f_buf[255];
32
struct cmsghdr *ctrl_mesg;
34
if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
35
fprintf(stderr, "FAIL CLIENT - sock %s\n",
40
remote.sun_family = AF_UNIX;
41
strcpy(remote.sun_path, argv[1]);
42
len = strlen(remote.sun_path) + sizeof(remote.sun_family);
43
if (connect(sock, (struct sockaddr *)&remote, len) == -1) {
44
fprintf(stderr, "FAIL CLIENT - connect %s\n",
49
vect.iov_base = f_buf;
57
ctrl_mesg = alloca(sizeof (struct cmsghdr) + sizeof(fd));
58
ctrl_mesg->cmsg_len = sizeof(struct cmsghdr) + sizeof(fd);
59
mesg.msg_control = ctrl_mesg;
60
mesg.msg_controllen = ctrl_mesg->cmsg_len;
62
if (!recvmsg(sock, &mesg,0 )) {
63
fprintf(stderr, "FAIL CLIENT - recvmsg\n");
67
/* get mr. file descriptor */
69
memcpy(&fd, CMSG_DATA(ctrl_mesg), sizeof(fd));
71
if (pread(fd, read_buffer, 16, 0) <= 0) {
73
fprintf(stderr, "FAIL CLIENT - could not read\n");
74
send(sock, "FAILFAILFAILFAIL", 16, 0);
77
send(sock, read_buffer, strlen(read_buffer),0);
80
/* looks like it worked */