LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 11-02-2017, 11:51 AM   #1
quantumxaos
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:
Quote:
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?
Code:
      
        int fd_in=0,fd_out=0,offset=1;

    if((fd_in=open(argv[0],O_RDONLY))==-1){
        perror("[-] open()");
        return -1;
    }

    if((fd_out=socket(PF_APPLETALK,SOCK_DGRAM,0))==-1){
        if((fd_out=socket(PF_BLUETOOTH,SOCK_DGRAM,0))==-1){
            perror("[-] socket()");
            return -1;
        }
    }

    if(sendfile(fd_out,fd_in,&offset,2)==-1){
        if(offset==0){
            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
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,098

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


Reply


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:57 AM.

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