LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 02-19-2004, 12:43 PM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
Obtaining a default gateway IP address from a Win2K workstation


Obtaining a default gateway IP address from a Win2K workstation
using Visual Basic 5.0

--------------------------------------------------------------------------------

Visual Basic 5.0

How do you Obtain a default gateway IP address from a Win2K workstation ?

1) I tried with OCX Winsock but it only have LocalIP property method not the method to obtain a default gateway.

2) The API GetIpForwardTable will allowed you to access a default gateway IP address, but I have not found the code example for it. Below is a C code. Maybe somebody could translate that to VB
============================

Local_IP = Winsock1.LocalIP

============================
Code:
#include <iphlpapi.h>
...

BOOL YourClass::CheckConnection()
{
  MIB_IPFORWARDTABLE*	pft;
  DWORD			dwTableSize = 0;
  BOOL			bHasDefaultRoute = FALSE;

  GetIpForwardTable(NULL, &dwTableSize, FALSE);
  pft = (MIB_IPFORWARDTABLE*) new BYTE[dwTableSize];

  if (GetIpForwardTable(pft, 
                        &dwTableSize, 
                        TRUE) == NO_ERROR)
  {
    for (unsigned int nIndex = 0; 
             nIndex < pft->dwNumEntries;
             nIndex++)
    {
      if (pft->table[nIndex].dwForwardDest == 0)
      // Default route to gateway
      {
        bHasDefaultRoute = TRUE;
        break;
      }
    }
  }

  delete pft;

  return bHasDefaultRoute;
}
http://www.codeguru.com/mfc/comments/56235.shtml
 
Old 02-20-2004, 02:55 AM   #2
PSIplus
Member
 
Registered: Feb 2004
Location: Vienna/Austria
Distribution: Debian Unstable
Posts: 36

Rep: Reputation: 15
Ähm... Maybe this is the wrong Forum for you... :-)
 
  


Reply



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
How do I set the ip address for eth0, eth1 and the default gateway? abefroman SUSE / openSUSE 5 05-19-2005 04:15 AM
Obtaining IP LAN gateway in C under Linux executive Programming 2 04-13-2005 11:21 AM
Universal default gateway address resolution otisthegbs Linux - Networking 2 07-09-2004 02:28 AM
How do I get iptables to redirect my default gateway address? Paul Woodhouse Linux - Networking 3 11-11-2003 08:52 AM
odd default gateway address, uses addr ~.ip.~ whatzat? piratebiter Linux - Networking 0 09-07-2003 07:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:43 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration