Detecting TCP/IP connections/disconnections

Started by
1 comment, last by MauMan 24 years ago
I think the question I want to ask is: Is there an API or technique that will notify a program if the TCP/IP routing tables have changed? Background: I have a small program that runs in the background. One of the things it does is show the current IP address(es) for the machine the program is running on. I''d like to make the list update if the user''s IP info changes (examples: dials onto the internet, disconnects from the internet, plugs in a PC Card/USB network card, changes the IP address of a network card under WIn2K, etc...). Thanks. --- See http://www.cyberbrinedreams.com
---CyberbrineDreamsSuspected implementation of the Windows idle loop: void idle_loop() { *((char*)rand()) = 0; }
Advertisement
I don''t think there is an API that will set a callback or event for when a network interface receives a new IP address. Next best thing is to enumerate current IP addresses on the host and detect if new IP addresses are detected/old IP addresses aren''t listed.

From the MSDN Knowledge Base (Article ID: Q129315):
void EnumIP() {  char     szHostname[100];  HOSTENT *pHostEnt;  int      nAdapter = 0;  gethostname( szHostname, sizeof( szHostname ));  pHostEnt = gethostbyname( szHostname );  while ( pHostEnt->h_addr_list[nAdapter] ) {    // pHostEnt->h_addr_list[nAdapter] is the current address in host    //  order.    nAdapter++;  }} 
I'm currently using a timer to recheck every so often but that seems to be overkill... :-(

Thanks for the response!


Edited by - mauMan on 4/10/00 8:16:08 PM
---CyberbrineDreamsSuspected implementation of the Windows idle loop: void idle_loop() { *((char*)rand()) = 0; }

This topic is closed to new replies.

Advertisement