LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-20-2008, 02:52 AM   #1
nasim751
Member
 
Registered: Jan 2008
Posts: 40

Rep: Reputation: 15
Post Cannot get interface flags: Invalid argument


hello,
i am trying to setup network device but unfortunately can't get interface.
i got few feedback from like you people even though the problem is in right place. How can i get this result.Please give me your feedback.

This is the function..........

error : Cannot get interface flags: Invalid argument
Code:
Description: Set up the network device so we can read it.


initdevice(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);
}
Main body..............
Code:
int SIOCGIFFLAGS;
int SIOCSIFFLAGS;


extern int errno;
extern char *optarg;
extern int optind, opterr;

void do_tcp(), do_udp(), do_icmp(), print_info(), process_packet();
void addtcp(), addudp(), clear_pktin(), buildnet();
void doargs(), usage(), addfloodinfo(), rmfloodinfo();
struct scaninfo *doicare(), *addtarget();
char *anetaddr(), *ether_ntoa();
u_char *readdevice();


main(argc, argv)
int argc;
char *argv[];
{
    int pktlen = 0, i, netfd;
    u_char *pkt;
    char hostname[32];
    struct hostent *hp;
    time_t t;

    doargs(argc, argv);
    openlog("WATCHER", 0, LOG_DAEMON);
    if(gethostname(hostname, sizeof(hostname)) < 0)
    {
	perror("gethostname");
	exit(-1);
    }
    if((hp = gethostbyname(hostname)) == NULL)
    {
	fprintf(stderr, "Cannot find own address\n");
	exit(-1);
    }
    memcpy((char *)&Gmaddr, hp->h_addr, hp->h_length);
    buildnet();
    if((netfd = initdevice(O_RDWR, 0)) < 0)
	exit(-1);

    /* Now read packets forever and process them. */

    t = time((time_t *)0);
    while(pkt = readdevice(netfd, &pktlen))
    {
	process_packet(pkt, pktlen);
	if(time((time_t *)0) - t > Gtimer)
	{
	    /* Times up.  Print what we found and clean out old stuff. */

	    for(Gsi = Gsilist, i = 0; Gsi; Gsi = Gsi->next, i++)
	    {
                clear_pktin(Gsi);
	        print_info();
		Gsi->icmpcnt = 0;
	    }
	    t = time((time_t *)0);
	}
    }
}
 
Old 04-21-2008, 12:22 PM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Does the following not need a cast?
Code:
    if(ioctl(fd, SIOCGIFFLAGS, (caddr_t)&ifr) == -1 )
Also for looking at the docs I do not think checking if less than zero is correct (yet have seen it may times in examples)
Quote:
Upon successful completion, ioctl() shall return a value other than -1 that depends upon the STREAMS device control function. Otherwise, it shall return -1 and set errno to indicate the error.
Anyway third time lucky in posting this in the correct forum
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot get interface flags: Invalid argument nasim751 Linux - Software 1 04-21-2008 07:20 PM
Cannot get interface flags: Invalid argument nasim751 Linux - Software 1 04-21-2008 07:18 PM
Error: SIOCSIF Flags Invalid Argument. wyzzerdd Fedora 1 02-09-2008 12:08 AM
message sending failed : Error[22 ] invalid argument .....but each and every argument rakeshranjanjha Linux - Software 2 01-07-2008 11:22 PM
iptables FLOOD FLAGS and INVALID chains - need another module? MadCactus Linux - Security 3 11-19-2003 08:26 AM


All times are GMT -5. The time now is 11:44 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration