summaryrefslogtreecommitdiffstats
path: root/03_exercise/cli/client.c
diff options
context:
space:
mode:
Diffstat (limited to '03_exercise/cli/client.c')
-rw-r--r--03_exercise/cli/client.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/03_exercise/cli/client.c b/03_exercise/cli/client.c
index 67731f4..22f4e61 100644
--- a/03_exercise/cli/client.c
+++ b/03_exercise/cli/client.c
@@ -70,7 +70,7 @@ int main() {
return 0;
}
-void receive_file(int recv_sock, char *path, int size) {
+void receive_file(int recv_sock, char *path, size_t size, char *start_buf, size_t start_buf_len) {
char buffer[BUF_SIZE];
int file_fd;
int received;
@@ -85,6 +85,17 @@ void receive_file(int recv_sock, char *path, int size) {
received = 0;
+ if (start_buf) {
+ // there was part of the file already in the "packet" which was supposed to contain only the header
+ // put that into the file too
+ if (write_all(file_fd, start_buf, start_buf_len) != start_buf_len) {
+ perror("write start buf");
+ printf("\n");
+ return;
+ }
+ received += start_buf_len;
+ }
+
/* Read all data */
while (received < size) {
int nread;
@@ -138,9 +149,8 @@ bool check_get(char *buffer) {
char path[strlen(rest) + 1];
memcpy(path, rest, strlen(rest));
path[strlen(rest)] = 0;
- path[strlen(rest) - 1] = 0;
- receive_file(server_sock, path, file_size);
+ receive_file(server_sock, path, file_size, &(buffer[i+2]), strlen(&(buffer[i+2])));
return true;
}