Thread: Cannot get interface flags: Invalid argument

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    20

    Post Cannot get interface flags: Invalid argument

    hello,
    I can not interface flag. Actually getting invalid argument. Can any one give me feedback. See my flag function....

    Code:
    /************************************************************************
    Function:  initdevice
    
    Description: Set up the network device so we can read it.
    
    **************************************************************************/
    initdevice(fd_flags, dflags)
    int fd_flags;
    u_long dflags;
    {
        struct ifreq ifr;
        int fd, flags = 0;
    
        if((fd = socket(PF_INET, SOCK_PACKET, htons(0x0003))) < 0)
        {
    	perror("Cannot open device socket");
    	exit(-1);
        }
    
        /* Get the existing interface flags */
    
        strcpy(ifr.ifr_name, Gdevice);
        if(ioctl(fd, SIOCGIFFLAGS, &ifr) < 0)
        {
    	perror("Cannot get interface flags");
    	exit(-1);
        }
    
        ifr.ifr_flags |= IFF_PROMISC;
        if(ioctl(fd, SIOCSIFFLAGS,  &ifr) < 0)
        {
    	perror("Cannot set interface flags");
    	exit(-1);
        }
        
        return(fd);
    }

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    this style
    Code:
    initdevice(fd_flags, dflags)
    int fd_flags;
    u_long dflags;
    is outdated
    use
    Code:
    initdevice(int fd_flags,u_long dflags)


    Code:
    struct ifreq ifr;
    your struct is not initialized - don't you get any warnings about -
    ifr.ifr_flags |= IFF_PROMISC;
    ??
    increase you warnings level (and maybe use more uptodate compiler)
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    Ė David J. Wheeler

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    20
    No i am not getting any warnings, getting only this message

    Cannot get interface flags: Invalid argument
    can you tell me, where i did mistake interims of structure?
    what is your opinion?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It is VERY impolite to ask the same question in multiple places:
    http://www.linuxquestions.org/questi...gument-634527/

    Vart: The struct should be initialized by the SIOCGIFFLAGS, but it appears that it doesn't do that (correctly).

    I don't know what the answer to the actual question is - I searched in google for a while, but found only a vague link (that is 6 years old, so I don't know if there's any relevance NOW):
    http://cygwin.com/ml/cygwin/2002-10/msg00884.html

    It's probably worth filling in the ifr_addr field and see if that helps. Not quite sure how you get that info...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Cannot get interface flags: Invalid argument
    By nasim751 in forum C Programming
    Replies: 1
    Last Post: 04-15-2008, 02:27 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Nested loop frustration
    By caroundw5h in forum C Programming
    Replies: 14
    Last Post: 03-15-2004, 09:45 PM