Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


Closed Thread
  Search this Thread
Old 04-10-2008, 09:22 PM   #1
Registered: Jan 2008
Posts: 40

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

I am trying to watch my network. Actually trying for identify attack. But my program can not get interface with flags. Can anyone tell what i did mistake.
This is flag function body..........

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");

    /* Get the existing interface flags */

    strcpy(ifr.ifr_name, Gdevice);
    if(ioctl(fd, SIOCGIFFLAGS, &ifr) < 0)
	perror("Cannot get interface flags");

    ifr.ifr_flags |= IFF_PROMISC;
    if(ioctl(fd, SIOCSIFFLAGS,  &ifr) < 0)
	perror("Cannot set interface flags");
The following code are main frogram and all declaration

#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/file.h>
#include <stdlib.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <malloc.h>
#include <netinet/in_systm.h>
#include <net/if_arp.h>
#include <net/if.h>
#include <netinet/udp.h>
#define __FAVOR_BSD
#include <netinet/tcp.h> 
//#include <netinet/udp.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <linux/if_ether.h>
#include <syslog.h>

#define PKTLEN 96	/* Should be enough for what we want */
#ifndef IP_MF
#define IP_MF	0x2000

/***** WATCH LEVELS ******/

#define MYSELFONLY	1
#define MYSUBNET	2

/***** REPORT LEVELS *****/

#define REPORTALL	1
#define REPORTDOS	2
#define REPORTSCAN	3

struct floodinfo {
    u_short sport;
    struct floodinfo *next;

struct addrlist {
    u_long saddr;
    int cnt;
    int wwwcnt;
    struct addrlist *next;

struct atk {
    u_long saddr;
    u_char eaddr[ETH_ALEN];
    time_t atktime;

struct pktin {
    u_long saddr;
    u_short sport;
    u_short dport;
    time_t timein;
    u_char eaddr[ETH_ALEN];
    struct floodinfo *fi;
    struct pktin *next;

struct scaninfo {
    u_long addr;
    struct atk teardrop;
    struct atk land;
    struct atk icmpfrag;
    struct pktin *tcpin;
    struct pktin *udpin;
    struct scaninfo *next;
    u_long icmpcnt;
} ;

struct scaninfo *Gsilist = NULL, *Gsi;

u_long Gmaddr;
time_t Gtimer = 10, Gtimein;
int Gportlimit = 7;
int Gsynflood = 8;
int Gwebcount = 40;
int Gicmplimit = 5;
int Gwatchlevel = MYSELFONLY;
int Greportlevel = REPORTALL;
char *Gprogramname, *Gdevice = "eth0";

/******** IP packet info ********/

u_long Gsaddr, Gdaddr;
int Giplen, Gisfrag, Gid;

/****** Externals *************/

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)
    if((hp = gethostbyname(hostname)) == NULL)
	fprintf(stderr, "Cannot find own address\n");
    memcpy((char *)&Gmaddr, hp->h_addr, hp->h_length);
    if((netfd = initdevice(O_RDWR, 0)) < 0)

    /* 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++)
		Gsi->icmpcnt = 0;
	    t = time((time_t *)0);
Please help me.
Old 04-21-2008, 08:20 PM   #2
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

Please continue this thread here.

Closed Thread

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
Error: SIOCSIF Flags Invalid Argument. wyzzerdd Fedora 1 02-09-2008 01:08 AM
message sending failed : Error[22 ] invalid argument .....but each and every argument rakeshranjanjha Linux - Software 2 01-08-2008 12:22 AM
sendmsg : Invalid Argument Programming 0 09-14-2006 08:16 AM
iptables FLOOD FLAGS and INVALID chains - need another module? MadCactus Linux - Security 3 11-19-2003 09:26 AM
xawtv - invalid argument liguorir Linux - Software 0 06-17-2003 09:55 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:51 PM.

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