diff --git a/client.c b/client.c index 22a2d5e..3c7d773 100644 --- a/client.c +++ b/client.c @@ -84,7 +84,7 @@ int main(int argc,char *argv[]) { //usage: ./client host port else puts("Send file error."); #else send(sockfd, &file_size, sizeof(uint32_t), 0); - if(!sendfile(sockfd, fileno(fp), &len, file_size)) puts("Send file success."); + if(!sendfile(sockfd, fileno(fp), &len, htonl(file_size))) puts("Send file success."); else puts("Send file error."); #endif fclose(fp); diff --git a/server.c b/server.c index d7e5366..6c8fe85 100644 --- a/server.c +++ b/server.c @@ -126,6 +126,7 @@ int sendAll(char* file_path, THREADTIMER *timer) { timer->fp = fp; timer->is_open = 1; uint32_t file_size = (uint32_t)fileSize(file_path); + printf("Get file size: %u bytes.\n", file_size); off_t len; #if __APPLE__ struct iovec headers; @@ -136,7 +137,7 @@ int sendAll(char* file_path, THREADTIMER *timer) { sendfile(fileno(fp), timer->accept_fd, 0, &len, &hdtr, 0); #else send(timer->accept_fd, &file_size, sizeof(uint32_t), 0); - sendfile(timer->accept_fd, fileno(fp), &len, file_size); + sendfile(timer->accept_fd, fileno(fp), &len, htonl(file_size)); #endif printf("Send %lld bytes.\n", len); closeFile(fp);