home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.protocols.tcp-ip      TCP and IP network protocols.      14,669 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 13,496 of 14,669   
   Jorgen Grahn to Prakash   
   Re: ioctl() behaving different on Linux   
   02 May 10 05:03:56   
   
   138c67bf   
   From: grahn+nntp@snipabacken.se   
      
   On Sat, 2010-05-01, Prakash wrote:   
   > Hello,   
   >   
   > I am migrating the c application from Solaris 9 SPARC to RHEL 5.x   
   > x86_64 platform.   
   >   
   > Here are the platform details:   
   > -------------------------------------------   
   > 1. OS: Red Hat Linux 5.x, kernel 2.6.x   
   > 2. gcc compiler : 4.1.2.x V   
   >   
   > ioctl() call on Linux returning errno as EFAULT (Bad Address).   
      
   It's more precise than that.  The Linux ioctl(2) man page says:   
      
   ERRORS   
          EBADF  d is not a valid descriptor.   
      
          EFAULT argp references an inaccessible memory area.   
      
          EINVAL Request or argp is not valid.   
   ...   
      
   here it means 'argp references an inaccessible memory area'.   
      
   > I have   
   > simulated the problem with below sample program. Can I know what is   
   > going wrong on Linux with this program.   
   >   
   > --------------   
   > /* Sample program to test the ioctl() call which sets the read mode to   
   > message-nondiscard mode.   
   >  * For some reason this sample is not working on Linux x84_64, gcc :   
   > 4.1.x V and Red Hat 5.x.   
   >  * However this code works on Solaris SPARC.   
   >  */   
   >   
   > # include    
   > # include    
   > # include    
   > # include    
   > # include    
   > # include    
   > # include    
   > # include    
   > # include  / macros I_SRDOPT and RMSGN are defined */   
                        ^^^^^^^   
   Hm -- apparently you haven't tried to compile this program. But that   
   seemed to be the only error.   
      
   >   
   >   
   > int   
   > main(){   
   >   
   >         int fd[2];   
   >   
   >         int fd_read;   
   >         int fd_write;   
   >   
   >         fd_read= fd_write = -1; /* Initila value */   
   >   
   >         /* Create unnamed socket pairs */   
   >         if ( socketpair(AF_UNIX, SOCK_STREAM,0,fd) == -1 ){   
   >                 fprintf(stdout, "socketpair call failed with errno: %d   
   > \n", errno);   
   >                 exit(1);   
   >         }   
   >   
   >         fd_read = fd[0];   
   >         fd_write = fd[1];   
   >   
   >         /* fcntl code comes here  to set non blocking read */   
   >   
   >         if ( ioctl(fd_read, I_SRDOPT, RMSGN  ) == -1 ){  /* set read mode to   
   message -nondiscard mode */   
   >                 fprintf(stdout, "ioctl call failed with below error:\n" );   
      
   And as mr Magol wrote, there's perror() and strerror() for printing   
   errnos. (You don't even have to do that -- it's easier to run the   
   program under strace(1) and have it explain everything.)   
      
   >         }else   
   >                 fprintf(stdout, "ioctl works!\n");   
   >   
   >   
   >         return 0;   
   > }// main() ends   
      ^^^^^^^^^^^^^^   
   Removing that to make it compile as C89.   
      
   >   
   > Thanks in Advance.   
      
   I_SRDOPT seems to be related to STREAMS. I cannot find it documented   
   in Stevens' "Unix network programming" books, and I have never used   
   STREAMS myself.  But I know the Linux people generally dislike it, and   
   last time I heard it was /not/ part of Linux except as a kernel patch.   
   It is most likely /not/ in RedHat's kernel.   
      
   But the question is: if this is indeed STREAMS, and you don't have   
   that, then why are the ioctls defined in the header files?  Perhaps   
   there are good reasons, but it's better when code that cannot possibly   
   work doesn't compile ...   
      
   Also, normally I expect 'gcc -std=c89 -Wall -W -pedantic ...' not to   
   compile unless I say "I want BSD APIs" or "I want POSIX this and   
   that". See features.h. But for these things, there was *no*   
   protection. That's surely a bug in the headers.   
      
   Someone else has to answer, but it seems to me you have a problem   
   here. The program you try to port uses Solaris-specific APIs. (OK,   
   some other Unices in the past may have had STREAMS too, but neither of   
   the healthy Unices -- Linux and the BSDs -- have it).   
      
   By the way, running the program under valgrind(1) is also enlightening.   
      
      Syscall param ioctl(CDROMREADTOCENTRY (cdte_format, char)) points to   
      unaddressable byte(s)   
      
   and so on.   
      
   /Jorgen   
      
   --   
     // Jorgen Grahn    O  o   .   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca