-   Linux - Newbie (
-   -   Problem Calling Sendfile from C Code (

quantumxaos 11-02-2017 12:51 PM

Hi, I'm trying to run a C code I found online using an old distribution of SLAX Linux 5.1.7 and Slackware 11.0. The linux kernel for this distribution is 2.6.16. The error occurs when executing the program and it calls sendfile giving a value of -1 and the error "sendfile(): Invalid argument". I've reproduced the relevant code below:

Moderator edit: Merged from a parallel question, using the same code example:

Hi, I'm trying to run something similar for linux kernel 2.6.16, but instead of output to a file, I was trying to output to a socket since you mentioned that sendfile wouldn't support regular files for out_fd until kernel 2.6.33. I still get the error "sendfile(): Invalid Argument" even when out_fd is a socket.

I was wondering if you ever figured out why sendfile works in the newer linux kernels but not for 2.6.18? Also, is there a way to fix the error for the older linux kernel?

        int fd_in=0,fd_out=0,offset=1;

        perror("[-] open()");
        return -1;

            perror("[-] socket()");
            return -1;

            perror("[-] sendfile()");
            return -1;

Running strace on this, gives sendfile(4,3,[1],2) = -1 EINVAL (Invalid Argument). I've googled this error and have seen others solve it with newer versions of the linux kernel.

My question is what is causing this error for the version I am using, how can I fix it, and what has changed in newer kernel versions to fix/change the behavior of sendfile?

Thanks for any help.

pan64 11-03-2017 05:54 AM

see man page:
EINVAL Descriptor is not valid or locked, or an mmap(2)-like operation is not available for in_fd.

All times are GMT -5. The time now is 12:16 AM.