[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Interface status detection



Oleg Goldshmidt wrote:
> 
> "Muli B.Y." <mulix@ibm.net> writes:
> 
> > I have written a small utility, ifup, which will tell you if any network
> > interface is up or down (connected or disconnected).
> 
> Can you explain what it does? I mean, is it a wrapper around ifconfig(8)
> or netstat(8) or something of the kind? Why is it preferable?

It is not a wrapper, it does not depend upon ifconfig. It does use the
same techniques ifconfig (or netstat) use. I wrote if for inclusion with
the licq (http://www.licq.org) icq clone, in order for licq to
automatically detect when you go online/ offline, and go online/ offline
accordingly.

> 
> > Now,  what I really need is a way to get a notification when an
> > interface changes its status. Is there any way to do this under
> > linux?
> 
> I suppose there is more than one way to do it under Linux.

I certainly hope so. I can think of a rather elegant way to do this
under windows, and it would pain me to no end if linux proved less
elegant... ;)

> 
> > (Of course I can sleep() and continually check the interface's
> > status,
> 
> Yes, you can. You can also use cron.

The minimal time resolution I'm talking about here is less than a
second, and the optimal is instantaneous. That is why cron is not an
option, and sleep() I don't like.

> 
> > but I dislike this approach- can you hear you cpu roasting? :))
> 
> No.

int main()
{
	while (1)
	{
		sleep(1)
		do_some_quick_stuff();
	}
	return 0;
}

Run this and talk to me in a couple of hours/ days/ months. 

Note: while the sleep() solution would work, and cpus don't roast that
quickly, it is not ELEGANT. There must be a better solution!
 
> --
> Oleg Goldshmidt | BLOOMBERG L.P. (BFM) | oleg@bfr.co.il
> "... We work by wit, and not by witchcraft;
>  And wit depends on dilatory time." - W. Shakespeare.

-- 
Muli B.Y.
email: mulix@ibm.net

linux/reboot.h: #define LINUX_REBOOT_MAGIC1 0xfee1dead

=================================================================
To unsubscribe, send mail to linux-il-request@linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request@linux.org.il