2012-08-02 20:41:25 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <unistd.h>
|
2012-08-02 22:37:20 +02:00
|
|
|
#include "common.h"
|
2012-08-02 20:41:25 +02:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2012-08-29 12:45:44 +02:00
|
|
|
int sock_fd, nbr, i;
|
2012-08-02 20:41:25 +02:00
|
|
|
struct sockaddr_un sock_address;
|
2012-09-24 11:00:35 +02:00
|
|
|
char socket_path[BUFSIZ];
|
2012-08-29 12:45:44 +02:00
|
|
|
char msg[BUFSIZ];
|
2012-08-02 22:37:20 +02:00
|
|
|
char rsp[BUFSIZ];
|
2012-08-02 20:41:25 +02:00
|
|
|
|
2012-08-02 22:37:20 +02:00
|
|
|
if (argc < 2)
|
2012-08-07 12:17:47 +02:00
|
|
|
return -1;
|
2012-08-02 20:41:25 +02:00
|
|
|
|
2012-09-24 11:00:35 +02:00
|
|
|
char *sp = getenv(SOCKET_ENV_VAR);
|
2012-08-02 20:41:25 +02:00
|
|
|
|
2012-09-29 11:57:41 +02:00
|
|
|
strncpy(socket_path, (sp == NULL ? DEFAULT_SOCKET_PATH : sp), sizeof(socket_path));
|
2012-08-02 20:41:25 +02:00
|
|
|
|
2012-08-29 12:45:44 +02:00
|
|
|
msg[0] = '\0';
|
|
|
|
|
2012-09-29 11:57:41 +02:00
|
|
|
int max = sizeof(msg);
|
|
|
|
for (i = 1; max > 0 && i < argc; i++) {
|
|
|
|
strncat(msg, argv[i], max);
|
|
|
|
max -= strlen(argv[i]);
|
|
|
|
if (i < (argc - 1)) {
|
|
|
|
strncat(msg, TOKEN_SEP, max);
|
|
|
|
max -= strlen(TOKEN_SEP);
|
|
|
|
}
|
2012-08-29 12:45:44 +02:00
|
|
|
}
|
|
|
|
|
2012-08-02 20:41:25 +02:00
|
|
|
sock_address.sun_family = AF_UNIX;
|
2012-09-29 11:57:41 +02:00
|
|
|
strncpy(sock_address.sun_path, socket_path, sizeof(sock_address.sun_path));
|
2012-08-02 20:41:25 +02:00
|
|
|
|
|
|
|
sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
|
|
connect(sock_fd, (struct sockaddr *) &sock_address, sizeof(sock_address));
|
|
|
|
|
2012-08-02 22:37:20 +02:00
|
|
|
send(sock_fd, msg, strlen(msg), 0);
|
2012-08-28 21:15:29 +02:00
|
|
|
|
2012-08-02 22:37:20 +02:00
|
|
|
if ((nbr = recv(sock_fd, rsp, sizeof(rsp), 0)) > 0) {
|
|
|
|
rsp[nbr] = '\0';
|
|
|
|
if (strcmp(rsp, EMPTY_RESPONSE) != 0)
|
|
|
|
printf("%s", rsp);
|
2012-08-02 20:41:25 +02:00
|
|
|
}
|
2012-08-07 12:17:47 +02:00
|
|
|
|
2012-08-28 21:15:29 +02:00
|
|
|
close(sock_fd);
|
2012-08-07 12:17:47 +02:00
|
|
|
return 0;
|
2012-08-02 20:41:25 +02:00
|
|
|
}
|