LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 07-25-2007, 12:24 PM   #1
taltman
Member
 
Registered: Jun 2004
Posts: 41

Rep: Reputation: 15
notified of ip address change


Is there a good way in c on linux to be notified(signal/libevent/etc) when the ip address of a network adapter changes? Or is polling the best option?

Things that work in kernel space are fine too this isn't just a user space question.

Last edited by taltman; 07-25-2007 at 12:37 PM.
 
Old 07-25-2007, 03:25 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,536

Rep: Reputation: 148Reputation: 148
You should connect to the kernel notification chain for addresses. It available on the kernel level, but you can do it in user space (routing daemons do the same).

Take a look into the subcommands of ip monitor. You can either run it and parse the output to find the events interesting for you or write a piece of netlink code (probably looking into ip's source) do do it entirely in your own program.

Edit. To make it clear: the command is
Code:
ip monitor
 
Old 07-26-2007, 02:10 PM   #3
taltman
Member
 
Registered: Jun 2004
Posts: 41

Original Poster
Rep: Reputation: 15
Thanks very much. I found an excerpt of Linux Network Internals on google books that explains notification chains quite well. ip_MASQUERADE.c had just the example I needed.
 
Old 07-26-2007, 07:28 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Quote:
Originally Posted by taltman
Thanks very much. I found an excerpt of Linux Network Internals on google books that explains notification chains quite well. ip_MASQUERADE.c had just the example I needed.
Sounds interesting ... can you post the link you found
for posteriority? :}



Cheers,
Tink
 
Old 07-26-2007, 07:59 PM   #5
taltman
Member
 
Registered: Jun 2004
Posts: 41

Original Poster
Rep: Reputation: 15
If the link doesn't work just search books.google.com for "linux network internals" and the chain stuff is on page 75.
linux network internals

The chain registration is on line 213.
Just take a look at the struct that is passed to the registration function to find the callback and such.
ipt_MASQUERADE.c

There is a list of the netdevice events starting on line 160.
notifier.h
 
Old 07-28-2007, 02:33 AM   #6
haxpor
Member
 
Registered: Dec 2006
Distribution: Ubuntu 9.10
Posts: 86

Rep: Reputation: 15
Thanks taltman, this also led me to another source, "Understanding The Linux Kernel".

http://www.sti.uniurb.it/acquaviva/ulk.pdf
 
Old 07-28-2007, 02:34 AM   #7
haxpor
Member
 
Registered: Dec 2006
Distribution: Ubuntu 9.10
Posts: 86

Rep: Reputation: 15
Thanks taltman, this also led me to another source, "Understanding The Linux Kernel".

http://www.sti.uniurb.it/acquaviva/ulk.pdf
 
Old 07-28-2007, 02:36 AM   #8
haxpor
Member
 
Registered: Dec 2006
Distribution: Ubuntu 9.10
Posts: 86

Rep: Reputation: 15
Thanks taltman, this also led me to another source, "Understanding The Linux Kernel".

http://www.sti.uniurb.it/acquaviva/ulk.pdf
 
  


Reply

Tags
event, ip, poll


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
monitor processes to be notified when a new process is started? cfh Programming 2 10-03-2005 07:07 PM
won't change ip address xushi Solaris / OpenSolaris 4 05-14-2005 03:11 AM
To get notified about a USB device getting Hotplugged Amol Patki Programming 2 04-06-2005 03:12 PM
Change IP address lvran Linux - Networking 2 10-16-2003 01:19 AM
how to get notified on activity on a thread LarryDoliver LQ Suggestions & Feedback 4 10-01-2003 03:36 PM


All times are GMT -5. The time now is 09:37 PM.

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