-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpsub.c
56 lines (49 loc) · 1.53 KB
/
psub.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/socket.h"
#include "sys/un.h"
#include "psub.h"
#define UNIXSTR_PATH "/tmp/psub.srt"
#define LISTENQ 5
#define BUFFER_SIZE 256
//test version
int main(int argc, char *argv[])
{
char path[BUFFER_SIZE], ProjectName[BUFFER_SIZE];
getcwd(path, BUFFER_SIZE); //get current path;
if(argc == 2){
getFolderName(path, ProjectName);
}else if(argc == 3){
strcpy(ProjectName, argv[2]);
} else{
printf("Error Usage.\n");
exit(-1);
} // get Project name;
char script[BUFFER_SIZE];
strcpy(script, argv[1]); //get script's name;
if(detectFiles(script) == -1){
perror("Script doesn't exist. SYSTEM");
exit(-1);
}
char CODE_TO_SERVER[BUFFER_SIZE];
sprintf(CODE_TO_SERVER, "PSUB|%s|%s|%s",path, script,ProjectName);//generate code sent to server;
printf("%s\n",CODE_TO_SERVER);
int sockfd;
struct sockaddr_un servaddr;
char mes_from_server[BUFFER_SIZE];
sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sun_family =AF_LOCAL;
strcpy(servaddr.sun_path, UNIXSTR_PATH);
if(connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) == -1){
perror("Error: Can't connect to pSUB-server. SYSTEM");
exit(-1);
}
// connect to server.
write(sockfd, CODE_TO_SERVER, strlen(CODE_TO_SERVER));
read(sockfd, mes_from_server, BUFFER_SIZE);
printf("%s",mes_from_server);
return 0;
}