Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-02-2017, 11:51 AM   #1
LQ Newbie
Registered: Oct 2017
Posts: 3

Rep: Reputation: Disabled

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.

Last edited by rtmistler; 11-02-2017 at 01:18 PM. Reason: Merging near duplicate questions
Old 11-03-2017, 04:54 AM   #2
LQ Guru
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,988

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Example of calling C++ library from C# code? Samuel_Minirobots Programming 4 10-05-2012 02:28 AM
Calling Fortran 95 code in C srunni Programming 2 04-15-2009 08:15 AM
calling external applications in your c++ code drisay Programming 2 01-25-2005 12:41 PM
Bug in c code calling bash code Linh Programming 11 08-12-2003 04:27 AM
Calling long BASH code within a C program Linh Programming 4 06-24-2003 01:41 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:29 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration