forked from emilytouchingcomputers/CTFium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_lib.c
36 lines (33 loc) · 851 Bytes
/
client_lib.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
#include "client_lib.h"
#include "util.h"
#include <err.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
void write_shared_file(char *filename, char *content, size_t content_len) {
send_pid(BROKER_FD);
send_ull(BROKER_FD, PUT_FILE);
send_str(BROKER_FD, filename);
send_ull(BROKER_FD, content_len);
writen(BROKER_FD, content, content_len);
char *resp = read_str(BROKER_FD);
if (strcmp(resp, "OK") != 0) {
err(1, "resp not OK");
}
free(resp);
}
int read_shared_file(char *filename) {
send_pid(BROKER_FD);
send_ull(BROKER_FD, GET_FILE);
send_str(BROKER_FD, filename);
send_str(BROKER_FD, filename);
char *resp = read_str(BROKER_FD);
if (strcmp(resp, "OK") != 0) {
err(1, "resp not OK");
}
free(resp);
open(filename, O_RDONLY);
}