blob: e980687cdd9fa34a2d6d4fffa163113a3653929e [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
akmhoque1771c412012-11-09 13:06:08 -060010static int
11usage(char *progname)
12{
13 printf("Usage: %s [OPTIONS...]\n\
14 NLSR Api client....\n\
15 nlsrc add|del name|neighbor name_prefix [faceX] \n\
16 add/del, -- adding/deleting operation\n\
17 name/neighbor, -- Operation for name/neighbor\n\
18 name_name, -- Name prefix for name/neighbor\n\
19 faceX, -- Face Id for neighbor if third argument is neighbor\n", progname);
20
21 exit(1);
22}
23
akmhoque1712a392012-11-08 12:00:30 -060024int main(int argc, char *argv[])
25{
26 int sockfd;
27 int len;
28 struct sockaddr_un address;
29 int result;
30 int byteSend;
31
32 int command_len=0;
33 int i;
akmhoque1771c412012-11-09 13:06:08 -060034
35 if (argc < 4 )
36 usage(argv[0]);
37 if ( strcmp(argv[2],"neighbor") == 0 && argc <5 )
38 usage(argv[0]);
39
akmhoque1712a392012-11-08 12:00:30 -060040 for(i=1;i<argc;i++)
41 command_len+=(strlen(argv[i])+1);
42 char *command=malloc(command_len);
43 memset(command,command_len+1,0);
44 for(i=1;i<argc;i++)
45 {
46 memcpy(command+strlen(command),argv[i],strlen(argv[i]));
47 if ( i < argc-1 )
48 memcpy(command+strlen(command)," ",1);
49 }
50
51 sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
52 address.sun_family = AF_UNIX;
53 strcpy(address.sun_path, "/tmp/nlsr_api_server_socket");
54 len = sizeof(address);
55 result = connect(sockfd, (struct sockaddr *)&address, len);
akmhoque1771c412012-11-09 13:06:08 -060056 if(result == -1)
57 {
akmhoque1712a392012-11-08 12:00:30 -060058 perror("oops nlsrc ");
59 exit(1);
60 }
61 printf("Data to send: %s \n",command);
62 byteSend=send(sockfd, command, strlen(command),0);
akmhoque1771c412012-11-09 13:06:08 -060063 free(command);
akmhoque1712a392012-11-08 12:00:30 -060064 close(sockfd);
65 exit(0);
66}