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. Advertising

  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. Advertising

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. Ron Peterson

    /dev/urandom vs. /dev/random

    Ron Peterson, Jan 7, 2005, in forum: C Programming
    Replies:
    21
    Views:
    1,509
    Keith Thompson
    Jan 13, 2005
  2. AC
    Replies:
    0
    Views:
    151
  3. Guest
    Replies:
    2
    Views:
    141
    Bob Barrows [MVP]
    Sep 18, 2005
  4. Eirikur Hallgrimsson
    Replies:
    3
    Views:
    151
    Gavin Sinclair
    Oct 10, 2004
  5. Michele Dondi
    Replies:
    1
    Views:
    136
    Anno Siegel
    Feb 22, 2004
Loading...

Share This Page