heres a version of the test case that builds..... Sorry about that. On Sun, Nov 24, 2013 at 9:21 AM, Shawn Landden <shawnlandden@xxxxxxxxx> wrote: > If I use sendfile() to send to a accept()ed AF_ALG socket set up for > "hash", I get the wrong > answer, if I read() and then write() I get the right answer. None of > the system calls return an error. > > test case attached. > > -- > > --- > Shawn Landden > +1 360 389 3001 (SMS preferred) -- --- Shawn Landden +1 360 389 3001 (SMS preferred)
#include <sys/sendfile.h> #include <sys/socket.h> #include <linux/if_alg.h> #include <stdio.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #include <unistd.h> int main(void) { int opfd; int tfmfd; struct sockaddr_alg sa = { .salg_family = AF_ALG, .salg_type = "hash", .salg_name = "sha1" }; char *buf2; char buf[20]; int i; struct stat st; ssize_t size; tfmfd = socket(AF_ALG, SOCK_SEQPACKET, 0); bind(tfmfd, (struct sockaddr *)&sa, sizeof(sa)); opfd = accept(tfmfd, NULL, 0); int t = open("/bin/true", O_RDONLY); fstat(t, &st); size = sendfile(opfd, t, NULL, st.st_size); if (size != st.st_size) exit(1); read(opfd, &buf, 20); for (i = 0; i < 20; i++) { printf("%02x", (unsigned char)buf[i]); } printf("\n"); lseek(t, 0, SEEK_SET); buf2 = malloc(st.st_size + 1); read(t, buf2, st.st_size); write(opfd, buf2, st.st_size); read(opfd, &buf, 20); for (i = 0; i < 20; i++) { printf("%02x", (unsigned char)buf[i]); } printf("\n"); close(opfd); close(tfmfd); return 0; }