writing and readig on virtual interface /dev/tapX

Discussion in 'C++' started by fabrizio, Nov 11, 2005.

  1. fabrizio

    fabrizio Guest

    I have to write an application which read from a virtual interface
    /dev/tap0, write the packets on /dev/tap1 on the same machine and
    viceversa (I have to emulate a network, with packets loss etc...).
    I don't know how to open the stream. Should I use fstream? If so, can I
    open a stream in input and output mode at the same time?

    Thanks.
    fabrizio
     
    fabrizio, Nov 11, 2005
    #1
    1. Advertisements

  2. fabrizio

    John Ratliff Guest

    fabrizio wrote:
    > I have to write an application which read from a virtual interface
    > /dev/tap0, write the packets on /dev/tap1 on the same machine and
    > viceversa (I have to emulate a network, with packets loss etc...).
    > I don't know how to open the stream. Should I use fstream? If so, can I
    > open a stream in input and output mode at the same time?


    Should be able to.

    #include <fstream>
    #include <iostream>

    std::fstream in("/dev/tap0", std::ios::in);
    std::fstream out("/dev/tap1", std::ios::eek:ut);

    Then you could overload the stream operators for your packet class to
    handle reading/writing.

    As far as read/write at once, you can or the in and out properties, but
    from what you've said, I don't know why you would want to.

    --John Ratliff
     
    John Ratliff, Nov 11, 2005
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Laine-Toner

    Graphical interface for Dev newbie

    Ben Laine-Toner, Jul 18, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    509
    Patrick.O.Ige
    Jul 19, 2005
  2. Steve Franks
    Replies:
    20
    Views:
    4,879
    doodilydoodily
    Dec 7, 2009
  3. Ron Peterson

    /dev/urandom vs. /dev/random

    Ron Peterson, Jan 7, 2005, in forum: C Programming
    Replies:
    21
    Views:
    2,000
    Keith Thompson
    Jan 13, 2005
  4. AC
    Replies:
    0
    Views:
    322
  5. Guest
    Replies:
    2
    Views:
    312
    Bob Barrows [MVP]
    Sep 18, 2005
  6. Eirikur Hallgrimsson
    Replies:
    3
    Views:
    287
    Gavin Sinclair
    Oct 10, 2004
  7. Michele Dondi
    Replies:
    1
    Views:
    258
    Anno Siegel
    Feb 22, 2004
  8. Stuart Kendrick
    Replies:
    0
    Views:
    292
    Stuart Kendrick
    Feb 26, 2004
Loading...