• Advertisement

Archived

This topic is now archived and is closed to further replies.

Detecting TCP/IP connections/disconnections

This topic is 6495 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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++;
}
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement