opening things without the O_LARGEFILE flag

Discussion in 'Perl Misc' started by Athanasios, Oct 30, 2006.

  1. Athanasios

    Athanasios Guest

    Hi everyone,

    I am trying to open the /dev/net/tun character device with perl.

    In C, I would issue:

    open("/dev/net/tun", O_RDWR)

    and continue as usual.

    However, when I try to use sysopen in perl like

    sysopen(TUNNELDEV, "/dev/net/tun", O_RDWR);

    from the strace (truss) output I can see that instead it tries to do:

    open("/dev/net/tun", O_RDWR|O_LARGEFILE)

    which for some VERY strange reason succeeds but the file descriptor is
    left in a bad state, so it is really unusable. For anything I try to do
    afterwards, I get a

    EBADFD (File descriptor in bad state).


    As I have come down to the systel call level, there is no other reason
    for this problem that I can think of except the O_LARGEFILE flag.
    Indeed, a simple C program works quite fine without that flag.

    I also have tried to use POSIX::eek:pen but it still adds the flag.

    The documentation clearly states that from perl 5.6 and forth, the
    O_LARGEFILE will be used whenever possible. But I really need to bypass
    this and generate an open system call without it.

    Does anyone know any conceivable way to accomplish this? Any help will
    be appreciated.

    If I should take this question to another group or list more suitable
    to get an answer, could you also please indicate that group?

    Kind Regards,
    Athanasios

    (I know, I know, the tun/tap driver may be slightly broken in the
    strict sense, but let's leave that outside for a moment.)
    Athanasios, Oct 30, 2006
    #1
    1. Advertising

  2. Athanasios

    Ted Zlatanov Guest

    On 30 Oct 2006, wrote:

    > The documentation clearly states that from perl 5.6 and forth, the
    > O_LARGEFILE will be used whenever possible. But I really need to bypass
    > this and generate an open system call without it.
    >
    > Does anyone know any conceivable way to accomplish this? Any help will
    > be appreciated.


    While there may be other more appropriate ways, you could use
    Inline::C maybe?

    Ted
    Ted Zlatanov, Oct 31, 2006
    #2
    1. Advertising

  3. Athanasios

    Guest

    "Athanasios" <> wrote:
    > Hi everyone,
    >
    > I am trying to open the /dev/net/tun character device with perl.
    >
    > In C, I would issue:
    >
    > open("/dev/net/tun", O_RDWR)
    >
    > and continue as usual.
    >
    > However, when I try to use sysopen in perl like
    >
    > sysopen(TUNNELDEV, "/dev/net/tun", O_RDWR);
    >
    > from the strace (truss) output I can see that instead it tries to do:
    >
    > open("/dev/net/tun", O_RDWR|O_LARGEFILE)
    >
    > which for some VERY strange reason succeeds but the file descriptor is
    > left in a bad state, so it is really unusable. For anything I try to do
    > afterwards, I get a
    >
    > EBADFD (File descriptor in bad state).
    >
    > As I have come down to the systel call level, there is no other reason
    > for this problem that I can think of except the O_LARGEFILE flag.
    > Indeed, a simple C program works quite fine without that flag.


    Just to make sure it is absolutely nailed down, does the simple C program
    stop working fine if you add the O_LARGEFILE in?


    > I also have tried to use POSIX::eek:pen but it still adds the flag.
    >
    > The documentation clearly states that from perl 5.6 and forth, the
    > O_LARGEFILE will be used whenever possible. But I really need to bypass
    > this and generate an open system call without it.


    Maybe you could compile perl without large file support?

    Or write a small C server that will accept socket connections and
    proxy /dev/net/tun over the socket.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Oct 31, 2006
    #3
  4. Athanasios

    Athanasios Guest

    wrote:
    > "Athanasios" <> wrote:
    > > Hi everyone,
    > >
    > > I am trying to open the /dev/net/tun character device with perl.
    > >
    > > In C, I would issue:
    > >
    > > open("/dev/net/tun", O_RDWR)
    > >
    > > and continue as usual.
    > >
    > > However, when I try to use sysopen in perl like
    > >
    > > sysopen(TUNNELDEV, "/dev/net/tun", O_RDWR);
    > >
    > > from the strace (truss) output I can see that instead it tries to do:
    > >
    > > open("/dev/net/tun", O_RDWR|O_LARGEFILE)
    > >
    > > which for some VERY strange reason succeeds but the file descriptor is
    > > left in a bad state, so it is really unusable. For anything I try to do
    > > afterwards, I get a
    > >
    > > EBADFD (File descriptor in bad state).
    > >
    > > As I have come down to the systel call level, there is no other reason
    > > for this problem that I can think of except the O_LARGEFILE flag.
    > > Indeed, a simple C program works quite fine without that flag.

    >
    > Just to make sure it is absolutely nailed down, does the simple C program
    > stop working fine if you add the O_LARGEFILE in?


    I 'll confirm that shortly, I haven't tried it yet. But judging from
    the system calls I see in truss, it almost surely won't work.

    >
    >
    > > I also have tried to use POSIX::eek:pen but it still adds the flag.
    > >
    > > The documentation clearly states that from perl 5.6 and forth, the
    > > O_LARGEFILE will be used whenever possible. But I really need to bypass
    > > this and generate an open system call without it.

    >
    > Maybe you could compile perl without large file support?
    >
    > Or write a small C server that will accept socket connections and
    > proxy /dev/net/tun over the socket.


    Yes, these are valid options, as is the Inline::C idea which the
    previous poster suggested. But the general idea is that there *should*
    be a way to omit the O_LARGEFILE flag if needed.

    Kind Regards,
    Athanasios

    >
    > Xho
    >
    > --
    > -------------------- http://NewsReader.Com/ --------------------
    > Usenet Newsgroup Service $9.95/Month 30GB
    Athanasios, Oct 31, 2006
    #4
    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. valentin tihomirov

    defining a flag-dependent constant

    valentin tihomirov, Nov 25, 2004, in forum: VHDL
    Replies:
    3
    Views:
    517
    Jim Lewis
    Nov 28, 2004
  2. Wayne Myers

    POK Flag Weirdness wth binary files

    Wayne Myers, May 26, 2004, in forum: Perl
    Replies:
    1
    Views:
    472
    ! aaa
    May 27, 2004
  3. =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=

    vs2005 publish website doing bad things, bad things

    =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=, Oct 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    597
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Oct 25, 2006
  4. samba
    Replies:
    2
    Views:
    474
  5. fniles
    Replies:
    0
    Views:
    269
    fniles
    Apr 26, 2009
Loading...

Share This Page