blob: cd3fc3dac57711da8bc9ea121a8f68d7ac6a0948 [file] [log] [blame]
akmhoque1712a392012-11-08 12:00:30 -06001//1. Make the necessary includes and set up the variables:
2#include <sys/types.h>
3#include <sys/socket.h>
4#include <stdio.h>
5#include <sys/un.h>
6#include <unistd.h>
7#include <stdlib.h>
8#include <string.h>
9
10int main(int argc, char *argv[])
11{
12 int sockfd;
13 int len;
14 struct sockaddr_un address;
15 int result;
16 int byteSend;
17
18 int command_len=0;
19 int i;
20 for(i=1;i<argc;i++)
21 command_len+=(strlen(argv[i])+1);
22 char *command=malloc(command_len);
23 memset(command,command_len+1,0);
24 for(i=1;i<argc;i++)
25 {
26 memcpy(command+strlen(command),argv[i],strlen(argv[i]));
27 if ( i < argc-1 )
28 memcpy(command+strlen(command)," ",1);
29 }
30
31 sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
32 address.sun_family = AF_UNIX;
33 strcpy(address.sun_path, "/tmp/nlsr_api_server_socket");
34 len = sizeof(address);
35 result = connect(sockfd, (struct sockaddr *)&address, len);
36 if(result == -1) {
37 perror("oops nlsrc ");
38 exit(1);
39 }
40 printf("Data to send: %s \n",command);
41 byteSend=send(sockfd, command, strlen(command),0);
42 close(sockfd);
43 exit(0);
44}