#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
-#include <sys/mman.h>
+#include <sys/sendfile.h>
#include <sys/socket.h>
#include <linux/if_alg.h>
-static void build_hash(int sk, char *map, size_t size, const char *pathname)
+static void build_hash(int sk, int fd, size_t size, const char *pathname)
{
unsigned char hash[20];
ssize_t written, length;
int i;
- written = send(sk, map, size, 0);
+ written = sendfile(sk, fd, NULL, size);
if (written < 0)
perror("Failed to write data");
static int create_hash(int sk, const char *pathname)
{
struct stat st;
- char *map;
int fd;
fd = open(pathname, O_RDONLY);
return -1;
}
- map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
- if (map == NULL || map == MAP_FAILED) {
- close(fd);
- return -1;
- }
-
- build_hash(sk, map, st.st_size, pathname);
-
- munmap(map, st.st_size);
+ build_hash(sk, fd, st.st_size, pathname);
close(fd);