0

I have successfully created and attached to a tap interface. I can also read from the interface with no problem. But trying to write to it fails reporting "invalid argument". The code follows :

int TapInterface::write(char *buf, int n)
{
  int nwrite;
  if((nwrite=::write(this->my_tap_fd, buf, n))<0)
 {
   qDebug("Writing data") ;
   perror("Error:");
   exit(1);
  }
  return nwrite;
}
....
....
QByteArray txData("hello");
write(txData.data(), txData.length());

Any help?

ae41
  • 15
  • 5
  • 1
    Which line gives the error? – Miki Jul 02 '15 at 08:35
  • Sorry, for the late response; the write function returns -1 i.e. ::write(this->my_tap_fd, buf, n) thus the if statement is entered and the "invalid argument" error code is reported by perror. The last two lines in the code show how I actually called the function – ae41 Jul 04 '15 at 11:30
  • Are you sure your `QIODevice` is correcly opened? – Miki Jul 04 '15 at 11:44
  • As it can be seen what i have written into the tap interface is a sample "hello" msg! Could this be the source of the problem? Should it be a valid ethernet frame/ ip packet? – ae41 Jul 04 '15 at 12:02
  • @Miki; for this part I have used direct sys calls (i.e. open, write, etc,...) and the open sys call and the corresponding ioctl call to create/attech to the interface return sucessfully . Actually i have followed the simpletun.c example @ http://backreference.org/2010/03/26/tuntap-interface-tutorial/ – ae41 Jul 04 '15 at 12:08
  • @Miki; BTW as I mentioned in my post i can successfully read out of the interface, so the interface must have been correctly opened (i guess). – ae41 Jul 04 '15 at 12:10
  • Can you go inside the body of the write that gives you the error? – Miki Jul 04 '15 at 12:13
  • I try to step into the function but nothing happens!! After many repeated F11 (step into) the debugger moves to the next line (i.e. inside the if function) – ae41 Jul 04 '15 at 12:25
  • Try writing your txData to a file, and check if your TapInterface::write writes data correctly. If so, your problem is in ::write – Miki Jul 04 '15 at 12:37
  • do you have the necessary permissions? – Hamish Moffatt Jul 06 '15 at 01:36
  • 1
    solved, as i guessed: the data written to the tun/tap interface should be a valid pkt/frame – ae41 Jul 12 '15 at 06:42

0 Answers0