#include <config.h>
#endif
+#define _GNU_SOURCE
#include <stdio.h>
#include <fcntl.h>
#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);
+ fd = open(pathname, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return -1;
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);
};
int sk, nsk;
- sk = socket(PF_ALG, SOCK_SEQPACKET, 0);
+ sk = socket(PF_ALG, SOCK_SEQPACKET | SOCK_CLOEXEC, 0);
if (sk < 0) {
perror("Failed to create socket");
return -1;