Skip to content
Snippets Groups Projects
Commit 41c43870 authored by Clément's avatar Clément
Browse files

client

parent 85d18a24
Branches
No related merge requests found
#include "utils/crc.h"
#include <fcntl.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdint.h>
#include <stdio.h>
#include <fcntl.h>
#include "utils/error.h"
#include "server/server.h"
#include <sys/poll.h>
#include <unistd.h>
#include <sys/stat.h>
int main(void)
int main(int argc, char *argv[])
{
printf("Hello world\n");
struct sockaddr_in addr;
int server;
if (argc != 4) {
BLAME("usage: %s <remote-host> <remote-port> <file>", argv[0]);
}
if ((server = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
PERROR("socket");
return 1;
}
addr.sin_family = AF_INET;
addr.sin_port = htons(atoi(argv[2]));
if (!inet_aton(argv[1], &addr.sin_addr))
BLAME("invalid remote host: %s", argv[1]);
if (connect(server, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
close(server);
PERROR("connect");
return 1;
}
int fd = open(argv[3], O_RDONLY);
if (fd < 0) {
PERROR("open");
return 1;
}
struct stat statbuf;
CHK(fstat(fd, &statbuf));
uint16_t data;
uint16_t residue;
uint32_t to_send;
for (int i = 0; i < (int)(statbuf.st_size / sizeof(data) +
statbuf.st_size % sizeof(data));
i++) {
CHK(read(fd, &data, sizeof(data)));
to_send = data << 16;
residue = crc_crc((uint8_t *)&(to_send), 4, crc16_xmodem);
to_send |= residue;
if (send(server, &to_send, sizeof(to_send), 0) <= 0)
break;
}
return 0;
return EXIT_SUCCESS;
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment