53 lines
1.2 KiB
C
53 lines
1.2 KiB
C
#include <arpa/inet.h>
|
|
#include <stdio.h>
|
|
#include <netinet/in.h>
|
|
#include <sys/socket.h>
|
|
#include <unistd.h>
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
|
|
#include <libflex.h>
|
|
|
|
#define PORT 12345
|
|
|
|
int main(int argc, char **argv) {
|
|
if (argc < 2) {
|
|
fprintf(stderr, "Usage: %s <path>\n", argv[0]);
|
|
return -1;
|
|
}
|
|
|
|
char *path = argv[1];
|
|
|
|
int client_fd = socket(AF_INET, SOCK_STREAM, 0);
|
|
if (client_fd == -1) {
|
|
perror("socket");
|
|
return -1;
|
|
}
|
|
|
|
struct sockaddr_in server_addr;
|
|
server_addr.sin_family = AF_INET;
|
|
server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
|
server_addr.sin_port = htons(PORT);
|
|
|
|
if (connect(client_fd, (struct sockaddr*)&server_addr, sizeof(server_addr)) == -1) {
|
|
perror("connect");
|
|
return -1;
|
|
}
|
|
|
|
uint8_t payload_buffer[256];
|
|
struct flex_byte_buffer bb = flex_bb_init(payload_buffer, sizeof(payload_buffer));
|
|
flex_bb_push_buffer8(&bb, (uint8_t*)path, strlen(path));
|
|
|
|
uint8_t send_buffer[512];
|
|
int send_size = flex_serialize(send_buffer, sizeof(send_buffer), 1, bb.data, bb.size);
|
|
|
|
write(client_fd, send_buffer, send_size);
|
|
|
|
while (true) {
|
|
}
|
|
|
|
close(client_fd);
|
|
|
|
return 0;
|
|
}
|